use of org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView in project ignite by apache.
the class LUDecompositionTest method matrixUtilTest.
/**
* Test for {@link MatrixUtil} features (more specifically, we test matrix which does not have
* a native like/copy methods support).
*/
@Test
public void matrixUtilTest() {
LUDecomposition dec = new LUDecomposition(new PivotedMatrixView(testMatrix));
Matrix luDecompositionL = dec.getL();
assertEquals("Unexpected L row size.", testL.rowSize(), luDecompositionL.rowSize());
assertEquals("Unexpected L column size.", testL.columnSize(), luDecompositionL.columnSize());
for (int i = 0; i < testL.rowSize(); i++) for (int j = 0; j < testL.columnSize(); j++) assertEquals("Unexpected L value at (" + i + "," + j + ").", testL.getX(i, j), luDecompositionL.getX(i, j), 0.0000001d);
Matrix luDecompositionU = dec.getU();
assertEquals("Unexpected U row size.", testU.rowSize(), luDecompositionU.rowSize());
assertEquals("Unexpected U column size.", testU.columnSize(), luDecompositionU.columnSize());
for (int i = 0; i < testU.rowSize(); i++) for (int j = 0; j < testU.columnSize(); j++) assertEquals("Unexpected U value at (" + i + "," + j + ").", testU.getX(i, j), luDecompositionU.getX(i, j), 0.0000001d);
Matrix luDecompositionP = dec.getP();
assertEquals("Unexpected P row size.", testP.rowSize(), luDecompositionP.rowSize());
assertEquals("Unexpected P column size.", testP.columnSize(), luDecompositionP.columnSize());
for (int i = 0; i < testP.rowSize(); i++) for (int j = 0; j < testP.columnSize(); j++) assertEquals("Unexpected P value at (" + i + "," + j + ").", testP.getX(i, j), luDecompositionP.getX(i, j), 0.0000001d);
dec.destroy();
}
use of org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView in project ignite by apache.
the class LUDecompositionTest method solveVec.
/** */
@Test
public void solveVec() throws Exception {
Vector sol = new LUDecomposition(new PivotedMatrixView(testMatrix)).solve(new DenseLocalOnHeapVector(testMatrix.rowSize()));
assertEquals("Wrong solution vector size.", testMatrix.rowSize(), sol.size());
for (int i = 0; i < sol.size(); i++) assertEquals("Unexpected value at index " + i, 0d, sol.getX(i), 0.0000001d);
}
use of org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView in project ignite by apache.
the class LUDecompositionTest method solveMtx.
/** */
@Test
public void solveMtx() throws Exception {
Matrix sol = new LUDecomposition(new PivotedMatrixView(testMatrix)).solve(new DenseLocalOnHeapMatrix(testMatrix.rowSize(), testMatrix.rowSize()));
assertEquals("Wrong solution matrix row size.", testMatrix.rowSize(), sol.rowSize());
assertEquals("Wrong solution matrix column size.", testMatrix.rowSize(), sol.columnSize());
for (int row = 0; row < sol.rowSize(); row++) for (int col = 0; col < sol.columnSize(); col++) assertEquals("Unexpected P value at (" + row + "," + col + ").", 0d, sol.getX(row, col), 0.0000001d);
}
Aggregations