Search in sources :

Example 1 with PivotedMatrixView

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();
}
Also used : PivotedMatrixView(org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView) Matrix(org.apache.ignite.ml.math.Matrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) Test(org.junit.Test)

Example 2 with PivotedMatrixView

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);
}
Also used : PivotedMatrixView(org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) Vector(org.apache.ignite.ml.math.Vector) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) Test(org.junit.Test)

Example 3 with PivotedMatrixView

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);
}
Also used : PivotedMatrixView(org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView) Matrix(org.apache.ignite.ml.math.Matrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) Test(org.junit.Test)

Aggregations

PivotedMatrixView (org.apache.ignite.ml.math.impls.matrix.PivotedMatrixView)3 Test (org.junit.Test)3 Matrix (org.apache.ignite.ml.math.Matrix)2 DenseLocalOnHeapMatrix (org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)2 Vector (org.apache.ignite.ml.math.Vector)1 DenseLocalOnHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)1