Search in sources :

Example 21 with DenseMatrix

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);
}
Also used : DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Example 22 with DenseMatrix

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);
    }
}
Also used : ViewMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) ViewMatrixStorage(org.apache.ignite.ml.math.primitives.matrix.storage.ViewMatrixStorage) ViewMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Example 23 with DenseMatrix

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.");
}
Also used : ViewMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) ViewMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Example 24 with DenseMatrix

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");
}
Also used : DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Example 25 with DenseMatrix

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);
}
Also used : MultivariateGaussianDistribution(org.apache.ignite.ml.math.stat.MultivariateGaussianDistribution) Vector(org.apache.ignite.ml.math.primitives.vector.Vector) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Aggregations

DenseMatrix (org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix)39 Test (org.junit.Test)28 Matrix (org.apache.ignite.ml.math.primitives.matrix.Matrix)14 DenseVector (org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)14 MLPArchitecture (org.apache.ignite.ml.nn.architecture.MLPArchitecture)9 Vector (org.apache.ignite.ml.math.primitives.vector.Vector)8 SparseVector (org.apache.ignite.ml.math.primitives.vector.impl.SparseVector)4 MultivariateGaussianDistribution (org.apache.ignite.ml.math.stat.MultivariateGaussianDistribution)3 LabeledVector (org.apache.ignite.ml.structures.LabeledVector)3 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 EuclideanDistance (org.apache.ignite.ml.math.distances.EuclideanDistance)2 HammingDistance (org.apache.ignite.ml.math.distances.HammingDistance)2 ManhattanDistance (org.apache.ignite.ml.math.distances.ManhattanDistance)2 ViewMatrix (org.apache.ignite.ml.math.primitives.matrix.impl.ViewMatrix)2 VectorizedViewMatrix (org.apache.ignite.ml.math.primitives.vector.impl.VectorizedViewMatrix)2 MLPTrainer (org.apache.ignite.ml.nn.MLPTrainer)2 SimpleGDParameterUpdate (org.apache.ignite.ml.optimization.updatecalculators.SimpleGDParameterUpdate)2 SimpleGDUpdateCalculator (org.apache.ignite.ml.optimization.updatecalculators.SimpleGDUpdateCalculator)2 Path (java.nio.file.Path)1