use of org.ejml.data.DMatrixRMaj in project narchy by automenta.
the class PrincipalComponentAnalysis method getBasisVector.
/**
* Returns a vector from the PCA's basis.
*
* @param which Which component's vector is to be returned.
* @return Vector from the PCA basis.
*/
public double[] getBasisVector(int which) {
if (which < 0 || which >= numComponents)
throw new IllegalArgumentException("Invalid component");
DMatrixRMaj v = new DMatrixRMaj(1, A.numCols);
extract(V_t, which, which + 1, 0, A.numCols, v, 0, 0);
return v.data;
}
use of org.ejml.data.DMatrixRMaj in project narchy by automenta.
the class PrincipalComponentAnalysis method response.
/**
* Computes the dot product of each basis vector against the sample. Can be used as a measure
* for membership in the training sample set. High values correspond to a better fit.
*
* @param sample Sample of original data.
* @return Higher value indicates it is more likely to be a member of input dataset.
*/
public double response(double[] sample) {
if (sample.length != A.numCols)
throw new IllegalArgumentException("Expected input vector to be in sample space");
DMatrixRMaj dots = new DMatrixRMaj(numComponents, 1);
DMatrixRMaj s = DMatrixRMaj.wrap(A.numCols, 1, sample);
mult(V_t, s, dots);
return NormOps_DDRM.normF(dots);
}
use of org.ejml.data.DMatrixRMaj in project narchy by automenta.
the class EjmlOps method fillWithRow.
public static DMatrixRMaj fillWithRow(DMatrixRMaj matrix, int setrow) {
int rows = matrix.numRows;
int cols = matrix.numCols;
DMatrixRMaj result = new DMatrixRMaj(rows, cols);
for (int row = 0; row < rows; row++) {
for (int col = 0; col < cols; col++) {
result.set(row, col, matrix.get(setrow, col));
}
}
return result;
}
use of org.ejml.data.DMatrixRMaj in project narchy by automenta.
the class EJMLVsPython method testAssignCol.
@Test
public void testAssignCol() throws IOException {
double[][] Xin = MatrixUtils.simpleRead2DMatrix(new StringReader(s), " ");
DMatrixRMaj X = new DMatrixRMaj(Xin);
DMatrixRMaj sumR = new DMatrixRMaj(1, X.numCols);
sumCols(X, sumR);
double[][] pyasgn = { { 1., 2., 3., 4., 5. }, { 6., 7., 8., 9., 5. }, { 3., 4., 2., 7., 3. }, { 30., 30., 38., 42., 32. }, { 2., 4., 7., 8., 9. }, { 3., 4., 3., 3., 5. }, { 8., 6., 9., 4., 2. } };
insert(sumR, X, 3, 0);
assertEqualDoubleArrays(pyasgn, EjmlOps.extractDoubleArray(X), epsilon);
}
use of org.ejml.data.DMatrixRMaj in project narchy by automenta.
the class EJMLVsPython method testScaleTimes.
@Test
public void testScaleTimes() throws IOException {
double[][] Xin = MatrixUtils.simpleRead2DMatrix(new StringReader(s), " ");
DMatrixRMaj X = new DMatrixRMaj(Xin);
double[][] pyscle = { { -2., -4., -6., -8., -10. }, { -12., -14., -16., -18., -10. }, { -6., -8., -4., -14., -6. }, { -14., -6., -12., -14., -6. }, { -4., -8., -14., -16., -18. }, { -6., -8., -6., -6., -10. }, { -16., -12., -18., -8., -4. } };
scale(-2.0, X);
double[][] scale = EjmlOps.extractDoubleArray(X);
assertEqualDoubleArrays(pyscle, scale, epsilon);
}
Aggregations