Search in sources :

Example 1 with ByLabelClustering

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);
}
Also used : Model(de.lmu.ifi.dbs.elki.data.model.Model) ByLabelClustering(de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering) ClusterContingencyTable(de.lmu.ifi.dbs.elki.evaluation.clustering.ClusterContingencyTable)

Example 2 with ByLabelClustering

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);
}
Also used : Database(de.lmu.ifi.dbs.elki.database.Database) Model(de.lmu.ifi.dbs.elki.data.model.Model) TrivialAllNoise(de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.TrivialAllNoise) TrivialAllInOne(de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.TrivialAllInOne) ByLabelClustering(de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering) Test(org.junit.Test) AbstractSimpleAlgorithmTest(de.lmu.ifi.dbs.elki.algorithm.AbstractSimpleAlgorithmTest)

Example 3 with ByLabelClustering

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);
    }
}
Also used : Database(de.lmu.ifi.dbs.elki.database.Database) StaticArrayDatabase(de.lmu.ifi.dbs.elki.database.StaticArrayDatabase) Model(de.lmu.ifi.dbs.elki.data.model.Model) ByLabelClustering(de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering) ClusterContingencyTable(de.lmu.ifi.dbs.elki.evaluation.clustering.ClusterContingencyTable) ListParameterization(de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization) Test(org.junit.Test) AbstractClusterAlgorithmTest(de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)

Aggregations

ByLabelClustering (de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering)3 Model (de.lmu.ifi.dbs.elki.data.model.Model)3 Database (de.lmu.ifi.dbs.elki.database.Database)2 ClusterContingencyTable (de.lmu.ifi.dbs.elki.evaluation.clustering.ClusterContingencyTable)2 Test (org.junit.Test)2 AbstractSimpleAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.AbstractSimpleAlgorithmTest)1 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)1 TrivialAllInOne (de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.TrivialAllInOne)1 TrivialAllNoise (de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.TrivialAllNoise)1 StaticArrayDatabase (de.lmu.ifi.dbs.elki.database.StaticArrayDatabase)1 ListParameterization (de.lmu.ifi.dbs.elki.utilities.optionhandling.parameterization.ListParameterization)1