use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class TrivialAllNoise method run.
public Clustering<Model> run(Relation<?> relation) {
final DBIDs ids = relation.getDBIDs();
Clustering<Model> result = new Clustering<>("All-in-noise trivial Clustering", "allinnoise-clustering");
Cluster<Model> c = new Cluster<Model>(ids, true, ClusterModel.CLUSTER);
result.addToplevelCluster(c);
return result;
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class TrivialAllInOne method run.
public Clustering<Model> run(Relation<?> relation) {
final DBIDs ids = relation.getDBIDs();
Clustering<Model> result = new Clustering<>("All-in-one trivial Clustering", "allinone-clustering");
Cluster<Model> c = new Cluster<Model>(ids, ClusterModel.CLUSTER);
result.addToplevelCluster(c);
return result;
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class WithinClusterMeanDistanceQualityMeasure method quality.
@Override
public <V extends NumberVector> double quality(Clustering<? extends MeanModel> clustering, NumberVectorDistanceFunction<? super V> distanceFunction, Relation<V> relation) {
double clusterDistanceSum = 0;
for (Cluster<? extends MeanModel> cluster : clustering.getAllClusters()) {
DBIDs ids = cluster.getIDs();
// Compute sum of pairwise distances:
double clusterPairwiseDistanceSum = 0;
for (DBIDIter iter1 = ids.iter(); iter1.valid(); iter1.advance()) {
NumberVector obj1 = relation.get(iter1);
for (DBIDIter iter2 = ids.iter(); iter2.valid(); iter2.advance()) {
clusterPairwiseDistanceSum += distanceFunction.distance(obj1, relation.get(iter2));
}
}
clusterDistanceSum += clusterPairwiseDistanceSum / (ids.size() * ids.size());
}
return clusterDistanceSum / clustering.getAllClusters().size();
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class StaticArrayDatabase method initialize.
/**
* Initialize the database by getting the initial data from the database
* connection.
*/
@Override
public void initialize() {
if (databaseConnection != null) {
if (LOG.isDebugging()) {
LOG.debugFine("Loading data from database connection.");
}
MultipleObjectsBundle bundle = databaseConnection.loadData();
// Run at most once.
databaseConnection = null;
// Find DBIDs for bundle
{
DBIDs bids = bundle.getDBIDs();
if (bids instanceof ArrayStaticDBIDs) {
this.ids = (ArrayStaticDBIDs) bids;
} else if (bids == null) {
this.ids = DBIDUtil.generateStaticDBIDRange(bundle.dataLength());
} else {
this.ids = (ArrayStaticDBIDs) DBIDUtil.makeUnmodifiable(bids);
}
}
// Replace id representation (it would be nicer if we would not need
// DBIDView at all)
this.idrep = new DBIDView(this.ids);
relations.add(this.idrep);
getHierarchy().add(this, idrep);
DBIDArrayIter it = this.ids.iter();
int numrel = bundle.metaLength();
for (int i = 0; i < numrel; i++) {
SimpleTypeInformation<?> meta = bundle.meta(i);
@SuppressWarnings("unchecked") SimpleTypeInformation<Object> ometa = (SimpleTypeInformation<Object>) meta;
WritableDataStore<Object> store = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_DB, ometa.getRestrictionClass());
for (it.seek(0); it.valid(); it.advance()) {
store.put(it, bundle.data(it.getOffset(), i));
}
Relation<?> relation = new MaterializedRelation<>(ometa, ids, null, store);
relations.add(relation);
getHierarchy().add(this, relation);
// Try to add indexes where appropriate
for (IndexFactory<?, ?> factory : indexFactories) {
if (factory.getInputTypeRestriction().isAssignableFromType(ometa)) {
@SuppressWarnings("unchecked") final IndexFactory<Object, ?> ofact = (IndexFactory<Object, ?>) factory;
@SuppressWarnings("unchecked") final Relation<Object> orep = (Relation<Object>) relation;
final Index index = ofact.instantiate(orep);
Duration duration = LOG.isStatistics() ? LOG.newDuration(index.getClass().getName() + ".construction").begin() : null;
index.initialize();
if (duration != null) {
LOG.statistics(duration.end());
}
getHierarchy().add(relation, index);
}
}
}
// fire insertion event
eventManager.fireObjectsInserted(ids);
}
}
use of de.lmu.ifi.dbs.elki.database.ids.DBIDs in project elki by elki-project.
the class LinearWeightedExtendedNeighborhood method getWeightedNeighbors.
@Override
public Collection<DoubleDBIDPair> getWeightedNeighbors(DBIDRef reference) {
ModifiableDBIDs seen = DBIDUtil.newHashSet();
List<DoubleDBIDPair> result = new ArrayList<>();
// Add starting object
result.add(DBIDUtil.newPair(computeWeight(0), reference));
seen.add(reference);
// Extend.
DBIDs cur = DBIDUtil.deref(reference);
for (int i = 1; i <= steps; i++) {
final double weight = computeWeight(i);
// Collect newly discovered IDs
ModifiableDBIDs add = DBIDUtil.newHashSet();
for (DBIDIter iter = cur.iter(); iter.valid(); iter.advance()) {
for (DBIDIter iter2 = inner.getNeighborDBIDs(iter).iter(); iter2.valid(); iter2.advance()) {
// Seen before?
if (seen.contains(iter2)) {
continue;
}
add.add(iter2);
result.add(DBIDUtil.newPair(weight, iter2));
}
}
if (add.size() == 0) {
break;
}
cur = add;
}
return result;
}
Aggregations