use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class CenterOfMassMetaClustering method runClusteringAlgorithm.
/**
* Run a clustering algorithm on a single instance.
*
* @param parent Parent result to attach to
* @param ids Object IDs to process
* @param store Input data
* @param dim Dimensionality
* @param title Title of relation
* @return Clustering result
*/
protected C runClusteringAlgorithm(ResultHierarchy hierarchy, Result parent, DBIDs ids, DataStore<DoubleVector> store, int dim, String title) {
SimpleTypeInformation<DoubleVector> t = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim);
Relation<DoubleVector> sample = new MaterializedRelation<>(t, ids, title, store);
ProxyDatabase d = new ProxyDatabase(ids, sample);
C clusterResult = inner.run(d);
d.getHierarchy().remove(sample);
d.getHierarchy().remove(clusterResult);
hierarchy.add(parent, sample);
hierarchy.add(sample, clusterResult);
return clusterResult;
}
use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class TSNE method run.
public Relation<DoubleVector> run(Relation<O> relation) {
AffinityMatrix pij = affinity.computeAffinityMatrix(relation, EARLY_EXAGGERATION);
// Create initial solution.
final int size = pij.size();
double[][] sol = randomInitialSolution(size, dim, random.getSingleThreadedRandom());
projectedDistances.setLong(0L);
optimizetSNE(pij, sol);
LOG.statistics(projectedDistances);
// Remove the original (unprojected) data unless configured otherwise.
removePreviousRelation(relation);
// Transform into output data format.
DBIDs ids = relation.getDBIDs();
WritableDataStore<DoubleVector> proj = DataStoreFactory.FACTORY.makeStorage(ids, DataStoreFactory.HINT_DB | DataStoreFactory.HINT_SORTED, DoubleVector.class);
VectorFieldTypeInformation<DoubleVector> otype = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim);
for (DBIDArrayIter it = pij.iterDBIDs(); it.valid(); it.advance()) {
proj.put(it, DoubleVector.wrap(sol[it.getOffset()]));
}
return new MaterializedRelation<>("tSNE", "t-SNE", otype, proj, ids);
}
use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class KNNJoin method run.
/**
* Joins in the given spatial database to each object its k-nearest neighbors.
*
* @param relation Relation to process
* @return result
*/
public Relation<KNNList> run(Relation<V> relation) {
DBIDs ids = relation.getDBIDs();
WritableDataStore<KNNList> knnLists = run(relation, ids);
// Wrap as relation:
return new MaterializedRelation<>("k nearest neighbors", "kNNs", TypeUtil.KNNLIST, knnLists, ids);
}
use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class CASH method buildDB.
/**
* Builds a dim-1 dimensional database where the objects are projected into
* the specified subspace.
*
* @param dim the dimensionality of the database
* @param basis the basis defining the subspace
* @param ids the ids for the new database
* @param relation the database storing the parameterization functions
* @return a dim-1 dimensional database where the objects are projected into
* the specified subspace
*/
private MaterializedRelation<ParameterizationFunction> buildDB(int dim, double[][] basis, DBIDs ids, Relation<ParameterizationFunction> relation) {
ProxyDatabase proxy = new ProxyDatabase(ids);
SimpleTypeInformation<ParameterizationFunction> type = new SimpleTypeInformation<>(ParameterizationFunction.class);
WritableDataStore<ParameterizationFunction> prep = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT, ParameterizationFunction.class);
// Project
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
prep.put(iter, project(basis, relation.get(iter)));
}
if (LOG.isDebugging()) {
LOG.debugFine("db fuer dim " + (dim - 1) + ": " + ids.size());
}
MaterializedRelation<ParameterizationFunction> prel = new MaterializedRelation<>(type, ids, null, prep);
proxy.addRelation(prel);
return prel;
}
use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class BarnesHutTSNE method run.
public Relation<DoubleVector> run(Database database, Relation<O> relation) {
AffinityMatrix neighbors = affinity.computeAffinityMatrix(relation, EARLY_EXAGGERATION);
double[][] solution = randomInitialSolution(neighbors.size(), dim, random.getSingleThreadedRandom());
projectedDistances.setLong(0L);
optimizetSNE(neighbors, solution);
LOG.statistics(projectedDistances);
// Remove the original (unprojected) data unless configured otherwise.
removePreviousRelation(relation);
DBIDs ids = relation.getDBIDs();
WritableDataStore<DoubleVector> proj = DataStoreFactory.FACTORY.makeStorage(ids, DataStoreFactory.HINT_DB | DataStoreFactory.HINT_SORTED, DoubleVector.class);
VectorFieldTypeInformation<DoubleVector> otype = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim);
for (DBIDArrayIter it = neighbors.iterDBIDs(); it.valid(); it.advance()) {
proj.put(it, DoubleVector.wrap(solution[it.getOffset()]));
}
return new MaterializedRelation<>("tSNE", "t-SNE", otype, proj, ids);
}
Aggregations