Search in sources :

Example 11 with DenseMatrix

use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.

the class BlasTest method testSyrNonSquareMatrix.

/**
 * Tests 'syr' operation for non-square dense matrix A.
 */
@Test(expected = NonSquareMatrixException.class)
public void testSyrNonSquareMatrix() {
    double alpha = 3.0;
    DenseMatrix a = new DenseMatrix(new double[][] { { 10.0, 11.0, 12.0 }, { 0.0, 1.0, 2.0 } }, 2);
    Vector x = new DenseVector(new double[] { 1.0, 2.0 });
    new Blas().syr(alpha, x, a);
}
Also used : SparseVector(org.apache.ignite.ml.math.primitives.vector.impl.SparseVector) Vector(org.apache.ignite.ml.math.primitives.vector.Vector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Example 12 with DenseMatrix

use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.

the class BlasTest method testGemvDenseDenseDense.

/**
 * Tests 'gemv' operation for dense matrix A, dense vector x and dense vector y.
 */
@Test
public void testGemvDenseDenseDense() {
    // y := alpha * A * x + beta * y
    double alpha = 3.0;
    DenseMatrix a = new DenseMatrix(new double[][] { { 10.0, 11.0 }, { 0.0, 1.0 } }, 2);
    DenseVector x = new DenseVector(new double[] { 1.0, 2.0 });
    double beta = 2.0;
    DenseVector y = new DenseVector(new double[] { 3.0, 4.0 });
    DenseVector exp = (DenseVector) y.times(beta).plus(a.times(x).times(alpha));
    Blas.gemv(alpha, a, x, beta, y);
    Assert.assertEquals(exp, y);
}
Also used : DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Example 13 with DenseMatrix

use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.

the class GmmPartitionDataTest method testUpdatePcxi.

/**
 */
@Test
public void testUpdatePcxi() {
    GmmPartitionData.updatePcxi(data, VectorUtils.of(0.3, 0.7), Arrays.asList(new MultivariateGaussianDistribution(VectorUtils.of(1.0, 0.5), new DenseMatrix(new double[] { 0.5, 0., 0., 1. }, 2)), new MultivariateGaussianDistribution(VectorUtils.of(0.0, 0.5), new DenseMatrix(new double[] { 1.0, 0., 0., 1. }, 2))));
    assertEquals(0.49, data.pcxi(0, 0), 1e-2);
    assertEquals(0.50, data.pcxi(1, 0), 1e-2);
    assertEquals(0.18, data.pcxi(0, 1), 1e-2);
    assertEquals(0.81, data.pcxi(1, 1), 1e-2);
    assertEquals(0.49, data.pcxi(0, 2), 1e-2);
    assertEquals(0.50, data.pcxi(1, 2), 1e-2);
}
Also used : MultivariateGaussianDistribution(org.apache.ignite.ml.math.stat.MultivariateGaussianDistribution) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) Test(org.junit.Test)

Example 14 with DenseMatrix

use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.

the class TracerTest method testHtmlMatrixTracer.

/**
 */
@Test
public void testHtmlMatrixTracer() throws IOException {
    Matrix mtx1 = makeRandomMatrix(100, 100);
    // Custom color mapping.
    verifyShowHtml(() -> Tracer.showHtml(mtx1, COLOR_MAPPER));
    Matrix mtx2 = new DenseMatrix(100, 100);
    double MAX = (double) (mtx2.rowSize() * mtx2.columnSize());
    mtx2.assign((x, y) -> (double) (x * y) / MAX);
    verifyShowHtml(() -> Tracer.showHtml(mtx2));
}
Also used : Matrix(org.apache.ignite.ml.math.primitives.matrix.Matrix) 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 15 with DenseMatrix

use of org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix in project ignite by apache.

the class TracerTest method testHtmlMatrixTracerWithAsciiFallback.

/**
 */
@Test
public void testHtmlMatrixTracerWithAsciiFallback() throws IOException {
    Matrix mtx1 = makeRandomMatrix(100, 100);
    // Custom color mapping.
    Tracer.showHtml(mtx1, COLOR_MAPPER, true);
    Matrix mtx2 = new DenseMatrix(100, 100);
    double MAX = (double) (mtx2.rowSize() * mtx2.columnSize());
    mtx2.assign((x, y) -> (double) (x * y) / MAX);
    Tracer.showHtml(mtx2, true);
}
Also used : Matrix(org.apache.ignite.ml.math.primitives.matrix.Matrix) DenseMatrix(org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix) 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