Search in sources :

Example 21 with WritableIntegerDataStore

use of de.lmu.ifi.dbs.elki.database.datastore.WritableIntegerDataStore in project elki by elki-project.

the class ClusteringVectorDumper method dumpClusteringOutput.

/**
 * Dump a single clustering result.
 *
 * @param writer Output writer
 * @param hierarchy Cluster hierarchy to process
 * @param c Clustering result
 */
protected void dumpClusteringOutput(PrintStream writer, ResultHierarchy hierarchy, Clustering<?> c) {
    DBIDRange ids = null;
    for (It<Relation<?>> iter = hierarchy.iterParents(c).filter(Relation.class); iter.valid(); iter.advance()) {
        DBIDs pids = iter.get().getDBIDs();
        if (pids instanceof DBIDRange) {
            ids = (DBIDRange) pids;
            break;
        }
        LOG.warning("Parent result " + iter.get().getLongName() + " has DBID type " + pids.getClass());
    }
    // Fallback: try to locate a database.
    if (ids == null) {
        for (It<Database> iter = hierarchy.iterAll().filter(Database.class); iter.valid(); iter.advance()) {
            DBIDs pids = iter.get().getRelation(TypeUtil.ANY).getDBIDs();
            if (pids instanceof DBIDRange) {
                ids = (DBIDRange) pids;
                break;
            }
            LOG.warning("Parent result " + iter.get().getLongName() + " has DBID type " + pids.getClass());
        }
    }
    if (ids == null) {
        LOG.warning("Cannot dump cluster assignment, as I do not have a well-defined DBIDRange to use for a unique column assignment. DBIDs must be a continuous range.");
        return;
    }
    WritableIntegerDataStore map = DataStoreUtil.makeIntegerStorage(ids, DataStoreFactory.HINT_TEMP);
    int cnum = 0;
    for (Cluster<?> clu : c.getAllClusters()) {
        for (DBIDIter iter = clu.getIDs().iter(); iter.valid(); iter.advance()) {
            map.putInt(iter, cnum);
        }
        ++cnum;
    }
    for (DBIDArrayIter iter = ids.iter(); iter.valid(); iter.advance()) {
        if (iter.getOffset() > 0) {
            writer.append(' ');
        }
        writer.append(Integer.toString(map.intValue(iter)));
    }
    if (forceLabel != null) {
        if (forceLabel.length() > 0) {
            writer.append(' ').append(forceLabel);
        }
    } else {
        writer.append(' ').append(c.getLongName());
    }
    writer.append('\n');
}
Also used : Relation(de.lmu.ifi.dbs.elki.database.relation.Relation) WritableIntegerDataStore(de.lmu.ifi.dbs.elki.database.datastore.WritableIntegerDataStore) DBIDs(de.lmu.ifi.dbs.elki.database.ids.DBIDs) DBIDRange(de.lmu.ifi.dbs.elki.database.ids.DBIDRange) Database(de.lmu.ifi.dbs.elki.database.Database) DBIDArrayIter(de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Aggregations

WritableIntegerDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableIntegerDataStore)21 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)16 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)16 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)14 IndefiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.IndefiniteProgress)14 ArrayList (java.util.ArrayList)14 KMeansModel (de.lmu.ifi.dbs.elki.data.model.KMeansModel)12 StringStatistic (de.lmu.ifi.dbs.elki.logging.statistics.StringStatistic)12 LongStatistic (de.lmu.ifi.dbs.elki.logging.statistics.LongStatistic)11 DoubleStatistic (de.lmu.ifi.dbs.elki.logging.statistics.DoubleStatistic)10 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)8 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)7 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)5 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)4 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)4 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)4 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)4 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)3 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)2 MedoidModel (de.lmu.ifi.dbs.elki.data.model.MedoidModel)2