Search in sources :

Example 1 with VectorGenerator

use of org.apache.ignite.ml.util.generators.primitives.vector.VectorGenerator in project ignite by apache.

the class VectorGeneratorFamilyExample method main.

/**
 * Run example.
 *
 * @param args Args.
 */
public static void main(String[] args) throws IOException {
    // Family of ring sectors.
    VectorGenerator family1 = new VectorGeneratorsFamily.Builder().add(VectorGeneratorPrimitives.ring(5., 0, 2 * Math.PI)).add(VectorGeneratorPrimitives.ring(10., 0, Math.PI)).add(VectorGeneratorPrimitives.ring(15., Math.PI, 2 * Math.PI)).add(VectorGeneratorPrimitives.ring(20., 0, Math.PI / 2)).add(VectorGeneratorPrimitives.ring(25., Math.PI / 2, Math.PI)).add(VectorGeneratorPrimitives.ring(30., Math.PI, 3 * Math.PI / 2)).add(VectorGeneratorPrimitives.ring(35., 3 * Math.PI / 2, 2 * Math.PI)).build();
    // Family that constructed by 45 degree rotation from previous family.
    VectorGenerator family2 = family1.rotate(Math.PI / 4).map(v -> v.times(1.5));
    Tracer.showClassificationDatasetHtml("Family of ring sectors [first family]", family1.asDataStream(), 2000, 0, 1, true);
    Tracer.showClassificationDatasetHtml("Family of ring sectors [second family]", family2.asDataStream(), 2000, 0, 1, true);
    // Combination of families where first family represents a complex distribution for first class and
    // second family for second class.
    VectorGenerator family = new VectorGeneratorsFamily.Builder().add(family1).add(family2).build();
    Tracer.showClassificationDatasetHtml("Family of ring sectors [both families as two calsses]", family.asDataStream(), 2000, 0, 1, true);
    System.out.flush();
}
Also used : VectorGeneratorsFamily(org.apache.ignite.ml.util.generators.primitives.vector.VectorGeneratorsFamily) VectorGenerator(org.apache.ignite.ml.util.generators.primitives.vector.VectorGenerator)

Example 2 with VectorGenerator

use of org.apache.ignite.ml.util.generators.primitives.vector.VectorGenerator in project ignite by apache.

the class VectorGeneratorPrimitivesExample method main.

/**
 * Run example.
 *
 * @param args Args.
 */
