Search in sources :

Example 86 with DenseVector

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

the class LinearRegressionModelTest method testPredict.

/**
 */
@Test
public void testPredict() {
    Vector weights = new DenseVector(new double[] { 2.0, 3.0 });
    LinearRegressionModel mdl = new LinearRegressionModel(weights, 1.0);
    assertTrue(!mdl.toString().isEmpty());
    assertTrue(!mdl.toString(true).isEmpty());
    assertTrue(!mdl.toString(false).isEmpty());
    Vector observation = new DenseVector(new double[] { 1.0, 1.0 });
    TestUtils.assertEquals(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(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(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(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(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) Test(org.junit.Test)

Example 87 with DenseVector

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

the class LogisticRegressionModelTest method testPredict.

/**
 */
@Test
public void testPredict() {
    Vector weights = new DenseVector(new double[] { 2.0, 3.0 });
    assertFalse(new LogisticRegressionModel(weights, 1.0).isKeepingRawLabels());
    assertEquals(0.1, new LogisticRegressionModel(weights, 1.0).withThreshold(0.1).threshold(), 0);
    assertTrue(!new LogisticRegressionModel(weights, 1.0).toString().isEmpty());
    assertTrue(!new LogisticRegressionModel(weights, 1.0).toString(true).isEmpty());
    assertTrue(!new LogisticRegressionModel(weights, 1.0).toString(false).isEmpty());
    verifyPredict(new LogisticRegressionModel(weights, 1.0).withRawLabels(true));
    verifyPredict(new LogisticRegressionModel(null, 1.0).withRawLabels(true).withWeights(weights));
    verifyPredict(new LogisticRegressionModel(weights, 1.0).withRawLabels(true).withThreshold(0.5));
    verifyPredict(new LogisticRegressionModel(weights, 0.0).withRawLabels(true).withIntercept(1.0));
}
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 88 with DenseVector

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

the class LogisticRegressionModelTest method verifyPredict.

/**
 */
private void verifyPredict(LogisticRegressionModel 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 89 with DenseVector

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

the class PipelineMdlTest method testPredict.

/**
 */
@Test
public void testPredict() {
    Vector weights = new DenseVector(new double[] { 2.0, 3.0 });
    verifyPredict(getMdl(new LogisticRegressionModel(weights, 1.0).withRawLabels(true)));
}
Also used : LogisticRegressionModel(org.apache.ignite.ml.regressions.logistic.LogisticRegressionModel) 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 90 with DenseVector

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

the class VectorUtils method concat.

/**
 * Concatenates given vectors.
 *
 * @param vs Other vectors.
 * @return Concatenation result.
 */
public static Vector concat(Vector... vs) {
    Vector res = vs.length == 0 ? new DenseVector() : vs[0];
    for (int i = 1; i < vs.length; i++) {
        Vector v = vs[i];
        res = concat(res, v);
    }
    return res;
}
Also used : SparseVector(org.apache.ignite.ml.math.primitives.vector.impl.SparseVector) DelegatingNamedVector(org.apache.ignite.ml.math.primitives.vector.impl.DelegatingNamedVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)

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