Search in sources :

Example 1 with PCARunner

use of de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner in project elki by elki-project.

the class CASH method runDerivator.

/**
 * Runs the derivator on the specified interval and assigns all points having
 * a distance less then the standard deviation of the derivator model to the
 * model to this model.
 *
 * @param relation the database containing the parameterization functions
 * @param interval the interval to build the model
 * @param dim the dimensionality of the database
 * @param ids an empty set to assign the ids
 * @return a basis of the found subspace
 */
private double[][] runDerivator(Relation<ParameterizationFunction> relation, int dim, CASHInterval interval, ModifiableDBIDs ids) {
    Database derivatorDB = buildDerivatorDB(relation, interval);
    PCARunner pca = new PCARunner(new StandardCovarianceMatrixBuilder());
    EigenPairFilter filter = new FirstNEigenPairFilter(dim - 1);
    DependencyDerivator<DoubleVector> derivator = new DependencyDerivator<>(null, FormatUtil.NF4, pca, filter, 0, false);
    CorrelationAnalysisSolution<DoubleVector> model = derivator.run(derivatorDB);
    double[][] weightMatrix = model.getSimilarityMatrix();
    double[] centroid = model.getCentroid();
    double eps = .25;
    ids.addDBIDs(interval.getIDs());
    // Search for nearby vectors in original database
    for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
        double[] v = relation.get(iditer).getColumnVector();
        double d = mahalanobisDistance(weightMatrix, v, centroid);
        if (d <= eps) {
            ids.add(iditer);
        }
    }
    double[][] basis = model.getStrongEigenvectors();
    return getMatrix(basis, 0, basis.length, 0, dim - 1);
}
Also used : EigenPairFilter(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.EigenPairFilter) FirstNEigenPairFilter(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.FirstNEigenPairFilter) DependencyDerivator(de.lmu.ifi.dbs.elki.algorithm.DependencyDerivator) FirstNEigenPairFilter(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.FirstNEigenPairFilter) PCARunner(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) Database(de.lmu.ifi.dbs.elki.database.Database) ProxyDatabase(de.lmu.ifi.dbs.elki.database.ProxyDatabase) StandardCovarianceMatrixBuilder(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.StandardCovarianceMatrixBuilder)

Example 2 with PCARunner

use of de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner in project elki by elki-project.

the class CASH method runDerivator.

/**
 * Runs the derivator on the specified interval and assigns all points having
 * a distance less then the standard deviation of the derivator model to the
 * model to this model.
 *
 * @param relation the database containing the parameterization functions
 * @param ids the ids to build the model
 * @param dimensionality the dimensionality of the subspace
 * @return a basis of the found subspace
 */
private LinearEquationSystem runDerivator(Relation<ParameterizationFunction> relation, int dimensionality, DBIDs ids) {
    try {
        // build database for derivator
        Database derivatorDB = buildDerivatorDB(relation, ids);
        PCARunner pca = new PCARunner(new StandardCovarianceMatrixBuilder());
        EigenPairFilter filter = new FirstNEigenPairFilter(dimensionality);
        DependencyDerivator<DoubleVector> derivator = new DependencyDerivator<>(null, FormatUtil.NF4, pca, filter, 0, false);
        CorrelationAnalysisSolution<DoubleVector> model = derivator.run(derivatorDB);
        LinearEquationSystem les = model.getNormalizedLinearEquationSystem(null);
        return les;
    } catch (NonNumericFeaturesException e) {
        throw new IllegalStateException("Error during normalization" + e);
    }
}
Also used : EigenPairFilter(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.EigenPairFilter) FirstNEigenPairFilter(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.FirstNEigenPairFilter) DependencyDerivator(de.lmu.ifi.dbs.elki.algorithm.DependencyDerivator) FirstNEigenPairFilter(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.FirstNEigenPairFilter) PCARunner(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner) NonNumericFeaturesException(de.lmu.ifi.dbs.elki.datasource.filter.normalization.NonNumericFeaturesException) Database(de.lmu.ifi.dbs.elki.database.Database) ProxyDatabase(de.lmu.ifi.dbs.elki.database.ProxyDatabase) LinearEquationSystem(de.lmu.ifi.dbs.elki.math.linearalgebra.LinearEquationSystem) StandardCovarianceMatrixBuilder(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.StandardCovarianceMatrixBuilder)

Example 3 with PCARunner

use of de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner in project elki by elki-project.

the class ERiCNeighborPredicate method instantiate.

