Search in sources :

Example 1 with UniformRandomProducer

use of org.apache.ignite.ml.util.generators.primitives.scalar.UniformRandomProducer in project ignite by apache.

the class ParametricVectorGeneratorExample method main.

/**
 * Run example.
 *
 * @param args Args.
 */
public static void main(String... args) throws IOException {
    // Example of Archimedean spiral.
    DataStreamGenerator spiral = new ParametricVectorGenerator(// 't' will be in [-50, 50] range
    new UniformRandomProducer(-50, 50), t -> Math.cos(Math.abs(t)) * Math.abs(t), t -> Math.sin(Math.abs(t)) * Math.abs(t)).asDataStream();
    Tracer.showClassificationDatasetHtml("Spiral", spiral, 20000, 0, 1, false);
    // Example of heart shape.
    DataStreamGenerator heart = new ParametricVectorGenerator(new UniformRandomProducer(-50, 50), t -> 16 * Math.pow(Math.sin(t), 3), t -> 13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t)).asDataStream();
    Tracer.showClassificationDatasetHtml("Heart", heart, 2000, 0, 1, false);
    // Example of butterfly-like shape.
    DataStreamGenerator butterfly = new ParametricVectorGenerator(// 't' will be in [-100, 100] range
    new UniformRandomProducer(-100, 100), t -> 10 * Math.sin(t) * (Math.exp(Math.cos(t)) - 2 * Math.cos(4 * t) - Math.pow(Math.sin(t / 12), 5)), t -> 10 * Math.cos(t) * (Math.exp(Math.cos(t)) - 2 * Math.cos(4 * t) - Math.pow(Math.sin(t / 12), 5))).asDataStream();
    Tracer.showClassificationDatasetHtml("Butterfly", butterfly, 2000, 0, 1, false);
    System.out.flush();
}
Also used : DataStreamGenerator(org.apache.ignite.ml.util.generators.DataStreamGenerator) ParametricVectorGenerator(org.apache.ignite.ml.util.generators.primitives.vector.ParametricVectorGenerator) IOException(java.io.IOException) Tracer(org.apache.ignite.ml.math.Tracer) UniformRandomProducer(org.apache.ignite.ml.util.generators.primitives.scalar.UniformRandomProducer) UniformRandomProducer(org.apache.ignite.ml.util.generators.primitives.scalar.UniformRandomProducer) ParametricVectorGenerator(org.apache.ignite.ml.util.generators.primitives.vector.ParametricVectorGenerator) DataStreamGenerator(org.apache.ignite.ml.util.generators.DataStreamGenerator)

Example 2 with UniformRandomProducer

use of org.apache.ignite.ml.util.generators.primitives.scalar.UniformRandomProducer in project ignite by apache.

the class VectorGeneratorTest method testMap.

/**
 */
@Test
public void testMap() {
    Vector originalVec = new UniformRandomProducer(-1, 1).vectorize(2).get();
    Vector doubledVec = VectorGeneratorPrimitives.constant(originalVec).map(v -> v.times(2.)).get();
    assertArrayEquals(originalVec.times(2.).asArray(), doubledVec.asArray(), 1e-7);
}
Also used : CardinalityException(org.apache.ignite.ml.math.exceptions.math.CardinalityException) ArrayComparisonFailure(org.junit.internal.ArrayComparisonFailure) VectorUtils(org.apache.ignite.ml.math.primitives.vector.VectorUtils) Vector(org.apache.ignite.ml.math.primitives.vector.Vector) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UniformRandomProducer(org.apache.ignite.ml.util.generators.primitives.scalar.UniformRandomProducer) UniformRandomProducer(org.apache.ignite.ml.util.generators.primitives.scalar.UniformRandomProducer) Vector(org.apache.ignite.ml.math.primitives.vector.Vector) Test(org.junit.Test)

Aggregations

UniformRandomProducer (org.apache.ignite.ml.util.generators.primitives.scalar.UniformRandomProducer)2 IOException (java.io.IOException)1 Tracer (org.apache.ignite.ml.math.Tracer)1 CardinalityException (org.apache.ignite.ml.math.exceptions.math.CardinalityException)1 Vector (org.apache.ignite.ml.math.primitives.vector.Vector)1 VectorUtils (org.apache.ignite.ml.math.primitives.vector.VectorUtils)1 DataStreamGenerator (org.apache.ignite.ml.util.generators.DataStreamGenerator)1 ParametricVectorGenerator (org.apache.ignite.ml.util.generators.primitives.vector.ParametricVectorGenerator)1 Assert.assertArrayEquals (org.junit.Assert.assertArrayEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 ArrayComparisonFailure (org.junit.internal.ArrayComparisonFailure)1