public static void main(String... args) throws IOException {
    // Vectors from ring-like distribution.
    VectorGenerator fullRing = VectorGeneratorPrimitives.ring(10, 0, 2 * Math.PI);
    // Vectors from ring's sector distribution.
    VectorGenerator partOfRing = VectorGeneratorPrimitives.ring(15, -Math.PI / 2, Math.PI);
    // Vectors from distribution having filled circle shape.
    VectorGenerator circle = VectorGeneratorPrimitives.circle(14.5);
    // Vectors from uniform distribution in n-dimensional space.
    VectorGenerator parallelogram = VectorGeneratorPrimitives.parallelogram(VectorUtils.of(10, 15));
    // Vectors from gaussian.
    VectorGenerator gauss = VectorGeneratorPrimitives.gauss(VectorUtils.of(0.0, 0.0), VectorUtils.of(10., 15.));
    Tracer.showClassificationDatasetHtml("Full ring", fullRing.asDataStream(), 1500, 0, 1, false);
    Tracer.showClassificationDatasetHtml("Sector", partOfRing.asDataStream(), 1500, 0, 1, false);
    Tracer.showClassificationDatasetHtml("Circle", circle.asDataStream(), 1500, 0, 1, false);
    Tracer.showClassificationDatasetHtml("Parallelogram", parallelogram.asDataStream(), 1500, 0, 1, false);
    Tracer.showClassificationDatasetHtml("Gauss", gauss.asDataStream(), 1500, 0, 1, false);
    // Using of rotate for generator.
    VectorGenerator rotatedParallelogram = parallelogram.rotate(-Math.PI / 8);
    Tracer.showClassificationDatasetHtml("Rotated Parallelogram", rotatedParallelogram.asDataStream(), 1500, 0, 1, false);
    // Sum of generators where vectors from first generator are summed with corresponding vectors from second generator.
    VectorGenerator gaussPlusRing = gauss.plus(fullRing);
    Tracer.showClassificationDatasetHtml("Gauss plus ring", gaussPlusRing.asDataStream(), 1500, 0, 1, false);
    // Example of vector generator filtering.
    VectorGenerator filteredCircle = circle.filter(v -> Math.abs(v.get(0)) > 5);
    Tracer.showClassificationDatasetHtml("Filtered circle", filteredCircle.asDataStream(), 1500, 0, 1, false);
    // Example of using map function for vector generator.
    VectorGenerator mappedCircle = circle.map(v -> v.get(1) < 0 ? v : v.times(VectorUtils.of(2, 4)));
    Tracer.showClassificationDatasetHtml("Mapped circle", mappedCircle.asDataStream(), 1500, 0, 1, false);
    // Example of generators concatenation where each vector of first generator are concatenated with corresponding
    // vector from second generator.
    DataStreamGenerator ringAndGauss = fullRing.concat(gauss).asDataStream();
    Tracer.showClassificationDatasetHtml("Ring and gauss [x1, x2]", ringAndGauss, 1500, 0, 1, false);
    Tracer.showClassificationDatasetHtml("Ring and gauss [x2, x3]", ringAndGauss, 1500, 1, 2, false);
    Tracer.showClassificationDatasetHtml("Ring and gauss [x3, x4]", ringAndGauss, 1500, 2, 3, false);
    Tracer.showClassificationDatasetHtml("Ring and gauss [x4, x1]", ringAndGauss, 1500, 3, 0, false);
    // Example of vector generator function noize.
    VectorGenerator noisifiedRing = fullRing.noisify(new DiscreteRandomProducer(0.1, 0.2, 0.3, 0.4));
    Tracer.showClassificationDatasetHtml("Noisified ring", noisifiedRing.asDataStream(), 1500, 0, 1, false);
    // Example of complex distribution with "axe" shape.
    VectorGenerator axeBlade = circle.filter(v -> Math.abs(v.get(1)) > 5.).rotate(Math.PI / 4).filter(v -> Math.abs(v.get(0)) > 1.5).rotate(-Math.PI / 2).filter(v -> Math.abs(v.get(0)) > 1.5).rotate(Math.PI / 4).filter(v -> Math.sqrt(v.getLengthSquared()) > 10).map(v -> Math.abs(v.get(0)) > 8 && Math.abs(v.get(1)) < 9 ? v.times(0.5) : v).rotate(Math.PI / 2);
    Tracer.showClassificationDatasetHtml("Axe blade", axeBlade.asDataStream(), 1500, 0, 1, false);
    System.out.flush();
}
Also used : DiscreteRandomProducer(org.apache.ignite.ml.util.generators.primitives.scalar.DiscreteRandomProducer) DataStreamGenerator(org.apache.ignite.ml.util.generators.DataStreamGenerator) VectorGenerator(org.apache.ignite.ml.util.generators.primitives.vector.VectorGenerator) VectorUtils(org.apache.ignite.ml.math.primitives.vector.VectorUtils) VectorGeneratorPrimitives(org.apache.ignite.ml.util.generators.primitives.vector.VectorGeneratorPrimitives) IOException(java.io.IOException) Tracer(org.apache.ignite.ml.math.Tracer) DiscreteRandomProducer(org.apache.ignite.ml.util.generators.primitives.scalar.DiscreteRandomProducer) DataStreamGenerator(org.apache.ignite.ml.util.generators.DataStreamGenerator) VectorGenerator(org.apache.ignite.ml.util.generators.primitives.vector.VectorGenerator)

Aggregations

VectorGenerator (org.apache.ignite.ml.util.generators.primitives.vector.VectorGenerator)2 IOException (java.io.IOException)1 Tracer (org.apache.ignite.ml.math.Tracer)1 VectorUtils (org.apache.ignite.ml.math.primitives.vector.VectorUtils)1 DataStreamGenerator (org.apache.ignite.ml.util.generators.DataStreamGenerator)1 DiscreteRandomProducer (org.apache.ignite.ml.util.generators.primitives.scalar.DiscreteRandomProducer)1 VectorGeneratorPrimitives (org.apache.ignite.ml.util.generators.primitives.vector.VectorGeneratorPrimitives)1 VectorGeneratorsFamily (org.apache.ignite.ml.util.generators.primitives.vector.VectorGeneratorsFamily)1