Search in sources :

Example 11 with VectorFieldTypeInformation

use of de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation in project elki by elki-project.

the class FastMultidimensionalScalingTransform method filter.

@Override
public MultipleObjectsBundle filter(MultipleObjectsBundle objects) {
    final int size = objects.dataLength();
    if (size == 0) {
        return objects;
    }
    MultipleObjectsBundle bundle = new MultipleObjectsBundle();
    for (int r = 0; r < objects.metaLength(); r++) {
        SimpleTypeInformation<? extends Object> type = objects.meta(r);
        @SuppressWarnings("unchecked") final List<Object> column = (List<Object>) objects.getColumn(r);
        // Not supported column (e.g. labels):
        if (!dist.getInputTypeRestriction().isAssignableFromType(type)) {
            bundle.appendColumn(type, column);
            continue;
        }
        // Get the replacement type information
        @SuppressWarnings("unchecked") final List<I> castColumn = (List<I>) column;
        NumberVector.Factory<? extends NumberVector> factory = null;
        {
            if (type instanceof VectorFieldTypeInformation) {
                final VectorFieldTypeInformation<?> ctype = (VectorFieldTypeInformation<?>) type;
                // Note two-step cast, to make stricter compilers happy.
                @SuppressWarnings("unchecked") final VectorFieldTypeInformation<? extends NumberVector> vtype = (VectorFieldTypeInformation<? extends NumberVector>) ctype;
                factory = FilterUtil.guessFactory(vtype);
            } else {
                factory = DoubleVector.FACTORY;
            }
            bundle.appendColumn(new VectorFieldTypeInformation<>(factory, tdim), castColumn);
        }
        // Compute distance matrix.
        double[][] imat = computeSquaredDistanceMatrix(castColumn, dist);
        doubleCenterSymmetric(imat);
        // Find eigenvectors.
        {
            double[][] evs = new double[tdim][size];
            double[] lambda = new double[tdim];
            findEigenVectors(imat, evs, lambda);
            // Undo squared, unless we were given a squared distance function:
            if (!dist.isSquared()) {
                for (int i = 0; i < tdim; i++) {
                    lambda[i] = FastMath.sqrt(Math.abs(lambda[i]));
                }
            }
            // Project each data point to the new coordinates.
            double[] buf = new double[tdim];
            for (int i = 0; i < size; i++) {
                for (int d = 0; d < tdim; d++) {
                    buf[d] = lambda[d] * evs[d][i];
                }
                column.set(i, factory.newNumberVector(buf));
            }
        }
    }
    return bundle;
}
Also used : MultipleObjectsBundle(de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle) NumberVector(de.lmu.ifi.dbs.elki.data.NumberVector) VectorFieldTypeInformation(de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation) List(java.util.List)

Example 12 with VectorFieldTypeInformation

use of de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation in project elki by elki-project.

the class GlobalPrincipalComponentAnalysisTransform method prepareStart.

@Override
protected boolean prepareStart(SimpleTypeInformation<O> in) {
    if (!(in instanceof VectorFieldTypeInformation)) {
        throw new AbortException("PCA can only applied to fixed dimensionality vectors");
    }
    dim = ((VectorFieldTypeInformation<?>) in).getDimensionality();
    covmat = new CovarianceMatrix(dim);
    return true;
}
Also used : VectorFieldTypeInformation(de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) CovarianceMatrix(de.lmu.ifi.dbs.elki.math.linearalgebra.CovarianceMatrix)

Example 13 with VectorFieldTypeInformation

use of de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation 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 14 with VectorFieldTypeInformation

use of de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation 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 15 with VectorFieldTypeInformation

use of de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation 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)

Aggregations

VectorFieldTypeInformation (de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation)22 DoubleVector (de.lmu.ifi.dbs.elki.data.DoubleVector)9 ArrayList (java.util.ArrayList)9 List (java.util.List)8 MaterializedRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedRelation)7 MultipleObjectsBundle (de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle)7 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)6 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)6 SimpleTypeInformation (de.lmu.ifi.dbs.elki.data.type.SimpleTypeInformation)5 ProxyDatabase (de.lmu.ifi.dbs.elki.database.ProxyDatabase)4 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)4 DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)3 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)3 ClassLabel (de.lmu.ifi.dbs.elki.data.ClassLabel)2 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)2 Distribution (de.lmu.ifi.dbs.elki.math.statistics.distribution.Distribution)2 Random (java.util.Random)2 ExternalID (de.lmu.ifi.dbs.elki.data.ExternalID)1 IntegerVector (de.lmu.ifi.dbs.elki.data.IntegerVector)1 SimpleClassLabel (de.lmu.ifi.dbs.elki.data.SimpleClassLabel)1