Search in sources :

Example 51 with DenseVector

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

the class DistanceTest method jensenShannonDistance.

/**
 */
@Test
public void jensenShannonDistance() {
    double precistion = 0.01;
    double expRes = 0.83;
    double[] pData = new double[] { 1.0, 0.0, 0.0 };
    Vector pV1 = new DenseVector(new double[] { 0.0, 1.0, 0.0 });
    Vector pV2 = new DenseVector(pData);
    DistanceMeasure distanceMeasure = new JensenShannonDistance();
    assertEquals(expRes, distanceMeasure.compute(pV1, pData), precistion);
    assertEquals(expRes, distanceMeasure.compute(pV1, pV2), precistion);
}
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 52 with DenseVector

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

the class NormalizationExample method createCache.

/**
 */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
    CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setName("PERSONS");
    cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2));
    IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
    persons.put(1, new DenseVector(new Serializable[] { "Mike", 10, 20 }));
    persons.put(2, new DenseVector(new Serializable[] { "John", 20, 10 }));
    persons.put(3, new DenseVector(new Serializable[] { "George", 30, 0 }));
    persons.put(4, new DenseVector(new Serializable[] { "Karl", 25, 15 }));
    return persons;
}
Also used : Serializable(java.io.Serializable) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Vector(org.apache.ignite.ml.math.primitives.vector.Vector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)

Example 53 with DenseVector

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

the class StandardScalerExample method createCache.

/**
 */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
    CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setName("PERSONS");
    cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2));
    IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
    persons.put(1, new DenseVector(new Serializable[] { "Mike", 42, 10000 }));
    persons.put(2, new DenseVector(new Serializable[] { "John", 32, 64000 }));
    persons.put(3, new DenseVector(new Serializable[] { "George", 53, 120000 }));
    persons.put(4, new DenseVector(new Serializable[] { "Karl", 24, 70000 }));
    return persons;
}
Also used : Serializable(java.io.Serializable) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Vector(org.apache.ignite.ml.math.primitives.vector.Vector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector)

Example 54 with DenseVector

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

the class TitanicUtils method readPassengers.

/**
 * Read passengers data from csv file.
 *
 * @param ignite The ignite.
 * @return The filled cache.
 * @throws FileNotFoundException If data file is not found.
 */
public static IgniteCache<Integer, Vector> readPassengers(Ignite ignite) throws FileNotFoundException {
    IgniteCache<Integer, Vector> cache = getCache(ignite);
    Scanner scanner = new Scanner(IgniteUtils.resolveIgnitePath("examples/src/main/resources/datasets/titanic.csv"));
    int cnt = 0;
    while (scanner.hasNextLine()) {
        String row = scanner.nextLine();
        if (cnt == 0) {
            cnt++;
            continue;
        }
        String[] cells = row.split(";");
        Serializable[] data = new Serializable[cells.length];
        NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);
        for (int i = 0; i < cells.length; i++) try {
            data[i] = "".equals(cells[i]) ? Double.NaN : Double.valueOf(cells[i]);
        } catch (java.lang.NumberFormatException e) {
            try {
                data[i] = format.parse(cells[i]).doubleValue();
            } catch (ParseException e1) {
                data[i] = cells[i];
            }
        }
        cache.put(cnt++, new DenseVector(data));
    }
    return cache;
}
Also used : Scanner(java.util.Scanner) Serializable(java.io.Serializable) ParseException(java.text.ParseException) 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) NumberFormat(java.text.NumberFormat)

Example 55 with DenseVector

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

the class CacheBasedDatasetExample method createCache.

/**
 */
private static IgniteCache<Integer, Vector> createCache(Ignite ignite) {
    CacheConfiguration<Integer, Vector> cacheConfiguration = new CacheConfiguration<>();
    cacheConfiguration.setName("PERSONS");
    cacheConfiguration.setAffinity(new RendezvousAffinityFunction(false, 2));
    IgniteCache<Integer, Vector> persons = ignite.createCache(cacheConfiguration);
    persons.put(1, new DenseVector(new Serializable[] { "Mike", 42, 10000 }));
    persons.put(2, new DenseVector(new Serializable[] { "John", 32, 64000 }));
    persons.put(3, new DenseVector(new Serializable[] { "George", 53, 120000 }));
    persons.put(4, new DenseVector(new Serializable[] { "Karl", 24, 70000 }));
    return persons;
}
Also used : Serializable(java.io.Serializable) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Vector(org.apache.ignite.ml.math.primitives.vector.Vector) DenseVector(org.apache.ignite.ml.math.primitives.vector.impl.DenseVector) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) 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