Search in sources :

Example 41 with DoubleDBIDListIter

use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.

the class AbstractIntrinsicDimensionalityEstimator method estimate.

@Override
public double estimate(RangeQuery<?> rnq, DBIDRef cur, double range) {
    DoubleArray buf = new DoubleArray();
    int p = 0;
    for (DoubleDBIDListIter it = rnq.getRangeForDBID(cur, range).iter(); it.valid(); it.advance()) {
        if (it.doubleValue() == 0. || DBIDUtil.equal(cur, it)) {
            continue;
        }
        buf.add(it.doubleValue());
        p++;
    }
    if (p < 1) {
        throw new ArithmeticException("ID estimation requires non-zero distances.");
    }
    return estimate(buf, buf, p);
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) DoubleArray(de.lmu.ifi.dbs.elki.utilities.datastructures.arraylike.DoubleArray)

Example 42 with DoubleDBIDListIter

use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.

the class LinearScanRKNNQuery method getRKNNForBulkDBIDs.

@Override
public List<? extends DoubleDBIDList> getRKNNForBulkDBIDs(ArrayDBIDs ids, int k) {
    List<ModifiableDoubleDBIDList> rNNList = new ArrayList<>(ids.size());
    for (int i = 0; i < ids.size(); i++) {
        rNNList.add(DBIDUtil.newDistanceDBIDList());
    }
    ArrayDBIDs allIDs = DBIDUtil.ensureArray(relation.getDBIDs());
    List<? extends KNNList> kNNList = knnQuery.getKNNForBulkDBIDs(allIDs, k);
    int i = 0;
    for (DBIDIter iter = allIDs.iter(); iter.valid(); iter.advance()) {
        KNNList knn = kNNList.get(i);
        for (DoubleDBIDListIter n = knn.iter(); n.valid(); n.advance()) {
            int j = 0;
            for (DBIDIter iter2 = ids.iter(); iter2.valid(); iter2.advance()) {
                if (DBIDUtil.equal(n, iter2)) {
                    ModifiableDoubleDBIDList rNN = rNNList.get(j);
                    rNN.add(n.doubleValue(), iter);
                }
                j++;
            }
        }
        i++;
    }
    for (int j = 0; j < ids.size(); j++) {
        rNNList.get(j).sort();
    }
    return rNNList;
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList) KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) ArrayList(java.util.ArrayList) ArrayDBIDs(de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs) DBIDIter(de.lmu.ifi.dbs.elki.database.ids.DBIDIter)

Example 43 with DoubleDBIDListIter

use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.

the class OUTRES method subsetNeighborhoodQuery.

/**
 * Refine neighbors within a subset.
 *
 * @param neighc Neighbor candidates
 * @param dbid Query object
 * @param df distance function
 * @param adjustedEps Epsilon range
 * @param kernel Kernel
 * @return Neighbors of neighbor object
 */
private DoubleDBIDList subsetNeighborhoodQuery(DoubleDBIDList neighc, DBIDRef dbid, PrimitiveDistanceFunction<? super V> df, double adjustedEps, KernelDensityEstimator kernel) {
    ModifiableDoubleDBIDList n = DBIDUtil.newDistanceDBIDList(neighc.size());
    V query = kernel.relation.get(dbid);
    for (DoubleDBIDListIter neighbor = neighc.iter(); neighbor.valid(); neighbor.advance()) {
        DoubleDBIDPair p = neighbor.getPair();
        double dist = df.distance(query, kernel.relation.get(p));
        if (dist <= adjustedEps) {
            n.add(dist, p);
        }
    }
    return n;
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList) DoubleDBIDPair(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair)

Example 44 with DoubleDBIDListIter

use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.

the class OUTRES method outresScore.

/**
 * Main loop of OUTRES. Run for each object
 *
 * @param s start dimension
 * @param subspace Current subspace
 * @param id Current object ID
 * @param kernel Kernel
 * @return Score
 */
