use of org.apache.ignite.ml.math.primitives.vector.Vector in project ignite by apache.
the class ParametricVectorGeneratorTest method testGet.
/**
*/
@Test
public void testGet() {
Vector vec = new ParametricVectorGenerator(() -> 2., t -> t, t -> 2 * t, t -> 3 * t, t -> 100.).get();
assertEquals(4, vec.size());
assertArrayEquals(new double[] { 2., 4., 6., 100. }, vec.asArray(), 1e-7);
}
use of org.apache.ignite.ml.math.primitives.vector.Vector in project ignite by apache.
the class VectorGeneratorTest method duplicateRandomFeatures.
/**
*/
@Test
public void duplicateRandomFeatures() {
VectorGenerator g1 = VectorGeneratorPrimitives.constant(VectorUtils.of(1., 2., 3., 4.)).duplicateRandomFeatures(2, 1L);
double[] exp = { 1., 2., 3., 4., 3., 1. };
Vector v1 = g1.get();
Vector v2 = g1.get();
assertArrayEquals(exp, v1.asArray(), 1e-7);
try {
assertArrayEquals(v1.asArray(), v2.asArray(), 1e-7);
} catch (ArrayComparisonFailure e) {
// this is valid situation - duplicator should get different features
}
}
use of org.apache.ignite.ml.math.primitives.vector.Vector in project ignite by apache.
the class VectorGeneratorTest method rotate.
/**
*/
@Test
public void rotate() {
double[] angles = { 0., Math.PI / 2, -Math.PI / 2, Math.PI, 2 * Math.PI, Math.PI / 4 };
Vector[] exp = new Vector[] { VectorUtils.of(1., 0., 100.), VectorUtils.of(0., -1., 100.), VectorUtils.of(0., 1., 100.), VectorUtils.of(-1., 0., 100.), VectorUtils.of(1., 0., 100.), VectorUtils.of(0.707, -0.707, 100.) };
for (int i = 0; i < angles.length; i++) {
Vector res = VectorGeneratorPrimitives.constant(VectorUtils.of(1., 0., 100.)).rotate(angles[i]).get();
assertArrayEquals(exp[i].asArray(), res.asArray(), 1e-3);
}
}
use of org.apache.ignite.ml.math.primitives.vector.Vector in project ignite by apache.
the class SVMBinaryTrainerTest method testUpdate.
/**
*/
@Test
public void testUpdate() {
Map<Integer, double[]> cacheMock = new HashMap<>();
for (int i = 0; i < twoLinearlySeparableClasses.length; i++) cacheMock.put(i, twoLinearlySeparableClasses[i]);
SVMLinearClassificationTrainer trainer = new SVMLinearClassificationTrainer().withAmountOfIterations(1000).withSeed(1234L);
Vectorizer<Integer, double[], Integer, Double> vectorizer = new DoubleArrayVectorizer<Integer>().labeled(Vectorizer.LabelCoordinate.FIRST);
SVMLinearClassificationModel originalMdl = trainer.fit(cacheMock, parts, vectorizer);
SVMLinearClassificationModel updatedOnSameDS = trainer.update(originalMdl, cacheMock, parts, vectorizer);
SVMLinearClassificationModel updatedOnEmptyDS = trainer.update(originalMdl, new HashMap<>(), parts, vectorizer);
Vector v = VectorUtils.of(100, 10);
TestUtils.assertEquals(originalMdl.predict(v), updatedOnSameDS.predict(v), PRECISION);
TestUtils.assertEquals(originalMdl.predict(v), updatedOnEmptyDS.predict(v), PRECISION);
}
use of org.apache.ignite.ml.math.primitives.vector.Vector in project ignite by apache.
the class VectorGeneratorsFamilyTest method testGet.
/**
*/
@Test
public void testGet() {
VectorGeneratorsFamily family = new VectorGeneratorsFamily.Builder().add(() -> VectorUtils.of(0.)).add(() -> VectorUtils.of(1.)).add(() -> VectorUtils.of(2.)).build(0L);
Set<Double> validValues = DoubleStream.of(0., 1., 2.).boxed().collect(Collectors.toSet());
for (int i = 0; i < 100; i++) {
Vector vector = family.get();
assertTrue(validValues.contains(vector.get(0)));
}
}
Aggregations