Search in sources :

Example 1 with DBSCAN

use of de.lmu.ifi.dbs.elki.algorithm.clustering.DBSCAN in project elki by elki-project.

the class SUBCLU method runDBSCAN.

/**
 * Runs the DBSCAN algorithm on the specified partition of the database in the
 * given subspace. If parameter {@code ids} is null DBSCAN will be applied to
 * the whole database.
 *
 * @param relation the database holding the objects to run DBSCAN on
 * @param ids the IDs of the database defining the partition to run DBSCAN on
 *        - if this parameter is null DBSCAN will be applied to the whole
 *        database
 * @param subspace the subspace to run DBSCAN on
 * @return the clustering result of the DBSCAN run
 */
private List<Cluster<Model>> runDBSCAN(Relation<V> relation, DBIDs ids, Subspace subspace) {
    // distance function
    distanceFunction.setSelectedDimensions(subspace.getDimensions());
    ProxyDatabase proxy;
    if (ids == null) {
        // TODO: in this case, we might want to use an index - the proxy below
        // will prevent this!
        ids = relation.getDBIDs();
    }
    proxy = new ProxyDatabase(ids, relation);
    DBSCAN<V> dbscan = new DBSCAN<>(distanceFunction, epsilon, minpts);
    // run DBSCAN
    if (LOG.isVerbose()) {
        LOG.verbose("\nRun DBSCAN on subspace " + subspace.dimensonsToString());
    }
    Clustering<Model> dbsres = dbscan.run(proxy);
    // separate cluster and noise
    List<Cluster<Model>> clusterAndNoise = dbsres.getAllClusters();
    List<Cluster<Model>> clusters = new ArrayList<>();
    for (Cluster<Model> c : clusterAndNoise) {
        if (!c.isNoise()) {
            clusters.add(c);
        }
    }
    return clusters;
}
Also used : SubspaceModel(de.lmu.ifi.dbs.elki.data.model.SubspaceModel) Model(de.lmu.ifi.dbs.elki.data.model.Model) ArrayList(java.util.ArrayList) ProxyDatabase(de.lmu.ifi.dbs.elki.database.ProxyDatabase) DBSCAN(de.lmu.ifi.dbs.elki.algorithm.clustering.DBSCAN) Cluster(de.lmu.ifi.dbs.elki.data.Cluster)

Aggregations

DBSCAN (de.lmu.ifi.dbs.elki.algorithm.clustering.DBSCAN)1 Cluster (de.lmu.ifi.dbs.elki.data.Cluster)1 Model (de.lmu.ifi.dbs.elki.data.model.Model)1 SubspaceModel (de.lmu.ifi.dbs.elki.data.model.SubspaceModel)1 ProxyDatabase (de.lmu.ifi.dbs.elki.database.ProxyDatabase)1 ArrayList (java.util.ArrayList)1