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);
}
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);
}
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);
}
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));
}
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);
}
Aggregations