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