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