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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations