use of de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering in project elki by elki-project.
the class AbstractClusterAlgorithmTest method testFMeasure.
/**
* Test the clustering result by comparing the score with an expected value.
*
* @param database Database to test
* @param clustering Clustering result
* @param expected Expected score
*/
protected <O> void testFMeasure(Database database, Clustering<?> clustering, double expected) {
// Run by-label as reference
ByLabelClustering bylabel = new ByLabelClustering();
Clustering<Model> rbl = bylabel.run(database);
ClusterContingencyTable ct = new ClusterContingencyTable(true, false);
ct.process(clustering, rbl);
double score = ct.getPaircount().f1Measure();
Logging.getLogger(this.getClass()).verbose(this.getClass().getSimpleName() + " score: " + score + " expect: " + expected);
assertEquals(this.getClass().getSimpleName() + ": Score does not match.", expected, score, 0.0001);
}
use of de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering in project elki by elki-project.
the class ClusterContingencyTableTest method testCompareDatabases.
/**
* Validate {@link ClusterContingencyTable} with respect to its ability to
* compare data clusterings.
*/
@Test
public void testCompareDatabases() {
Database db = AbstractSimpleAlgorithmTest.makeSimpleDatabase(dataset, shoulds);
Clustering<Model> rai = new TrivialAllInOne().run(db);
Clustering<Model> ran = new TrivialAllNoise().run(db);
Clustering<?> rbl = new ByLabelClustering().run(db);
assertEquals(1.0, computeFMeasure(rai, rai, false), Double.MIN_VALUE);
assertEquals(1.0, computeFMeasure(ran, ran, false), Double.MIN_VALUE);
assertEquals(1.0, computeFMeasure(rbl, rbl, false), Double.MIN_VALUE);
assertEquals(0.009950248756218905, computeFMeasure(ran, rbl, true), Double.MIN_VALUE);
assertEquals(0.0033277870216306157, computeFMeasure(rai, ran, true), Double.MIN_VALUE);
assertEquals(0.5, /* 0.3834296724470135 */
computeFMeasure(rai, rbl, false), Double.MIN_VALUE);
}
use of de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering in project elki by elki-project.
the class DeLiCluTest method testDeLiCluResults.
/**
* Run DeLiClu with fixed parameters and compare the result to a golden
* standard.
*/
@Test
public void testDeLiCluResults() {
ListParameterization indexparams = new ListParameterization();
// We need a special index for this algorithm:
indexparams.addParameter(StaticArrayDatabase.Parameterizer.INDEX_ID, DeLiCluTreeFactory.class);
indexparams.addParameter(AbstractPageFileFactory.Parameterizer.PAGE_SIZE_ID, 1000);
Database db = makeSimpleDatabase(UNITTEST + "hierarchical-2d.ascii", 710, indexparams);
Clustering<?> clustering = //
new ELKIBuilder<>(OPTICSXi.class).with(DeLiClu.Parameterizer.MINPTS_ID, //
18).with(OPTICSXi.Parameterizer.XI_ID, //
0.038).with(OPTICSXi.Parameterizer.XIALG_ID, //
DeLiClu.class).build().run(db);
// Test F-Measure
Clustering<Model> rbl = new ByLabelClustering().run(db);
ClusterContingencyTable ct = new ClusterContingencyTable(true, false);
ct.process(clustering, rbl);
double score = ct.getPaircount().f1Measure();
// identical each time, the results will vary.
if (Math.abs(score - 0.8771174) < 1e-5) {
assertEquals("Score does not match.", 0.8771174, score, 1e-5);
} else {
assertEquals("Score does not match.", 0.8819664, score, 1e-5);
}
}
Aggregations