Search in sources :

Example 26 with Model

use of de.lmu.ifi.dbs.elki.data.model.Model in project elki by elki-project.

the class OutlierThresholdClustering method split.

private Clustering<Model> split(OutlierResult or) {
    DoubleRelation scores = or.getScores();
    if (scaling instanceof OutlierScalingFunction) {
        ((OutlierScalingFunction) scaling).prepare(or);
    }
    ArrayList<ModifiableDBIDs> idlists = new ArrayList<>(threshold.length + 1);
    for (int i = 0; i <= threshold.length; i++) {
        idlists.add(DBIDUtil.newHashSet());
    }
    for (DBIDIter iter = scores.getDBIDs().iter(); iter.valid(); iter.advance()) {
        double score = scores.doubleValue(iter);
        if (scaling != null) {
            score = scaling.getScaled(score);
        }
        int i = 0;
        for (; i < threshold.length; i++) {
            if (score < threshold[i]) {
                break;
            }
        }
        idlists.get(i).add(iter);
    }
    Clustering<Model> c = new Clustering<>("Outlier threshold clustering", "threshold-clustering");
    for (int i = 0; i <= threshold.length; i++) {
        String name = (i == 0) ? "Inlier" : "Outlier_" + threshold[i - 1];
        c.addToplevelCluster(new Cluster<>(name, idlists.get(i), (i > 0)));
    }
    return c;
}
Also used : OutlierScalingFunction(de.lmu.ifi.dbs.elki.utilities.scaling.outlier.OutlierScalingFunction) ArrayList(java.util.ArrayList) Clustering(de.lmu.ifi.dbs.elki.data.Clustering) DoubleRelation(de.lmu.ifi.dbs.elki.database.relation.DoubleRelation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) Model(de.lmu.ifi.dbs.elki.data.model.Model) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)

Example 27 with Model

use of de.lmu.ifi.dbs.elki.data.model.Model in project elki by elki-project.

the class KMLOutputHandler method buildHullsRecursively.

/**
 * Recursively step through the clusters to build the hulls.
 *
 * @param clu Current cluster
 * @param hier Clustering hierarchy
 * @param hulls Hull map
 */
private DoubleObjPair<Polygon> buildHullsRecursively(Cluster<Model> clu, Hierarchy<Cluster<Model>> hier, Map<Object, DoubleObjPair<Polygon>> hulls, Relation<? extends NumberVector> coords) {
    final DBIDs ids = clu.getIDs();
    GrahamScanConvexHull2D hull = new GrahamScanConvexHull2D();
    for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
        hull.add(coords.get(iter).toArray());
    }
    double weight = ids.size();
    if (hier != null && hulls != null) {
        final int numc = hier.numChildren(clu);
        if (numc > 0) {
            for (It<Cluster<Model>> iter = hier.iterChildren(clu); iter.valid(); iter.advance()) {
                final Cluster<Model> iclu = iter.get();
                DoubleObjPair<Polygon> poly = hulls.get(iclu);
                if (poly == null) {
                    poly = buildHullsRecursively(iclu, hier, hulls, coords);
                }
                // Add inner convex hull to outer convex hull.
                for (ArrayListIter<double[]> vi = poly.second.iter(); vi.valid(); vi.advance()) {
                    hull.add(vi.get());
                }
                weight += poly.first / numc;
            }
        }
    }
    DoubleObjPair<Polygon> pair = new DoubleObjPair<>(weight, hull.getHull());
    hulls.put(clu, pair);
    return pair;
}
Also used : ArrayModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs) DBIDs(de.lmu.ifi.dbs.elki.database.ids.DBIDs) Cluster(de.lmu.ifi.dbs.elki.data.Cluster) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) DoubleObjPair(de.lmu.ifi.dbs.elki.utilities.pairs.DoubleObjPair) GrahamScanConvexHull2D(de.lmu.ifi.dbs.elki.math.geometry.GrahamScanConvexHull2D) Model(de.lmu.ifi.dbs.elki.data.model.Model) Polygon(de.lmu.ifi.dbs.elki.data.spatial.Polygon)

Example 28 with Model

use of de.lmu.ifi.dbs.elki.data.model.Model in project elki by elki-project.

the class CASHTest method testCASHEmbedded.

/**
 * Run CASH with fixed parameters and compare the result to a golden standard.
 */