public double outresScore(final int s, long[] subspace, DBIDRef id, KernelDensityEstimator kernel) {
    // Initial score is 1.0
    double score = 1.0;
    final SubspaceEuclideanDistanceFunction df = new SubspaceEuclideanDistanceFunction(subspace);
    MeanVariance meanv = new MeanVariance();
    for (int i = s; i < kernel.dim; i++) {
        if (BitsUtil.get(subspace, i)) {
            // with i=0?
            continue;
        }
        BitsUtil.setI(subspace, i);
        df.setSelectedDimensions(subspace);
        final double adjustedEps = kernel.adjustedEps(kernel.dim);
        // Query with a larger window, to also get neighbors of neighbors
        // Subspace euclidean is metric!
        final double range = adjustedEps * 2.;
        RangeQuery<V> rq = QueryUtil.getRangeQuery(kernel.relation, df, range);
        DoubleDBIDList neighc = rq.getRangeForDBID(id, range);
        DoubleDBIDList neigh = refineRange(neighc, adjustedEps);
        if (neigh.size() > 2) {
            // Relevance test
            if (relevantSubspace(subspace, neigh, kernel)) {
                final double density = kernel.subspaceDensity(subspace, neigh);
                // Compute mean and standard deviation for densities of neighbors.
                meanv.reset();
                for (DoubleDBIDListIter neighbor = neigh.iter(); neighbor.valid(); neighbor.advance()) {
                    DoubleDBIDList n2 = subsetNeighborhoodQuery(neighc, neighbor, df, adjustedEps, kernel);
                    meanv.put(kernel.subspaceDensity(subspace, n2));
                }
                final double deviation = (meanv.getMean() - density) / (2. * meanv.getSampleStddev());
                // High deviation:
                if (deviation >= 1) {
                    score *= (density / deviation);
                }
                // Recursion
                score *= outresScore(i + 1, subspace, id, kernel);
            }
        }
        BitsUtil.clearI(subspace, i);
    }
    return score;
}
Also used : MeanVariance(de.lmu.ifi.dbs.elki.math.MeanVariance) DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) SubspaceEuclideanDistanceFunction(de.lmu.ifi.dbs.elki.distance.distancefunction.subspace.SubspaceEuclideanDistanceFunction) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList) DoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList)

Example 45 with DoubleDBIDListIter

use of de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter in project elki by elki-project.

the class AbstractIntrinsicDimensionalityEstimator method estimate.

@Override
public double estimate(KNNQuery<?> knnq, DBIDRef cur, int k) {
    double[] buf = new double[k];
    int p = 0;
    for (DoubleDBIDListIter it = knnq.getKNNForDBID(cur, k).iter(); it.valid() && p < k; it.advance()) {
        if (it.doubleValue() == 0. || DBIDUtil.equal(cur, it)) {
            continue;
        }
        buf[p++] = it.doubleValue();
    }
    if (p < 1) {
        throw new ArithmeticException("ID estimation requires non-zero distances.");
    }
    return estimate(buf, DoubleArrayAdapter.STATIC, p);
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)

Aggregations

DoubleDBIDListIter (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)69 KNNList (de.lmu.ifi.dbs.elki.database.ids.KNNList)38 DBIDIter (de.lmu.ifi.dbs.elki.database.ids.DBIDIter)34 FiniteProgress (de.lmu.ifi.dbs.elki.logging.progress.FiniteProgress)20 ModifiableDoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)19 WritableDoubleDataStore (de.lmu.ifi.dbs.elki.database.datastore.WritableDoubleDataStore)12 DoubleRelation (de.lmu.ifi.dbs.elki.database.relation.DoubleRelation)11 MaterializedDoubleRelation (de.lmu.ifi.dbs.elki.database.relation.MaterializedDoubleRelation)11 DoubleMinMax (de.lmu.ifi.dbs.elki.math.DoubleMinMax)11 OutlierResult (de.lmu.ifi.dbs.elki.result.outlier.OutlierResult)11 OutlierScoreMeta (de.lmu.ifi.dbs.elki.result.outlier.OutlierScoreMeta)11 DoubleDBIDList (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDList)10 ArrayDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayDBIDs)9 DBIDs (de.lmu.ifi.dbs.elki.database.ids.DBIDs)7 DBID (de.lmu.ifi.dbs.elki.database.ids.DBID)6 MeanVariance (de.lmu.ifi.dbs.elki.math.MeanVariance)6 ArrayModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ArrayModifiableDBIDs)5 DoubleDBIDPair (de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDPair)5 ArrayList (java.util.ArrayList)5 NumberVector (de.lmu.ifi.dbs.elki.data.NumberVector)4