use of org.apache.ignite.ml.math.distances.EuclideanDistance in project ignite by apache.
the class IgniteKMeansDistributedClustererBenchmark method test.
/**
* {@inheritDoc}
*/
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
final DataChanger.Scale scale = new DataChanger.Scale();
// Create IgniteThread, we must work with SparseDistributedMatrix inside IgniteThread
// because we create ignite cache internally.
IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(), this.getClass().getSimpleName(), new Runnable() {
/**
* {@inheritDoc}
*/
@Override
public void run() {
// IMPL NOTE originally taken from KMeansDistributedClustererTest
KMeansDistributedClusterer clusterer = new KMeansDistributedClusterer(new EuclideanDistance(), 1, 1, 1L);
double[] v1 = scale.mutate(new double[] { 1959, 325100 });
double[] v2 = scale.mutate(new double[] { 1960, 373200 });
SparseDistributedMatrix points = new SparseDistributedMatrix(2, 2, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
points.setRow(0, v1);
points.setRow(1, v2);
clusterer.cluster(points, 1);
points.destroy();
}
});
igniteThread.start();
igniteThread.join();
return true;
}
use of org.apache.ignite.ml.math.distances.EuclideanDistance 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;
}
use of org.apache.ignite.ml.math.distances.EuclideanDistance in project ignite by apache.
the class IgniteKNNClassificationBenchmark method test.
/**
* {@inheritDoc}
*/
@Override
public boolean test(Map<Object, Object> ctx) throws Exception {
// Create IgniteThread, we must work with SparseDistributedMatrix inside IgniteThread
// because we create ignite cache internally.
IgniteThread igniteThread = new IgniteThread(ignite.configuration().getIgniteInstanceName(), this.getClass().getSimpleName(), new Runnable() {
/**
* {@inheritDoc}
*/
@Override
public void run() {
// IMPL NOTE originally taken from KNNClassificationExample.
// Obtain shuffled dataset.
LabeledDataset dataset = new Datasets().shuffleIris((int) (DataChanger.next()));
// Random splitting of iris data as 70% train and 30% test datasets.
LabeledDatasetTestTrainPair split = new LabeledDatasetTestTrainPair(dataset, 0.3);
LabeledDataset test = split.test();
LabeledDataset train = split.train();
KNNModel knnMdl = new KNNModel(5, new EuclideanDistance(), KNNStrategy.SIMPLE, train);
// Calculate predicted classes.
for (int i = 0; i < test.rowSize() - 1; i++) knnMdl.apply(test.getRow(i).features());
}
});
igniteThread.start();
igniteThread.join();
return true;
}
use of org.apache.ignite.ml.math.distances.EuclideanDistance 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);
}
use of org.apache.ignite.ml.math.distances.EuclideanDistance in project ignite by apache.
the class KMeansDistributedClustererTestSingleNode method testPerformClusterAnalysisDegenerate.
/**
*/
public void testPerformClusterAnalysisDegenerate() {
IgniteUtils.setCurrentIgniteName(ignite.configuration().getIgniteInstanceName());
KMeansDistributedClusterer clusterer = new KMeansDistributedClusterer(new EuclideanDistance(), 1, 1, 1L);
double[] v1 = new double[] { 1959, 325100 };
double[] v2 = new double[] { 1960, 373200 };
SparseDistributedMatrix points = new SparseDistributedMatrix(2, 2, StorageConstants.ROW_STORAGE_MODE, StorageConstants.RANDOM_ACCESS_MODE);
points.setRow(0, v1);
points.setRow(1, v2);
KMeansModel mdl = clusterer.cluster(points, 1);
Assert.assertEquals(1, mdl.centers().length);
Assert.assertEquals(2, mdl.centers()[0].size());
}
Aggregations