use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class CASH method preprocess.
/**
* Preprocess the dataset, precomputing the parameterization functions.
*
* @param db Database
* @param vrel Vector relation
* @return Preprocessed relation
*/
private Relation<ParameterizationFunction> preprocess(Database db, Relation<V> vrel) {
DBIDs ids = vrel.getDBIDs();
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, new ParameterizationFunction(vrel.get(iter)));
}
return new MaterializedRelation<>(type, ids, null, prep);
}
use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class CASH method buildDerivatorDB.
/**
* Builds a database for the derivator consisting of the ids in the specified
* interval.
*
* @param relation the database storing the parameterization functions
* @param ids the ids to build the database from
* @return a database for the derivator consisting of the ids in the specified
* interval
*/
private Database buildDerivatorDB(Relation<ParameterizationFunction> relation, DBIDs ids) {
ProxyDatabase proxy = new ProxyDatabase(ids);
int dim = dimensionality(relation);
SimpleTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim);
MaterializedRelation<DoubleVector> prep = new MaterializedRelation<>(type, ids);
proxy.addRelation(prep);
// Project
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
prep.insert(iter, DoubleVector.wrap(relation.get(iter).getColumnVector()));
}
return proxy;
}
use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class CASH method buildDerivatorDB.
/**
* Builds a database for the derivator consisting of the ids in the specified
* interval.
*
* @param relation the database storing the parameterization functions
* @param interval the interval to build the database from
* @return a database for the derivator consisting of the ids in the specified
* interval
*/
private Database buildDerivatorDB(Relation<ParameterizationFunction> relation, CASHInterval interval) {
DBIDs ids = interval.getIDs();
ProxyDatabase proxy = new ProxyDatabase(ids);
int dim = dimensionality(relation);
SimpleTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim);
WritableDataStore<DoubleVector> prep = DataStoreUtil.makeStorage(ids, DataStoreFactory.HINT_HOT, DoubleVector.class);
// Project
for (DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
prep.put(iter, DoubleVector.wrap(relation.get(iter).getColumnVector()));
}
if (LOG.isDebugging()) {
LOG.debugFine("db fuer derivator : " + ids.size());
}
MaterializedRelation<DoubleVector> prel = new MaterializedRelation<>(type, ids, null, prep);
proxy.addRelation(prel);
return proxy;
}
use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class SNE method run.
public Relation<DoubleVector> run(Relation<O> relation) {
AffinityMatrix pij = affinity.computeAffinityMatrix(relation, 1.);
// Create initial solution.
final int size = pij.size();
double[][] sol = randomInitialSolution(size, dim, random.getSingleThreadedRandom());
projectedDistances.setLong(0L);
optimizeSNE(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<>("SNE", "SNE", otype, proj, ids);
}
use of de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation in project elki by elki-project.
the class HashmapDatabase method addNewRelation.
/**
* Add a new representation for the given meta.
*
* @param meta meta data
* @return new representation
*/
private Relation<?> addNewRelation(SimpleTypeInformation<?> meta) {
@SuppressWarnings("unchecked") SimpleTypeInformation<Object> ometa = (SimpleTypeInformation<Object>) meta;
Relation<?> relation = new MaterializedRelation<>(ometa, ids);
relations.add(relation);
getHierarchy().add(this, relation);
// Try to add indexes where appropriate
for (IndexFactory<?, ?> factory : indexFactories) {
if (factory.getInputTypeRestriction().isAssignableFromType(meta)) {
@SuppressWarnings("unchecked") final IndexFactory<Object, ?> ofact = (IndexFactory<Object, ?>) factory;
@SuppressWarnings("unchecked") final Relation<Object> orep = (Relation<Object>) relation;
Index index = ofact.instantiate(orep);
index.initialize();
getHierarchy().add(relation, index);
}
}
return relation;
}
Aggregations