Search in sources :

Example 46 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class VectorImplementationsTest method assignVectorTest.

/**
 */
@Test
public void assignVectorTest() {
    consumeSampleVectors((v, desc) -> {
        if (readOnly())
            return;
        final int size = v.size();
        final double[] ref = new double[size];
        final ElementsChecker checker = new ElementsChecker(v, ref, desc);
        for (int idx = 0; idx < size; idx++) ref[idx] = -ref[idx];
        v.assign(new DenseVector(ref));
        checker.assertCloseEnough(v, ref);
        assignVectorWrongCardinality(v, desc);
    });
}
Also used : DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Test(org.junit.Test) ExternalizeTest(org.apache.ignite.ml.math.ExternalizeTest)

Example 47 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class VectorToMatrixTest method testCross.

/**
 */
@Test
public void testCross() {
    consumeSampleVectors((v, desc) -> {
        if (!availableForTesting(v))
            return;
        fillWithNonZeroes(v);
        for (int delta : new int[] { -1, 0, 1 }) {
            final int size2 = v.size() + delta;
            if (size2 < 1)
                return;
            final Vector v2 = new DenseVector(size2);
            for (Vector.Element e : v2.all()) e.set(size2 - e.index());
            assertCross(v, v2, desc);
        }
    });
}
Also used : DelegatingVector(org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector) SparseVector(org.apache.ignite.ml.math.primitives.vector.impl.SparseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Test(org.junit.Test)

Example 48 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class PipelineMdlTest method verifyPredict.

/**
 */
private void verifyPredict(PipelineMdl mdl) {
    Vector observation = new DenseVector(new double[] { 1.0, 1.0 });
    TestUtils.assertEquals(sigmoid(1.0 + 2.0 * 1.0 + 3.0 * 1.0), mdl.predict(observation), PRECISION);
    observation = new DenseVector(new double[] { 2.0, 1.0 });
    TestUtils.assertEquals(sigmoid(1.0 + 2.0 * 2.0 + 3.0 * 1.0), mdl.predict(observation), PRECISION);
    observation = new DenseVector(new double[] { 1.0, 2.0 });
    TestUtils.assertEquals(sigmoid(1.0 + 2.0 * 1.0 + 3.0 * 2.0), mdl.predict(observation), PRECISION);
    observation = new DenseVector(new double[] { -2.0, 1.0 });
    TestUtils.assertEquals(sigmoid(1.0 - 2.0 * 2.0 + 3.0 * 1.0), mdl.predict(observation), PRECISION);
    observation = new DenseVector(new double[] { 1.0, -2.0 });
    TestUtils.assertEquals(sigmoid(1.0 + 2.0 * 1.0 - 3.0 * 2.0), mdl.predict(observation), PRECISION);
}
Also used : 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)

Example 49 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class LUDecompositionTest method solveVec.

/**
 */
@Test
public void solveVec() throws Exception {
    Vector sol = new LUDecomposition(testMatrix).solve(new DenseVector(testMatrix.rowSize()));
    assertEquals("Wrong solution vector size.", testMatrix.rowSize(), sol.size());
    for (int i = 0; i < sol.size(); i++) assertEquals("Unexpected value at index " + i, 0d, sol.getX(i), 0.0000001d);
}
Also used : 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) Test(org.junit.Test)

Example 50 with DenseVector

use of org.apache.ignite.ml.math.primitives.vector.impl.DenseVector in project ignite by apache.

the class DelegatingVectorConstructorTest method basicTest.

/**
 */
@Test
public void basicTest() {
    final Vector parent = new DenseVector(new double[] { 0, 1 });
    final DelegatingVector delegate = new DelegatingVector(parent);
    final int size = parent.size();
    assertEquals("Delegate size differs from expected.", size, delegate.size());
    assertEquals("Delegate vector differs from expected.", parent, delegate.getVector());
    for (int idx = 0; idx < size; idx++) assertDelegate(parent, delegate, idx);
}
Also used : DelegatingVector(org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector) DelegatingVector(org.apache.ignite.ml.math.primitives.vector.impl.DelegatingVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) Test(org.junit.Test)

Aggregations

DenseVector (org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)101 Vector (org.apache.ignite.ml.math.primitives.vector.Vector)59 Test (org.junit.Test)59 Serializable (java.io.Serializable)16 SparseVector (org.apache.ignite.ml.math.primitives.vector.impl.SparseVector)14 HashMap (java.util.HashMap)13 DenseMatrix (org.apache.ignite.ml.math.primitives.matrix.impl.DenseMatrix)13 DummyVectorizer (org.apache.ignite.ml.dataset.feature.extractor.impl.DummyVectorizer)10 LabeledVector (org.apache.ignite.ml.structures.LabeledVector)10 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)9 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)9 HashSet (java.util.HashSet)7 TrainerTest (org.apache.ignite.ml.common.TrainerTest)7 KMeansModel (org.apache.ignite.ml.clustering.kmeans.KMeansModel)5 LocalDatasetBuilder (org.apache.ignite.ml.dataset.impl.local.LocalDatasetBuilder)5 EuclideanDistance (org.apache.ignite.ml.math.distances.EuclideanDistance)5 IgniteDifferentiableVectorToDoubleFunction (org.apache.ignite.ml.math.functions.IgniteDifferentiableVectorToDoubleFunction)5 MLPArchitecture (org.apache.ignite.ml.nn.architecture.MLPArchitecture)5 OneHotEncoderPreprocessor (org.apache.ignite.ml.preprocessing.encoding.onehotencoder.OneHotEncoderPreprocessor)4 Random (java.util.Random)3