Search in sources :

Example 31 with DoubleDBIDListIter

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

the class KNNClassifier method classify.

@Override
public ClassLabel classify(O instance) {
    Object2IntOpenHashMap<ClassLabel> count = new Object2IntOpenHashMap<>();
    KNNList query = knnq.getKNNForObject(instance, k);
    for (DoubleDBIDListIter neighbor = query.iter(); neighbor.valid(); neighbor.advance()) {
        count.addTo(labelrep.get(neighbor), 1);
    }
    int bestoccur = Integer.MIN_VALUE;
    ClassLabel bestl = null;
    for (ObjectIterator<Entry<ClassLabel>> iter = count.object2IntEntrySet().fastIterator(); iter.hasNext(); ) {
        Entry<ClassLabel> entry = iter.next();
        if (entry.getIntValue() > bestoccur) {
            bestoccur = entry.getIntValue();
            bestl = entry.getKey();
        }
    }
    return bestl;
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) Entry(it.unimi.dsi.fastutil.objects.Object2IntMap.Entry) ClassLabel(de.lmu.ifi.dbs.elki.data.ClassLabel) KNNList(de.lmu.ifi.dbs.elki.database.ids.KNNList) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)

Example 32 with DoubleDBIDListIter

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

the class AbstractCoverTree method collectByCover.

/**
 * Collect all elements with respect to a new routing object.
 *
 * @param cur Routing object
 * @param candidates Candidate list
 * @param fmax Maximum distance
 * @param collect Output list
 */
protected void collectByCover(DBIDRef cur, ModifiableDoubleDBIDList candidates, double fmax, ModifiableDoubleDBIDList collect) {
    assert (collect.size() == 0) : "Not empty";
    // Except first = cur!
    DoubleDBIDListIter it = candidates.iter().advance();
    while (it.valid()) {
        assert (!DBIDUtil.equal(cur, it));
        final double dist = distance(cur, it);
        if (dist <= fmax) {
            // Collect
            collect.add(dist, it);
            candidates.removeSwap(it.getOffset());
        } else {
            // Keep in candidates, outside cover radius.
            it.advance();
        }
    }
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)

Example 33 with DoubleDBIDListIter

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

the class AbstractCoverTree method excludeNotCovered.

/**
 * Retain all elements within the current cover.
 *
 * @param candidates Candidates
 * @param fmax Maximum distance
 * @param collect Far neighbors
 */
protected void excludeNotCovered(ModifiableDoubleDBIDList candidates, double fmax, ModifiableDoubleDBIDList collect) {
    for (DoubleDBIDListIter it = candidates.iter(); it.valid(); ) {
        if (it.doubleValue() > fmax) {
            collect.add(it.doubleValue(), it);
            candidates.removeSwap(it.getOffset());
        } else {
            // Keep in candidates
            it.advance();
        }
    }
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)

Example 34 with DoubleDBIDListIter

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

the class AbstractCoverTree method maxDistance.

/**
 * Find maximum in a list via scanning.
 *
 * @param elems Elements
 * @return Maximum distance
 */
protected double maxDistance(DoubleDBIDList elems) {
    double max = 0;
    for (DoubleDBIDListIter it = elems.iter(); it.valid(); it.advance()) {
        final double v = it.doubleValue();
        max = max > v ? max : v;
    }
    return max;
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter)

Example 35 with DoubleDBIDListIter

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

the class InMemoryInvertedIndex method naiveQuerySparse.

/**
 * Query the most similar objects, sparse version.
 *
 * @param obj Query object
 * @param scores Score storage
 * @param cands Non-zero objects set
 * @return Result
 */
private double naiveQuerySparse(SparseNumberVector obj, WritableDoubleDataStore scores, HashSetModifiableDBIDs cands) {
    // Length of query object, for final normalization
    double len = 0.;
    for (int iter = obj.iter(); obj.iterValid(iter); iter = obj.iterAdvance(iter)) {
        final int dim = obj.iterDim(iter);
        final double val = obj.iterDoubleValue(iter);
        if (val == 0. || val != val) {
            continue;
        }
        len += val * val;
        // No matching documents in index:
        if (dim >= index.size()) {
            continue;
        }
        ModifiableDoubleDBIDList column = index.get(dim);
        for (DoubleDBIDListIter n = column.iter(); n.valid(); n.advance()) {
            scores.increment(n, n.doubleValue() * val);
            cands.add(n);
        }
    }
    return FastMath.sqrt(len);
}
Also used : DoubleDBIDListIter(de.lmu.ifi.dbs.elki.database.ids.DoubleDBIDListIter) ModifiableDoubleDBIDList(de.lmu.ifi.dbs.elki.database.ids.ModifiableDoubleDBIDList)

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