Skip to content

Commit

Permalink
Update tests, kNN instead of mknn as default.
Browse files Browse the repository at this point in the history
  • Loading branch information
kno10 committed Feb 27, 2024
1 parent a0f982e commit f5080ae
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import elki.Algorithm;
import elki.clustering.AbstractClusterAlgorithmTest;
import elki.clustering.dbscan.predicates.MutualNearestNeighborPredicate;
import elki.clustering.dbscan.predicates.NearestNeighborPredicate;
import elki.clustering.kmeans.KMeans;
import elki.clustering.kmeans.LloydKMeans;
import elki.data.Clustering;
Expand Down Expand Up @@ -59,12 +60,14 @@ public void testKMeansENFORCE() {

Relation<NumberVector> rel = db.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
double nn1 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 1) //
.with(NeighborConsistency.Par.PREDICATE_ID, NearestNeighborPredicate.class) //
.with(NearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(NearestNeighborPredicate.Par.KNN_ID, 1) //
.build().evaluateClustering(result, rel);
assertEquals("1NN-consistency was not enforced?", 1.0, nn1, 1e-15);
assertEquals("1NN-consistency was not enforced?", 0.998, nn1, 1e-15);

double nn10 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(NeighborConsistency.Par.PREDICATE_ID, MutualNearestNeighborPredicate.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 10) //
.build().evaluateClustering(result, rel);
Expand All @@ -85,10 +88,11 @@ public void testKMeansENFORCENoise() {

Relation<NumberVector> rel = db.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
double nn1 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 1) //
.with(NeighborConsistency.Par.PREDICATE_ID, NearestNeighborPredicate.class) //
.with(NearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(NearestNeighborPredicate.Par.KNN_ID, 1) //
.build().evaluateClustering(result, rel);
assertEquals("1NN-consistency was not enforced?", 1.0, nn1, 1e-15);
assertEquals("1NN-consistency was not enforced?", 0.9848, nn1, 1e-4);

double nn10 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import elki.clustering.AbstractClusterAlgorithmTest;
import elki.clustering.dbscan.predicates.MutualNearestNeighborPredicate;
import elki.clustering.dbscan.predicates.NearestNeighborPredicate;
import elki.clustering.kmeans.KMeans;
import elki.data.Clustering;
import elki.data.DoubleVector;
Expand Down Expand Up @@ -58,16 +59,17 @@ public void testFastKMeansCP() {

Relation<NumberVector> rel = db.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
double nn1 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 1) //
.with(NeighborConsistency.Par.PREDICATE_ID, NearestNeighborPredicate.class) //
.with(NearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(NearestNeighborPredicate.Par.KNN_ID, 1) //
.build().evaluateClustering(result, rel);
assertEquals("2NN-consistency was not enforced?", 1.0, nn1, 1e-15);
assertEquals("2NN-consistency was not enforced?", 0.996, nn1, 1e-15);

double nn10 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 10) //
.build().evaluateClustering(result, rel);
assertEquals("10NN-consistency not as expected?", 0.964, nn10, 1e-15);
assertEquals("10NN-consistency not as expected?", 0.954, nn10, 1e-15);
}

@Test
Expand All @@ -83,10 +85,11 @@ public void testFastKMeansCPNoise() {

Relation<NumberVector> rel = db.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
double nn1 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 1) //
.with(NeighborConsistency.Par.PREDICATE_ID, NearestNeighborPredicate.class) //
.with(NearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(NearestNeighborPredicate.Par.KNN_ID, 1) //
.build().evaluateClustering(result, rel);
assertEquals("1NN-consistency was not enforced?", 1.0, nn1, 1e-15);
assertEquals("1NN-consistency was not enforced?", 0.9848, nn1, 1e-4);

double nn10 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import elki.clustering.AbstractClusterAlgorithmTest;
import elki.clustering.dbscan.predicates.MutualNearestNeighborPredicate;
import elki.clustering.dbscan.predicates.NearestNeighborPredicate;
import elki.clustering.kmeans.KMeans;
import elki.data.Clustering;
import elki.data.DoubleVector;
Expand Down Expand Up @@ -58,16 +59,17 @@ public void testKMeansCP() {

Relation<NumberVector> rel = db.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
double nn1 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 1) //
.with(NeighborConsistency.Par.PREDICATE_ID, NearestNeighborPredicate.class) //
.with(NearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(NearestNeighborPredicate.Par.KNN_ID, 1) //
.build().evaluateClustering(result, rel);
assertEquals("2NN-consistency was not enforced?", 1.0, nn1, 1e-15);
assertEquals("2NN-consistency was not enforced?", 0.996, nn1, 1e-15);

double nn10 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 10) //
.build().evaluateClustering(result, rel);
assertEquals("10NN-consistency not as expected?", 0.964, nn10, 1e-15);
assertEquals("10NN-consistency not as expected?", 0.954, nn10, 1e-15);
}

@Test
Expand All @@ -83,10 +85,11 @@ public void testKMeansCPNoise() {

Relation<NumberVector> rel = db.getRelation(TypeUtil.NUMBER_VECTOR_FIELD);
double nn1 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(MutualNearestNeighborPredicate.Par.KNN_ID, 1) //
.with(NeighborConsistency.Par.PREDICATE_ID, NearestNeighborPredicate.class) //
.with(NearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
.with(NearestNeighborPredicate.Par.KNN_ID, 1) //
.build().evaluateClustering(result, rel);
assertEquals("1NN-consistency was not enforced?", 1.0, nn1, 1e-15);
assertEquals("1NN-consistency was not enforced?", 0.9848, nn1, 1e-4);

double nn10 = new ELKIBuilder<NeighborConsistency<NumberVector>>(NeighborConsistency.class) //
.with(MutualNearestNeighborPredicate.Par.DISTANCE_FUNCTION_ID, SquaredEuclideanDistance.STATIC) //
Expand Down

0 comments on commit f5080ae

Please sign in to comment.