Search in sources :

Example 1 with CLIQUESubspace

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;
}
Also used : ArrayList(java.util.ArrayList) SubspaceModel(de.lmu.ifi.dbs.elki.data.model.SubspaceModel) Cluster(de.lmu.ifi.dbs.elki.data.Cluster) StepProgress(de.lmu.ifi.dbs.elki.logging.progress.StepProgress) Clustering(de.lmu.ifi.dbs.elki.data.Clustering) CLIQUESubspace(de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUESubspace) CLIQUESubspace(de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUESubspace) Subspace(de.lmu.ifi.dbs.elki.data.Subspace) ArrayList(java.util.ArrayList) List(java.util.List) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs) Pair(de.lmu.ifi.dbs.elki.utilities.pairs.Pair)

Example 2 with CLIQUESubspace

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CLIQUESubspace(de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUESubspace) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) CLIQUEUnit(de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUEUnit)

Aggregations

CLIQUESubspace (de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUESubspace)2 ArrayList (java.util.ArrayList)2 CLIQUEUnit (de.lmu.ifi.dbs.elki.algorithm.clustering.subspace.clique.CLIQUEUnit)1 Cluster (de.lmu.ifi.dbs.elki.data.Cluster)1 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)1 Subspace (de.lmu.ifi.dbs.elki.data.Subspace)1 SubspaceModel (de.lmu.ifi.dbs.elki.data.model.SubspaceModel)1 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)1 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)1 StepProgress (de.lmu.ifi.dbs.elki.logging.progress.StepProgress)1 Pair (de.lmu.ifi.dbs.elki.utilities.pairs.Pair)1 HashMap (java.util.HashMap)1 List (java.util.List)1