@Test
public void testCASHEmbedded() {
    Database db = makeSimpleDatabase(UNITTEST + "correlation-embedded-2-4d.ascii", 600);
    Clustering<Model> result = // 
    new ELKIBuilder<CASH<DoubleVector>>(CASH.class).with(CASH.Parameterizer.JITTER_ID, // 
    0.7).with(CASH.Parameterizer.MINPTS_ID, // 
    160).with(CASH.Parameterizer.MAXLEVEL_ID, // 
    40).build().run(db);
    testFMeasure(db, result, 0.443246);
    testClusterSizes(result, new int[] { 169, 196, 235 });
}
Also used : Database(de.lmu.ifi.dbs.elki.database.Database) Model(de.lmu.ifi.dbs.elki.data.model.Model) AbstractClusterAlgorithmTest(de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest) Test(org.junit.Test)

Example 29 with Model

use of de.lmu.ifi.dbs.elki.data.model.Model in project elki by elki-project.

the class CASHTest method testCASHResults.

/**
 * Run CASH with fixed parameters and compare the result to a golden standard.
 */
@Test
public void testCASHResults() {
    Database db = makeSimpleDatabase(UNITTEST + "hierarchical-3d2d1d.csv", 600);
    Clustering<Model> result = // 
    new ELKIBuilder<CASH<DoubleVector>>(CASH.class).with(CASH.Parameterizer.JITTER_ID, // 
    0.7).with(CASH.Parameterizer.MINPTS_ID, // 
    50).with(CASH.Parameterizer.MAXLEVEL_ID, // 
    25).with(// 
    CASH.Parameterizer.ADJUST_ID).build().run(db);
    // with hierarchical pairs: 0.64102
    testFMeasure(db, result, 0.50074);
    testClusterSizes(result, new int[] { 18, 80, 252, 468 });
}
Also used : ELKIBuilder(de.lmu.ifi.dbs.elki.utilities.ELKIBuilder) Database(de.lmu.ifi.dbs.elki.database.Database) Model(de.lmu.ifi.dbs.elki.data.model.Model) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) AbstractClusterAlgorithmTest(de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest) Test(org.junit.Test)

Example 30 with Model

use of de.lmu.ifi.dbs.elki.data.model.Model in project elki by elki-project.

the class SUBCLU method bestSubspace.

/**
 * Determines the {@code d}-dimensional subspace of the {@code (d+1)}
 * -dimensional candidate with minimal number of objects in the cluster.
 *
 * @param subspaces the list of {@code d}-dimensional subspaces containing
 *        clusters
 * @param candidate the {@code (d+1)}-dimensional candidate subspace
 * @param clusterMap the mapping of subspaces to clusters
 * @return the {@code d}-dimensional subspace of the {@code (d+1)}
 *         -dimensional candidate with minimal number of objects in the
 *         cluster
 */
private Subspace bestSubspace(List<Subspace> subspaces, Subspace candidate, TreeMap<Subspace, List<Cluster<Model>>> clusterMap) {
    Subspace bestSubspace = null;
    for (Subspace subspace : subspaces) {
        int min = Integer.MAX_VALUE;
        if (subspace.isSubspace(candidate)) {
            List<Cluster<Model>> clusters = clusterMap.get(subspace);
            for (Cluster<Model> cluster : clusters) {
                int clusterSize = cluster.size();
                if (clusterSize < min) {
                    min = clusterSize;
                    bestSubspace = subspace;
                }
            }
        }
    }
    return bestSubspace;
}
Also used : Subspace(de.lmu.ifi.dbs.elki.data.Subspace) SubspaceModel(de.lmu.ifi.dbs.elki.data.model.SubspaceModel) Model(de.lmu.ifi.dbs.elki.data.model.Model) Cluster(de.lmu.ifi.dbs.elki.data.Cluster)

Aggregations

Model (de.lmu.ifi.dbs.elki.data.model.Model)60 Database (de.lmu.ifi.dbs.elki.database.Database)29 Test (org.junit.Test)24 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)21 Cluster (de.lmu.ifi.dbs.elki.data.Cluster)18 AbstractClusterAlgorithmTest (de.lmu.ifi.dbs.elki.algorithm.clustering.AbstractClusterAlgorithmTest)17 ClusterModel (de.lmu.ifi.dbs.elki.data.model.ClusterModel)13 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)12 ELKIBuilder (de.lmu.ifi.dbs.elki.utilities.ELKIBuilder)11 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)10 ArrayList (java.util.ArrayList)9 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)8 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)8 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)8 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)7 HashMap (java.util.HashMap)5 ByLabelClustering (de.lmu.ifi.dbs.elki.algorithm.clustering.trivial.ByLabelClustering)3 SubspaceModel (de.lmu.ifi.dbs.elki.data.model.SubspaceModel)3 IndefiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.IndefiniteProgress)3 CorePredicate (de.lmu.ifi.dbs.elki.algorithm.clustering.gdbscan.CorePredicate)2