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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations