Search in sources :

Example 46 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class SparseBlockDistributedVectorTest method testCopy.

/**
 */
public void testCopy() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    sparseBlockDistributedVector = new SparseBlockDistributedVector(size);
    Vector cp = sparseBlockDistributedVector.copy();
    assertNotNull(cp);
    for (int i = 0; i < size; i++) assertEquals(UNEXPECTED_VAL, cp.get(i), sparseBlockDistributedVector.get(i), PRECISION);
}
Also used : Vector(org.apache.ignite.ml.math.Vector)

Example 47 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class VectorFoldMapTest method operatorTest.

/**
 */
private void operatorTest(Vector v, String desc, Function<Vector, Vector> op, Function<Double, Double> refOp) {
    final int size = v.size();
    final double[] ref = new double[size];
    VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc);
    Vector actual = op.apply(v);
    for (int idx = 0; idx < size; idx++) ref[idx] = refOp.apply(ref[idx]);
    checker.assertCloseEnough(actual, ref);
}
Also used : Vector(org.apache.ignite.ml.math.Vector)

Example 48 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class VectorFoldMapTest method operationVectorTest.

/**
 */
private void operationVectorTest(BiFunction<Double, Double, Double> operation, BiFunction<Vector, Vector, Vector> vecOperation) {
    consumeSampleVectors((v, desc) -> {
        // TODO: IGNTIE-5723, find out if more elaborate testing scenario is needed or it's okay as is.
        final int size = v.size();
        final double[] ref = new double[size];
        final VectorImplementationsTest.ElementsChecker checker = new VectorImplementationsTest.ElementsChecker(v, ref, desc);
        final Vector operand = v.copy();
        for (int idx = 0; idx < size; idx++) ref[idx] = operation.apply(ref[idx], ref[idx]);
        checker.assertCloseEnough(vecOperation.apply(v, operand), ref);
    });
}
Also used : Vector(org.apache.ignite.ml.math.Vector)

Example 49 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class VectorImplementationsTest method operationVectorTest.

/**
 */
private void operationVectorTest(BiFunction<Double, Double, Double> operation, BiFunction<Vector, Vector, Vector> vecOperation) {
    consumeSampleVectors((v, desc) -> {
        // TODO : IGNTIE-5723, find out if more elaborate testing scenario is needed or it's okay as is.
        final int size = v.size();
        final double[] ref = new double[size];
        final ElementsChecker checker = new ElementsChecker(v, ref, desc);
        final Vector operand = v.copy();
        for (int idx = 0; idx < size; idx++) ref[idx] = operation.apply(ref[idx], ref[idx]);
        checker.assertCloseEnough(vecOperation.apply(v, operand), ref);
        assertWrongCardinality(v, desc, vecOperation);
    });
}
Also used : Vector(org.apache.ignite.ml.math.Vector)

Example 50 with Vector

use of org.apache.ignite.ml.math.Vector in project ignite by apache.

the class VectorNormTest method getDistanceSquaredTest.

/**
 */
@Test
public void getDistanceSquaredTest() {
    consumeSampleVectors((v, desc) -> {
        // IMPL NOTE this initialises vector
        new VectorImplementationsTest.ElementsChecker(v, desc);
        final int size = v.size();
        final Vector vOnHeap = new DenseLocalOnHeapVector(size);
        final Vector vOffHeap = new DenseLocalOffHeapVector(size);
        invertValues(v, vOnHeap);
        invertValues(v, vOffHeap);
        for (int idx = 0; idx < size; idx++) {
            final double exp = v.get(idx);
            final int idxMirror = size - 1 - idx;
            assertTrue("On heap vector difference at " + desc + ", idx " + idx, exp - vOnHeap.get(idxMirror) == 0);
            assertTrue("Off heap vector difference at " + desc + ", idx " + idx, exp - vOffHeap.get(idxMirror) == 0);
        }
        // IMPL NOTE this won't mutate vOnHeap
        final double exp = vOnHeap.minus(v).getLengthSquared();
        final VectorImplementationsTest.Metric metric = new VectorImplementationsTest.Metric(exp, v.getDistanceSquared(vOnHeap));
        assertTrue("On heap vector not close enough at " + desc + ", " + metric, metric.closeEnough());
        final VectorImplementationsTest.Metric metric1 = new VectorImplementationsTest.Metric(exp, v.getDistanceSquared(vOffHeap));
        assertTrue("Off heap vector not close enough at " + desc + ", " + metric1, metric1.closeEnough());
    });
}
Also used : Vector(org.apache.ignite.ml.math.Vector) Test(org.junit.Test)

Aggregations

Vector (org.apache.ignite.ml.math.Vector)116 DenseLocalOnHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector)62 Test (org.junit.Test)29 EuclideanDistance (org.apache.ignite.ml.math.distances.EuclideanDistance)20 DenseLocalOnHeapMatrix (org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)20 Matrix (org.apache.ignite.ml.math.Matrix)19 SparseDistributedMatrix (org.apache.ignite.ml.math.impls.matrix.SparseDistributedMatrix)17 Random (java.util.Random)12 ArrayList (java.util.ArrayList)11 DistanceMeasure (org.apache.ignite.ml.math.distances.DistanceMeasure)10 Arrays (java.util.Arrays)9 Ignite (org.apache.ignite.Ignite)9 SparseDistributedMatrixStorage (org.apache.ignite.ml.math.impls.storage.matrix.SparseDistributedMatrixStorage)9 LabeledDataset (org.apache.ignite.ml.structures.LabeledDataset)9 UUID (java.util.UUID)8 Collections (java.util.Collections)7 List (java.util.List)7 MathIllegalArgumentException (org.apache.ignite.ml.math.exceptions.MathIllegalArgumentException)7 DenseLocalOffHeapVector (org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector)7 HashMap (java.util.HashMap)6