/**
 * Full instantiation interface.
 *
 * @param database Database
 * @param relation Relation
 * @return Instance
 */
public Instance instantiate(Database database, Relation<V> relation) {
    DistanceQuery<V> dq = database.getDistanceQuery(relation, EuclideanDistanceFunction.STATIC);
    KNNQuery<V> knnq = database.getKNNQuery(dq, settings.k);
    WritableDataStore<PCAFilteredResult> storage = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_HOT | DataStoreFactory.HINT_TEMP, PCAFilteredResult.class);
    PCARunner pca = settings.pca;
    EigenPairFilter filter = settings.filter;
    Duration time = LOG.newDuration(this.getClass().getName() + ".preprocessing-time").begin();
    FiniteProgress progress = LOG.isVerbose() ? new FiniteProgress(this.getClass().getName(), relation.size(), LOG) : null;
    for (DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
        DoubleDBIDList ref = knnq.getKNNForDBID(iditer, settings.k);
        PCAResult pcares = pca.processQueryResult(ref, relation);
        storage.put(iditer, new PCAFilteredResult(pcares.getEigenPairs(), filter.filter(pcares.getEigenvalues()), 1., 0.));
        LOG.incrementProcessed(progress);
    }
    LOG.ensureCompleted(progress);
    LOG.statistics(time.end());
    return new Instance(relation.getDBIDs(), storage, relation);
}
Also used : EigenPairFilter(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.EigenPairFilter) PCARunner(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner) FiniteProgress(de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress) Duration(de.lmu.ifi.dbs.elki.logging.statistics.Duration) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter) PCAResult(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAResult) DoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList) PCAFilteredResult(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredResult)

Example 4 with PCARunner

use of de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner in project elki by elki-project.

the class GlobalPrincipalComponentAnalysisTransform method prepareComplete.

@Override
protected void prepareComplete() {
    mean = covmat.getMeanVector();
    PCAResult pcares = (new PCARunner(null)).processCovarMatrix(covmat.destroyToPopulationMatrix());
    SortedEigenPairs eps = pcares.getEigenPairs();
    covmat = null;
    if (filter == null) {
        proj = new double[dim][dim];
        for (int d = 0; d < dim; d++) {
            EigenPair ep = eps.getEigenPair(d);
            double[] ev = ep.getEigenvector();
            double mult = 1. / FastMath.sqrt(ep.getEigenvalue());
            // Fill weighted and transposed:
            for (int i = 0; i < dim; i++) {
                proj[d][i] = ev[i] * mult;
            }
        }
    } else {
        final int pdim = filter.filter(eps.eigenValues());
        if (LOG.isVerbose()) {
            LOG.verbose("Reducing dimensionality from " + dim + " to " + pdim + " via PCA.");
        }
        proj = new double[pdim][dim];
        for (int d = 0; d < pdim; d++) {
            EigenPair ep = eps.getEigenPair(d);
            double[] ev = ep.getEigenvector();
            double mult = 1. / FastMath.sqrt(ep.getEigenvalue());
            // Fill weighted and transposed:
            for (int i = 0; i < dim; i++) {
                proj[d][i] = ev[i] * mult;
            }
        }
    }
    buf = new double[dim];
}
Also used : PCAResult(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAResult) PCARunner(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner) SortedEigenPairs(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.SortedEigenPairs) EigenPair(de.lmu.ifi.dbs.elki.math.linearalgebra.pca.EigenPair)

Aggregations

PCARunner (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner)4 EigenPairFilter (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.EigenPairFilter)3 DependencyDerivator (de.lmu.ifi.dbs.elki.algorithm.DependencyDerivator)2 Database (de.lmu.ifi.dbs.elki.database.Database)2 ProxyDatabase (de.lmu.ifi.dbs.elki.database.ProxyDatabase)2 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)2 PCAResult (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAResult)2 StandardCovarianceMatrixBuilder (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.StandardCovarianceMatrixBuilder)2 FirstNEigenPairFilter (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.FirstNEigenPairFilter)2 DoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList)1 NonNumericFeaturesException (de.lmu.ifi.dbs.elki.datasource.filter.normalization.NonNumericFeaturesException)1 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)1 Duration (de.lmu.ifi.dbs.elki.logging.statistics.Duration)1 LinearEquationSystem (de.lmu.ifi.dbs.elki.math.linearalgebra.LinearEquationSystem)1 EigenPair (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.EigenPair)1 PCAFilteredResult (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredResult)1 SortedEigenPairs (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.SortedEigenPairs)1