Search in sources :

Example 1 with KMeansLocalClusterer

use of org.apache.ignite.ml.clustering.KMeansLocalClusterer in project ignite by apache.

the class KMeansLocalClustererExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 */
public static void main(String[] args) {
    // IMPL NOTE based on KMeansDistributedClustererTestSingleNode#testClusterizationOnDatasetWithObviousStructure
    System.out.println(">>> K-means local clusterer example started.");
    int ptsCnt = 10000;
    DenseLocalOnHeapMatrix points = new DenseLocalOnHeapMatrix(ptsCnt, 2);
    DatasetWithObviousStructure dataset = new DatasetWithObviousStructure(10000);
    List<Vector> massCenters = dataset.generate(points);
    EuclideanDistance dist = new EuclideanDistance();
    OrderedNodesComparator comp = new OrderedNodesComparator(dataset.centers().values().toArray(new Vector[] {}), dist);
    massCenters.sort(comp);
    KMeansLocalClusterer clusterer = new KMeansLocalClusterer(dist, 100, 1L);
    KMeansModel mdl = clusterer.cluster(points, 4);
    Vector[] resCenters = mdl.centers();
    Arrays.sort(resCenters, comp);
    System.out.println("Mass centers:");
    massCenters.forEach(Tracer::showAscii);
    System.out.println("Cluster centers:");
    Arrays.asList(resCenters).forEach(Tracer::showAscii);
    System.out.println("\n>>> K-means local clusterer example completed.");
}
Also used : EuclideanDistance(org.apache.ignite.ml.math.distances.EuclideanDistance) KMeansModel(org.apache.ignite.ml.clustering.KMeansModel) Tracer(org.apache.ignite.ml.math.Tracer) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) Vector(org.apache.ignite.ml.math.Vector) KMeansLocalClusterer(org.apache.ignite.ml.clustering.KMeansLocalClusterer)

Example 2 with KMeansLocalClusterer

use of org.apache.ignite.ml.clustering.KMeansLocalClusterer in project ignite by apache.

the class IgniteKMeansLocalClustererBenchmark method test.

/**
 * {@inheritDoc}
 */
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
    final DataChanger.Scale scale = new DataChanger.Scale();
    // IMPL NOTE originally taken from KMeansLocalClustererTest
    KMeansLocalClusterer clusterer = new KMeansLocalClusterer(new EuclideanDistance(), 1, 1L);
    double[] v1 = scale.mutate(new double[] { 1959, 325100 });
    double[] v2 = scale.mutate(new double[] { 1960, 373200 });
    DenseLocalOnHeapMatrix points = new DenseLocalOnHeapMatrix(new double[][] { v1, v2 });
    clusterer.cluster(points, 1);
    return true;
}
Also used : EuclideanDistance(org.apache.ignite.ml.math.distances.EuclideanDistance) DataChanger(org.apache.ignite.yardstick.ml.DataChanger) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) KMeansLocalClusterer(org.apache.ignite.ml.clustering.KMeansLocalClusterer)

Example 3 with KMeansLocalClusterer

use of org.apache.ignite.ml.clustering.KMeansLocalClusterer in project ignite by apache.

the class LocalModelsTest method getClusterModel.

/**
 */
private KMeansModel getClusterModel() {
    KMeansLocalClusterer clusterer = new KMeansLocalClusterer(new EuclideanDistance(), 1, 1L);
    double[] v1 = new double[] { 1959, 325100 };
    double[] v2 = new double[] { 1960, 373200 };
    DenseLocalOnHeapMatrix points = new DenseLocalOnHeapMatrix(new double[][] { v1, v2 });
    return clusterer.cluster(points, 1);
}
Also used : EuclideanDistance(org.apache.ignite.ml.math.distances.EuclideanDistance) DenseLocalOnHeapMatrix(org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix) KMeansLocalClusterer(org.apache.ignite.ml.clustering.KMeansLocalClusterer)

Aggregations

KMeansLocalClusterer (org.apache.ignite.ml.clustering.KMeansLocalClusterer)3 EuclideanDistance (org.apache.ignite.ml.math.distances.EuclideanDistance)3 DenseLocalOnHeapMatrix (org.apache.ignite.ml.math.impls.matrix.DenseLocalOnHeapMatrix)3 KMeansModel (org.apache.ignite.ml.clustering.KMeansModel)1 Tracer (org.apache.ignite.ml.math.Tracer)1 Vector (org.apache.ignite.ml.math.Vector)1 DataChanger (org.apache.ignite.yardstick.ml.DataChanger)1