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;
}
Aggregations