Search in sources :

Example 21 with IdentityValueMapper

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

the class CacheMatrixTest method testSum.

/**
 */
public void testSum() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
    IgniteCache<Integer, Double> cache = getCache();
    CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
    double sum;
    initMatrix(cacheMatrix);
    sum = cacheMatrix.sum();
    assertTrue(Double.compare(sum, 0d) == 0);
    cacheMatrix.assign(1d);
    sum = cacheMatrix.sum();
    assertTrue(Double.compare(sum, rows * cols) == 0);
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper)

Example 22 with IdentityValueMapper

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

the class CacheMatrixTest method testGetSet.

/**
 */
public void testGetSet() throws Exception {
    MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
    IgniteCache<Integer, Double> cache = getCache();
    CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            double v = Math.random();
            cacheMatrix.set(i, j, v);
            assert Double.compare(v, cacheMatrix.get(i, j)) == 0;
            assert Double.compare(v, cache.get(keyMapper.apply(i, j))) == 0;
        }
    }
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper)

Example 23 with IdentityValueMapper

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

the class CacheMatrixTest method testMinMax.

/**
 */
public void testMinMax() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
    IgniteCache<Integer, Double> cache = getCache();
    final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
    for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) cacheMatrix.set(i, j, i * rows + j);
    assertEquals(0.0, cacheMatrix.minValue(), 0.0);
    assertEquals(rows * cols - 1, cacheMatrix.maxValue(), 0.0);
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper)

Example 24 with IdentityValueMapper

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

the class CacheMatrixTest method testExternalization.

/**
 */
public void testExternalization() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
    IgniteCache<Integer, Double> cache = getCache();
    final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
    ExternalizeTest<CacheMatrix<Integer, Double>> externalizeTest = new ExternalizeTest<CacheMatrix<Integer, Double>>() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void externalizeTest() {
            super.externalizeTest(cacheMatrix);
        }
    };
    externalizeTest.externalizeTest();
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper) ExternalizeTest(org.apache.ignite.ml.math.ExternalizeTest)

Example 25 with IdentityValueMapper

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

the class CacheMatrixTest method testMap.

/**
 */
public void testMap() {
    IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
    MatrixKeyMapper<Integer> keyMapper = getKeyMapper(rows, cols);
    IgniteCache<Integer, Double> cache = getCache();
    final CacheMatrix<Integer, Double> cacheMatrix = new CacheMatrix<>(rows, cols, cache, keyMapper, new IdentityValueMapper());
    initMatrix(cacheMatrix);
    cacheMatrix.map(value -> value + 10);
    for (int i = 0; i < rows; i++) for (int j = 0; j < cols; j++) assertEquals(10.0, cacheMatrix.getX(i, j), 0.0);
}
Also used : IdentityValueMapper(org.apache.ignite.ml.math.IdentityValueMapper)

Aggregations

IdentityValueMapper (org.apache.ignite.ml.math.IdentityValueMapper)37 UnsupportedOperationException (org.apache.ignite.ml.math.exceptions.UnsupportedOperationException)8 Vector (org.apache.ignite.ml.math.Vector)5 Ignite (org.apache.ignite.Ignite)2 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)2 ValueMapper (org.apache.ignite.ml.math.distributed.ValueMapper)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 ExternalizeTest (org.apache.ignite.ml.math.ExternalizeTest)1 MatrixKeyMapper (org.apache.ignite.ml.math.distributed.MatrixKeyMapper)1 VectorKeyMapper (org.apache.ignite.ml.math.distributed.VectorKeyMapper)1 CacheMatrix (org.apache.ignite.ml.math.impls.matrix.CacheMatrix)1 CacheVector (org.apache.ignite.ml.math.impls.vector.CacheVector)1