Search in sources :

Example 1 with GeneratorInterface

use of de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorInterface in project elki by elki-project.

the class ByModelClustering method run.

/**
 * Run the actual clustering algorithm.
 *
 * @param relation The data input we use
 */
public Clustering<Model> run(Relation<Model> relation) {
    // Build model mapping
    HashMap<Model, ModifiableDBIDs> modelMap = new HashMap<>();
    for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
        Model model = relation.get(iditer);
        ModifiableDBIDs modelids = modelMap.get(model);
        if (modelids == null) {
            modelids = DBIDUtil.newHashSet();
            modelMap.put(model, modelids);
        }
        modelids.add(iditer);
    }
    Clustering<Model> result = new Clustering<>("By Model Clustering", "bymodel-clustering");
    for (Entry<Model, ModifiableDBIDs> entry : modelMap.entrySet()) {
        final Model model = entry.getKey();
        final ModifiableDBIDs ids = entry.getValue();
        final String name = (model instanceof GeneratorInterface) ? ((GeneratorInterface) model).getName() : model.toString();
        Cluster<Model> c = new Cluster<>(name, ids, model);
        if (noisepattern != null && noisepattern.matcher(name).find()) {
            c.setNoise(true);
        }
        result.addToplevelCluster(c);
    }
    return result;
}
Also used : GeneratorInterface(de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorInterface) HashMap(java.util.HashMap) Model(de.lmu.ifi.dbs.elki.data.model.Model) Cluster(de.lmu.ifi.dbs.elki.data.Cluster) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs) Clustering(de.lmu.ifi.dbs.elki.data.Clustering) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

Cluster (de.lmu.ifi.dbs.elki.data.Cluster)1 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)1 Model (de.lmu.ifi.dbs.elki.data.model.Model)1 GeneratorInterface (de.lmu.ifi.dbs.elki.data.synthetic.bymodel.GeneratorInterface)1 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)1 HashMap (java.util.HashMap)1