Search in sources :

Example 11 with MaterializedRelation

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);
}
Also used : DBIDs(de.lmu.ifi.dbs.elki.database.ids.DBIDs) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs) ParameterizationFunction(de.lmu.ifi.dbs.elki.algorithm.clustering.correlation.cash.ParameterizationFunction) SimpleTypeInformation(de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) MaterializedRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation)

Example 12 with MaterializedRelation

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;
}
Also used : VectorFieldTypeInformation(de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation) ProxyDatabase(de.lmu.ifi.dbs.elki.database.ProxyDatabase) MaterializedRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 13 with MaterializedRelation

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;
}
Also used : VectorFieldTypeInformation(de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation) DBIDs(de.lmu.ifi.dbs.elki.database.ids.DBIDs) ModifiableDBIDs(de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs) ProxyDatabase(de.lmu.ifi.dbs.elki.database.ProxyDatabase) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) MaterializedRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation)

Example 14 with MaterializedRelation

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);
}
Also used : VectorFieldTypeInformation(de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation) DBIDs(de.lmu.ifi.dbs.elki.database.ids.DBIDs) DBIDArrayIter(de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter) DoubleVector(de.lmu.ifi.dbs.elki.data.DoubleVector) MaterializedRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation)

Example 15 with MaterializedRelation

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;
}
Also used : ModifiableRelation(de.lmu.ifi.dbs.elki.database.relation.ModifiableRelation) Relation(de.lmu.ifi.dbs.elki.database.relation.Relation) MaterializedRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation) IndexFactory(de.lmu.ifi.dbs.elki.index.IndexFactory) SimpleTypeInformation(de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation) Index(de.lmu.ifi.dbs.elki.index.Index) MaterializedRelation(de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation)

Aggregations

MaterializedRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation)15 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)10 VectorFieldTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation)7 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)7 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)6 ProxyDatabase (de.lmu.ifi.dbs.elki.database.ProxyDatabase)6 SimpleTypeInformation (de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation)4 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)4 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)3 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)3 ParameterizationFunction (de.lmu.ifi.dbs.elki.algorithm.clustering.correlation.cash.ParameterizationFunction)2 Index (de.lmu.ifi.dbs.elki.index.Index)2 IndexFactory (de.lmu.ifi.dbs.elki.index.IndexFactory)2 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)2 Clustering (de.lmu.ifi.dbs.elki.data.Clustering)1 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)1 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)1 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)1 ArrayStaticDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayStaticDBIDs)1 DBIDRange (de.lmu.ifi.dbs.elki.database.ids.DBIDRange)1