this.lambda = lambda;
}
public Clustering<Model> run(Database database, Relation<V> relation) throws IllegalStateException {
FiniteProgress objprog = getLogger().isVerbose() ? new FiniteProgress("Processing objects", relation.size(), getLogger()) : null;
IndefiniteProgress clusprog = getLogger().isVerbose() ? new IndefiniteProgress("Number of clusters", getLogger()) : null;
resultList = new ArrayList<ModifiableDBIDs>();
noise = DBIDUtil.newHashSet();
processedIDs = DBIDUtil.newHashSet(relation.size());
LocallyWeightedDistanceFunction.Instance<V> distFunc = distanceFunction.instantiate(relation);
RangeQuery<V, DoubleDistance> rangeQuery = database.getRangeQuery(distFunc);
if(relation.size() >= minpts) {
for(DBID id : relation.iterDBIDs()) {
if(!processedIDs.contains(id)) {
expandCluster(distFunc, rangeQuery, id, objprog, clusprog);
if(processedIDs.size() == relation.size() && noise.size() == 0) {
break;
}
}
if(objprog != null && clusprog != null) {
objprog.setProcessed(processedIDs.size(), getLogger());
clusprog.setProcessed(resultList.size(), getLogger());
}
}
}
else {
for(DBID id : relation.iterDBIDs()) {
noise.add(id);
if(objprog != null && clusprog != null) {
objprog.setProcessed(processedIDs.size(), getLogger());
clusprog.setProcessed(resultList.size(), getLogger());
}
}
}
if(objprog != null && clusprog != null) {
objprog.setProcessed(processedIDs.size(), getLogger());
clusprog.setProcessed(resultList.size(), getLogger());
}
Clustering<Model> result = new Clustering<Model>(getLongResultName(), getShortResultName());
for(Iterator<ModifiableDBIDs> resultListIter = resultList.iterator(); resultListIter.hasNext();) {
Cluster<Model> c = new Cluster<Model>(resultListIter.next(), ClusterModel.CLUSTER);
result.addCluster(c);
}
Cluster<Model> n = new Cluster<Model>(noise, true, ClusterModel.CLUSTER);
result.addCluster(n);
if(objprog != null && clusprog != null) {
objprog.setProcessed(processedIDs.size(), getLogger());
clusprog.setProcessed(resultList.size(), getLogger());
}
// Signal that the progress has completed.
if(objprog != null && clusprog != null) {
objprog.ensureCompleted(getLogger());
clusprog.setCompleted(getLogger());
}
return result;
}