use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.
the class LUDecompositionTest method solveMtx.
/**
*/
@Test
public void solveMtx() throws Exception {
Matrix sol = new LUDecomposition(testMatrix).solve(new DenseMatrix(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);
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.
the class MatrixViewConstructorTest method attributeTest.
/**
*/
@Test
public void attributeTest() {
for (Matrix m : new Matrix[] { new DenseMatrix(3, 3), new DenseMatrix(3, 4), new DenseMatrix(4, 3) }) {
ViewMatrix matrixView = new ViewMatrix(m, 0, 0, m.rowSize(), m.columnSize());
ViewMatrixStorage delegateStorage = (ViewMatrixStorage) matrixView.getStorage();
assertEquals(m.rowSize(), matrixView.rowSize());
assertEquals(m.columnSize(), matrixView.columnSize());
assertEquals(m.rowSize(), (delegateStorage).rowsLength());
assertEquals(m.columnSize(), (delegateStorage).columnsLength());
assertEquals(m.isDense(), delegateStorage.isDense());
assertEquals(m.isArrayBased(), delegateStorage.isArrayBased());
assertArrayEquals(m.getStorage().data(), delegateStorage.data(), 0.0);
}
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.
the class MatrixViewConstructorTest method invalidArgsTest.
/**
*/
@Test
public void invalidArgsTest() {
Matrix m = new DenseMatrix(1, 1);
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix((Matrix) null, 0, 0, 1, 1), "Null parent matrix.");
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix(m, -1, 0, 1, 1), "Invalid row offset.");
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix(m, 0, -1, 1, 1), "Invalid col offset.");
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix(m, 0, 0, 0, 1), "Invalid rows.");
DenseMatrixConstructorTest.verifyAssertionError(() -> new ViewMatrix(m, 0, 0, 1, 0), "Invalid cols.");
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.
the class DenseMatrixConstructorTest method invalidArgsTest.
/**
*/
@Test
public void invalidArgsTest() {
verifyAssertionError(() -> new DenseMatrix(0, 1), "invalid row parameter");
verifyAssertionError(() -> new DenseMatrix(1, 0), "invalid col parameter");
// noinspection ConstantConditions
verifyAssertionError(() -> new DenseMatrix(null), "null matrix parameter");
verifyAssertionError(() -> new DenseMatrix(new double[][] { null, new double[1] }), "null row in matrix");
}
use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.
the class GmmModelTest method testTrivialCasesWithOneComponent.
/**
*/
@Test
public void testTrivialCasesWithOneComponent() {
Vector mean = VectorUtils.of(1., 2.);
DenseMatrix covariance = MatrixUtil.fromList(Arrays.asList(VectorUtils.of(1, -0.5), VectorUtils.of(-0.5, 1)), true);
GmmModel gmm = new GmmModel(VectorUtils.of(1.0), Collections.singletonList(new MultivariateGaussianDistribution(mean, covariance)));
Assert.assertEquals(2, gmm.dimension());
Assert.assertEquals(1, gmm.countOfComponents());
Assert.assertEquals(VectorUtils.of(1.), gmm.componentsProbs());
Assert.assertEquals(0., gmm.predict(mean), 0.01);
Assert.assertEquals(1, gmm.likelihood(mean).size());
Assert.assertEquals(0.183, gmm.likelihood(mean).get(0), 0.01);
Assert.assertEquals(0.183, gmm.prob(mean), 0.01);
}
Aggregations