Java Code Examples for weka.core.matrix.Matrix#getArray()
The following examples show how to use
weka.core.matrix.Matrix#getArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaceMatrix.java From tsml with GNU General Public License v3.0 | 5 votes |
/** Generate matrix with standard-normally distributed random elements @param m Number of rows. @param n Number of colums. @return An m-by-n matrix with random elements. */ public static Matrix randomNormal( int m, int n ) { Random random = new Random(); Matrix A = new Matrix(m,n); double[][] X = A.getArray(); for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { X[i][j] = random.nextGaussian(); } } return A; }
Example 2
Source File: MultivariateGaussianEstimator.java From tsml with GNU General Public License v3.0 | 5 votes |
private double getLogDeterminant(Matrix L) { double logDeterminant; double detL = 0; int n = L.getRowDimension(); double[][] matrixAsArray = L.getArray(); for (int i = 0; i < n; i++) { detL += Math.log(matrixAsArray[i][i]); } logDeterminant = detL * 2; return logDeterminant; }
Example 3
Source File: PLST.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Transforms the predictions of the internal classifier back to the original labels. * * @param y The predictions that should be transformed back. The array consists only of * the predictions as they are returned from the internal classifier. * @return The transformed predictions. */ @Override public double[] transformPredictionsBack(double[] y){ // y consists of predictions and maxindex, we need only predictions double[] predictions = new double[y.length/2]; for (int i = 0; i < predictions.length; i++){ predictions[i] = y[predictions.length+i]; } double[][] dataArray = new double[1][predictions.length]; dataArray[0] = predictions; Matrix yMat = new Matrix(dataArray); Matrix multiplied = yMat.times(this.m_v.transpose()).plus(m_Shift); double[] res = new double[multiplied.getColumnDimension()]; // change back from -1/1 coding to 0/1 for (int i = 0; i < res.length; i++) { res[i] = multiplied.getArray()[0][i]<0.0 ? 0.0 : 1.0; } return res; }
Example 4
Source File: MatrixUtils.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Helper method that transforms a Matrix object to an Instances object. * * @param mat The Matrix to transform. * @param patternInst the Instances template to use * @return The resulting Instances object. */ public static Instances matrixToInstances(Matrix mat, Instances patternInst){ Instances result = new Instances(patternInst); for (int i = 0; i < mat.getRowDimension(); i++) { double[] row = mat.getArray()[i]; DenseInstance denseInst = new DenseInstance(1.0, row); result.add(denseInst); } return result; }
Example 5
Source File: PaceMatrix.java From tsml with GNU General Public License v3.0 | 4 votes |
/** Construct a PaceMatrix from a Matrix @param X Matrix */ public PaceMatrix( Matrix X ) { super( X.getRowDimension(), X.getColumnDimension() ); A = X.getArray(); }