use of de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUESubspace in project elki by elki-project.
the class CLIQUE method run.
/**
* Performs the CLIQUE algorithm on the given database.
*
* @param relation Data relation to process
* @return Clustering result
*/
public Clustering<SubspaceModel> run(Relation<V> relation) {
final int dimensionality = RelationUtil.dimensionality(relation);
StepProgress step = new StepProgress(2);
// 1. Identification of subspaces that contain clusters
step.beginStep(1, "Identification of subspaces that contain clusters", LOG);
ArrayList<List<CLIQUESubspace<V>>> dimensionToDenseSubspaces = new ArrayList<>(dimensionality);
List<CLIQUESubspace<V>> denseSubspaces = findOneDimensionalDenseSubspaces(relation);
dimensionToDenseSubspaces.add(denseSubspaces);
if (LOG.isVerbose()) {
LOG.verbose("1-dimensional dense subspaces: " + denseSubspaces.size());
}
if (LOG.isDebugging()) {
for (CLIQUESubspace<V> s : denseSubspaces) {
LOG.debug(s.toString(" "));
}
}
for (int k = 2; k <= dimensionality && !denseSubspaces.isEmpty(); k++) {
denseSubspaces = findDenseSubspaces(relation, denseSubspaces);
assert (dimensionToDenseSubspaces.size() == k - 1);
dimensionToDenseSubspaces.add(denseSubspaces);
if (LOG.isVerbose()) {
LOG.verbose(k + "-dimensional dense subspaces: " + denseSubspaces.size());
}
if (LOG.isDebugging()) {
for (CLIQUESubspace<V> s : denseSubspaces) {
LOG.debug(s.toString(" "));
}
}
}
// 2. Identification of clusters
step.beginStep(2, "Identification of clusters", LOG);
// build result
Clustering<SubspaceModel> result = new Clustering<>("CLIQUE clustering", "clique-clustering");
for (int dim = 0; dim < dimensionToDenseSubspaces.size(); dim++) {
List<CLIQUESubspace<V>> subspaces = dimensionToDenseSubspaces.get(dim);
List<Pair<Subspace, ModifiableDBIDs>> modelsAndClusters = determineClusters(subspaces);
if (LOG.isVerbose()) {
LOG.verbose((dim + 1) + "-dimensional clusters: " + modelsAndClusters.size());
}
for (Pair<Subspace, ModifiableDBIDs> modelAndCluster : modelsAndClusters) {
Cluster<SubspaceModel> newCluster = new Cluster<>(modelAndCluster.second);
newCluster.setModel(new SubspaceModel(modelAndCluster.first, Centroid.make(relation, modelAndCluster.second).getArrayRef()));
result.addToplevelCluster(newCluster);
}
}
return result;
}
use of de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUESubspace in project elki by elki-project.
the class CLIQUE method findOneDimensionalDenseSubspaceCandidates.
/**
* Determines the one-dimensional dense subspace candidates by making a pass
* over the database.
*
* @param database the database to run the algorithm on
* @return the one-dimensional dense subspace candidates reverse ordered by
* their coverage
*/
private List<CLIQUESubspace<V>> findOneDimensionalDenseSubspaceCandidates(Relation<V> database) {
Collection<CLIQUEUnit<V>> units = initOneDimensionalUnits(database);
// identify dense units
double total = database.size();
for (DBIDIter it = database.iterDBIDs(); it.valid(); it.advance()) {
V featureVector = database.get(it);
for (CLIQUEUnit<V> unit : units) {
unit.addFeatureVector(it, featureVector);
}
}
Collection<CLIQUEUnit<V>> denseUnits = new ArrayList<>();
Map<Integer, CLIQUESubspace<V>> denseSubspaces = new HashMap<>();
for (CLIQUEUnit<V> unit : units) {
// unit is a dense unit
if (unit.selectivity(total) >= tau) {
denseUnits.add(unit);
// add the dense unit to its subspace
int dim = unit.getIntervals().iterator().next().getDimension();
CLIQUESubspace<V> subspace_d = denseSubspaces.get(Integer.valueOf(dim));
if (subspace_d == null) {
denseSubspaces.put(Integer.valueOf(dim), subspace_d = new CLIQUESubspace<>(dim));
}
subspace_d.addDenseUnit(unit);
}
}
if (LOG.isDebugging()) {
LOG.debugFine(//
new StringBuilder().append(" number of 1-dim dense units: ").append(denseUnits.size()).append("\n number of 1-dim dense subspace candidates: ").append(denseSubspaces.size()).toString());
}
List<CLIQUESubspace<V>> subspaceCandidates = new ArrayList<>(denseSubspaces.values());
Collections.sort(subspaceCandidates, new CLIQUESubspace.CoverageComparator());
return subspaceCandidates;
}
Aggregations