Search in sources :

Example 91 with Vector

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

the class MatrixImplementationsTest method testFoldRow.

/**
 */
@Test
public void testFoldRow() {
    consumeSampleMatrix((m, desc) -> {
        if (ignore(m.getClass()))
            return;
        fillMatrix(m);
        Vector foldRows = m.foldRows(Vector::sum);
        for (int i = 0; i < m.rowSize(); i++) {
            Double locSum = 0d;
            for (int j = 0; j < m.columnSize(); j++) locSum += m.get(i, j);
            assertEquals("Unexpected value for " + desc + " at " + i, foldRows.get(i), locSum, 0d);
        }
    });
}
Also used : RandomVector(org.apache.ignite.ml.math.impls.vector.RandomVector) DenseLocalOffHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector) Vector(org.apache.ignite.ml.math.Vector) SparseLocalVector(org.apache.ignite.ml.math.impls.vector.SparseLocalVector) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) Test(org.junit.Test) ExternalizeTest(org.apache.ignite.ml.math.ExternalizeTest)

Example 92 with Vector

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

the class MatrixImplementationsTest method testFoldCol.

/**
 */
@Test
public void testFoldCol() {
    consumeSampleMatrix((m, desc) -> {
        if (ignore(m.getClass()))
            return;
        fillMatrix(m);
        Vector foldCols = m.foldColumns(Vector::sum);
        for (int j = 0; j < m.columnSize(); j++) {
            Double locSum = 0d;
            for (int i = 0; i < m.rowSize(); i++) locSum += m.get(i, j);
            assertEquals("Unexpected value for " + desc + " at " + j, foldCols.get(j), locSum, 0d);
        }
    });
}
Also used : RandomVector(org.apache.ignite.ml.math.impls.vector.RandomVector) DenseLocalOffHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOffHeapVector) Vector(org.apache.ignite.ml.math.Vector) SparseLocalVector(org.apache.ignite.ml.math.impls.vector.SparseLocalVector) DenseLocalOnHeapVector(org.apache.ignite.ml.math.impls.vector.DenseLocalOnHeapVector) Test(org.junit.Test) ExternalizeTest(org.apache.ignite.ml.math.ExternalizeTest)

Example 93 with Vector

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

the class CacheVectorTest method testPlusVec.

/**
 */
public void testPlusVec() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    IdentityValueMapper valMapper = new IdentityValueMapper();
    CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
    Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
    try {
        cacheVector.plus(testVec);
        TestCase.fail();
    } catch (UnsupportedOperationException ignored) {
    }
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) Vector(org.apache.ignite.ml.math.Vector) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 94 with Vector

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

the class CacheVectorTest method testTimesVector.

/**
 */
public void testTimesVector() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    IdentityValueMapper valMapper = new IdentityValueMapper();
    CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
    cacheVector.assign(1d);
    Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
    try {
        cacheVector.times(testVec);
        TestCase.fail();
    } catch (UnsupportedOperationException ignored) {
    }
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) Vector(org.apache.ignite.ml.math.Vector) UnsupportedOperationException(org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)

Example 95 with Vector

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

the class CacheVectorTest method testMin.

/**
 */
public void testMin() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    IdentityValueMapper valMapper = new IdentityValueMapper();
    CacheVector<Integer, Double> cacheVector = new CacheVector<>(size, getCache(), keyMapper, valMapper);
    Vector testVec = new DenseLocalOnHeapVector(IntStream.range(0, size).asDoubleStream().toArray());
    cacheVector.assign(testVec);
    assertEquals("Unexpected value.", cacheVector.minValue(), 0d, 0d);
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) Vector(org.apache.ignite.ml.math.Vector)

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