de.lmu.ifi.dbs.elki.database.relation.Relation.getDistanceQuery()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(14.1k)|赞(0)|评价(0)|浏览(163)

本文整理了Java中de.lmu.ifi.dbs.elki.database.relation.Relation.getDistanceQuery方法的一些代码示例,展示了Relation.getDistanceQuery的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Relation.getDistanceQuery方法的具体详情如下:
包路径:de.lmu.ifi.dbs.elki.database.relation.Relation
类名称:Relation
方法名:getDistanceQuery

Relation.getDistanceQuery介绍

[英]Get the distance query for a particular distance function.
[中]获取特定距离函数的距离查询。

代码示例

代码示例来源:origin: elki-project/elki

@Override
public <O> DistanceQuery<O> getDistanceQuery(Relation<O> objQuery, DistanceFunction<? super O> distanceFunction, Object... hints) {
 return objQuery.getDistanceQuery(distanceFunction, hints);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki

@Override
public <O> DistanceQuery<O> getDistanceQuery(Relation<O> objQuery, DistanceFunction<? super O> distanceFunction, Object... hints) {
 return objQuery.getDistanceQuery(distanceFunction, hints);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-database

@Override
public <O> DistanceQuery<O> getDistanceQuery(Relation<O> objQuery, DistanceFunction<? super O> distanceFunction, Object... hints) {
 return objQuery.getDistanceQuery(distanceFunction, hints);
}

代码示例来源:origin: elki-project/elki

/**
 * Get a range query object for the given distance query. (Range queries in
 * ELKI refers to radius-based ranges, not rectangular query windows.)
 *
 * When possible, this will use an index, but it may default to an expensive
 * linear scan.
 *
 * Hints include:
 * <ul>
 * <li>Distance object: Maximum query range</li>
 * <li>{@link DatabaseQuery#HINT_BULK} bulk query needed</li>
 * </ul>
 *
 * @param distanceFunction Distance function to use
 * @param hints Optimizer hints (optional)
 * @return KNN Query object
 */
default RangeQuery<O> getRangeQuery(DistanceFunction<? super O> distanceFunction, Object... hints) {
 DistanceQuery<O> distanceQuery = getDistanceQuery(distanceFunction, hints);
 return getRangeQuery(distanceQuery, hints);
}

代码示例来源:origin: elki-project/elki

/**
  * Get a rKNN query object for the given distance query.
  *
  * When possible, this will use an index, but it may default to an expensive
  * linear scan.
  *
  * Hints include:
  * <ul>
  * <li>Integer: maximum value for k needed</li>
  * <li>{@link DatabaseQuery#HINT_BULK} bulk query needed</li>
  * </ul>
  *
  * @param distanceFunction Distance function to use
  * @param hints Optimizer hints (optional)
  * @return KNN Query object
  */
 default RKNNQuery<O> getRKNNQuery(DistanceFunction<? super O> distanceFunction, Object... hints) {
  DistanceQuery<O> distanceQuery = getDistanceQuery(distanceFunction, hints);
  return getRKNNQuery(distanceQuery, hints);
 }
}

代码示例来源:origin: elki-project/elki

/**
 * Get a KNN query object for the given distance query.
 *
 * When possible, this will use an index, but it may default to an expensive
 * linear scan.
 *
 * Hints include:
 * <ul>
 * <li>Integer: maximum value for k needed</li>
 * <li>{@link DatabaseQuery#HINT_BULK} bulk query needed</li>
 * </ul>
 *
 * @param distanceFunction Distance function to use
 * @param hints Optimizer hints (optional)
 * @return KNN Query object
 */
default KNNQuery<O> getKNNQuery(DistanceFunction<? super O> distanceFunction, Object... hints) {
 DistanceQuery<O> distanceQuery = getDistanceQuery(distanceFunction, hints);
 return getKNNQuery(distanceQuery, hints);
}

代码示例来源:origin: elki-project/elki

/**
 * Get a KNN query object for the given distance function.
 *
 * An index is used when possible, but it may fall back to a linear scan.
 *
 * Hints include:
 * <ul>
 * <li>Integer: maximum value for k needed</li>
 * <li>{@link de.lmu.ifi.dbs.elki.database.query.DatabaseQuery#HINT_BULK} bulk
 * query needed</li>
 * </ul>
 *
 * @param relation Relation used
 * @param distanceFunction Distance function
 * @param hints Optimizer hints
 *
 * @param <O> Object type
 * @return KNN Query object
 */
public static <O> KNNQuery<O> getKNNQuery(Relation<O> relation, DistanceFunction<? super O> distanceFunction, Object... hints) {
 final DistanceQuery<O> distanceQuery = relation.getDistanceQuery(distanceFunction, hints);
 return relation.getKNNQuery(distanceQuery, hints);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-core-api

/**
 * Get a range query object for the given distance query. (Range queries in
 * ELKI refers to radius-based ranges, not rectangular query windows.)
 *
 * When possible, this will use an index, but it may default to an expensive
 * linear scan.
 *
 * Hints include:
 * <ul>
 * <li>Distance object: Maximum query range</li>
 * <li>{@link DatabaseQuery#HINT_BULK} bulk query needed</li>
 * </ul>
 *
 * @param distanceFunction Distance function to use
 * @param hints Optimizer hints (optional)
 * @return KNN Query object
 */
default RangeQuery<O> getRangeQuery(DistanceFunction<? super O> distanceFunction, Object... hints) {
 DistanceQuery<O> distanceQuery = getDistanceQuery(distanceFunction, hints);
 return getRangeQuery(distanceQuery, hints);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-core-api

/**
  * Get a rKNN query object for the given distance query.
  *
  * When possible, this will use an index, but it may default to an expensive
  * linear scan.
  *
  * Hints include:
  * <ul>
  * <li>Integer: maximum value for k needed</li>
  * <li>{@link DatabaseQuery#HINT_BULK} bulk query needed</li>
  * </ul>
  *
  * @param distanceFunction Distance function to use
  * @param hints Optimizer hints (optional)
  * @return KNN Query object
  */
 default RKNNQuery<O> getRKNNQuery(DistanceFunction<? super O> distanceFunction, Object... hints) {
  DistanceQuery<O> distanceQuery = getDistanceQuery(distanceFunction, hints);
  return getRKNNQuery(distanceQuery, hints);
 }
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-core-api

/**
 * Get a KNN query object for the given distance query.
 *
 * When possible, this will use an index, but it may default to an expensive
 * linear scan.
 *
 * Hints include:
 * <ul>
 * <li>Integer: maximum value for k needed</li>
 * <li>{@link DatabaseQuery#HINT_BULK} bulk query needed</li>
 * </ul>
 *
 * @param distanceFunction Distance function to use
 * @param hints Optimizer hints (optional)
 * @return KNN Query object
 */
default KNNQuery<O> getKNNQuery(DistanceFunction<? super O> distanceFunction, Object... hints) {
 DistanceQuery<O> distanceQuery = getDistanceQuery(distanceFunction, hints);
 return getKNNQuery(distanceQuery, hints);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki

/**
 * Get a rKNN query object for the given distance function.
 *
 * When possible, this will use an index, but it may default to an expensive
 * linear scan.
 *
 * Hints include:
 * <ul>
 * <li>Integer: maximum value for k needed</li>
 * <li>{@link de.lmu.ifi.dbs.elki.database.query.DatabaseQuery#HINT_BULK} bulk
 * query needed</li>
 * </ul>
 *
 * @param relation Relation used
 * @param distanceFunction Distance function
 * @param hints Optimizer hints
 *
 * @param <O> Object type
 * @return RKNN Query object
 */
public static <O> RKNNQuery<O> getRKNNQuery(Relation<O> relation, DistanceFunction<? super O> distanceFunction, Object... hints) {
 final DistanceQuery<O> distanceQuery = relation.getDistanceQuery(distanceFunction, hints);
 return relation.getRKNNQuery(distanceQuery, hints);
}

代码示例来源:origin: elki-project/elki

/**
 * Get a KNN query object for the given distance function.
 *
 * An index is used when possible, but it may fall back to a linear scan.
 *
 * Hints include:
 * <ul>
 * <li>Integer: maximum value for k needed</li>
 * <li>{@link de.lmu.ifi.dbs.elki.database.query.DatabaseQuery#HINT_BULK} bulk
 * query needed</li>
 * </ul>
 *
 * @param <O> Object type
 * @param database Database
 * @param distanceFunction Distance function
 * @param hints Optimizer hints
 * @return KNN Query object
 */
public static <O> KNNQuery<O> getKNNQuery(Database database, DistanceFunction<? super O> distanceFunction, Object... hints) {
 final Relation<O> relation = database.getRelation(distanceFunction.getInputTypeRestriction(), hints);
 final DistanceQuery<O> distanceQuery = relation.getDistanceQuery(distanceFunction, hints);
 return relation.getKNNQuery(distanceQuery, hints);
}

代码示例来源:origin: elki-project/elki

@Override
public <T extends O> AffinityMatrix computeAffinityMatrix(Relation<T> relation, double initialScale) {
 DistanceQuery<T> dq = relation.getDistanceQuery(distanceFunction);
 ArrayDBIDs ids = DBIDUtil.ensureArray(relation.getDBIDs());
 // Compute desired affinities.
 double[][] dist = buildDistanceMatrix(ids, dq);
 return new DenseAffinityMatrix(computePij(dist, sigma, initialScale), ids);
}

代码示例来源:origin: elki-project/elki

@Override
public <T extends O> AffinityMatrix computeAffinityMatrix(Relation<T> relation, double initialScale) {
 DistanceQuery<T> dq = relation.getDistanceQuery(distanceFunction);
 ArrayDBIDs ids = DBIDUtil.ensureArray(relation.getDBIDs());
 // Compute desired affinities.
 double[][] dist = buildDistanceMatrix(ids, dq);
 return new DenseAffinityMatrix(computePij(dist, perplexity, initialScale), ids);
}

代码示例来源:origin: elki-project/elki

/**
 * Find the neighbors of point q in the given subspace
 *
 * @param q Query point
 * @param nD Subspace mask
 * @param S Remaining data points
 * @param relation Data relation
 * @return Neighbors
 */
protected DBIDs findNeighbors(DBIDRef q, long[] nD, ArrayModifiableDBIDs S, Relation<V> relation) {
 // Weights for distance (= rectangle query)
 DistanceQuery<V> dq = relation.getDistanceQuery(new SubspaceMaximumDistanceFunction(nD));
 // TODO: add filtering capabilities into query API!
 // Until then, using the range query API will be unnecessarily slow.
 // RangeQuery<V> rq = relation.getRangeQuery(df, DatabaseQuery.HINT_SINGLE);
 ArrayModifiableDBIDs nC = DBIDUtil.newArray();
 for(DBIDIter it = S.iter(); it.valid(); it.advance()) {
  if(dq.distance(q, it) <= w) {
   nC.add(it);
  }
 }
 return nC;
}

代码示例来源:origin: elki-project/elki

@Override
public <T extends O> AffinityMatrix computeAffinityMatrix(Relation<T> relation, double initialScale) {
 DistanceQuery<T> dq = relation.getDistanceQuery(distanceFunction);
 final int numberOfNeighbours = (int) FastMath.ceil(3 * perplexity);
 KNNQuery<T> knnq = relation.getKNNQuery(dq, numberOfNeighbours + 1);
 if(knnq instanceof LinearScanQuery && numberOfNeighbours * numberOfNeighbours < relation.size()) {
  LOG.warning("To accelerate Barnes-Hut tSNE, please use an index.");
 }
 if(!(relation.getDBIDs() instanceof DBIDRange)) {
  throw new AbortException("Distance matrixes are currently only supported for DBID ranges (as used by static databases) for performance reasons (Patches welcome).");
 }
 DBIDRange rids = (DBIDRange) relation.getDBIDs();
 final int size = rids.size();
 // Sparse affinity graph
 double[][] pij = new double[size][];
 int[][] indices = new int[size][];
 final boolean square = !SquaredEuclideanDistanceFunction.class.isInstance(dq.getDistanceFunction());
 computePij(rids, knnq, square, numberOfNeighbours, pij, indices, initialScale);
 SparseAffinityMatrix mat = new SparseAffinityMatrix(pij, indices, rids);
 return mat;
}

代码示例来源:origin: elki-project/elki

@Override
public <T extends O> AffinityMatrix computeAffinityMatrix(Relation<T> relation, double initialScale) {
 DistanceQuery<T> dq = relation.getDistanceQuery(distanceFunction);
 KNNQuery<T> knnq = relation.getKNNQuery(dq, numberOfNeighbours + 1);
 if(knnq instanceof LinearScanQuery && numberOfNeighbours * numberOfNeighbours < relation.size()) {
  LOG.warning("To accelerate Barnes-Hut tSNE, please use an index.");
 }
 if(!(relation.getDBIDs() instanceof DBIDRange)) {
  throw new AbortException("Distance matrixes are currently only supported for DBID ranges (as used by static databases) for performance reasons (Patches welcome).");
 }
 DBIDRange rids = (DBIDRange) relation.getDBIDs();
 final int size = rids.size();
 // Sparse affinity graph
 double[][] pij = new double[size][];
 int[][] indices = new int[size][];
 final boolean square = !dq.getDistanceFunction().isSquared();
 computePij(rids, knnq, square, numberOfNeighbours, pij, indices, initialScale);
 SparseAffinityMatrix mat = new SparseAffinityMatrix(pij, indices, rids);
 return mat;
}

代码示例来源:origin: elki-project/elki

@Override
protected void preprocess() {
 DistanceQuery<O> distanceQuery = relation.getDistanceQuery(distanceFunction);
 storage = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_STATIC, KNNList.class);
 FiniteProgress progress = getLogger().isVerbose() ? new FiniteProgress("Materializing random-sample k nearest neighbors (k=" + k + ")", relation.size(), getLogger()) : null;
 final ArrayDBIDs ids = DBIDUtil.ensureArray(relation.getDBIDs());
 final int samplesize = (int) (ids.size() * share);
 Random random = rnd.getSingleThreadedRandom();
 for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
  KNNHeap kNN = DBIDUtil.newHeap(k);
  DBIDs rsamp = DBIDUtil.randomSample(ids, samplesize, random);
  for(DBIDIter iter2 = rsamp.iter(); iter2.valid(); iter2.advance()) {
   double dist = distanceQuery.distance(iter, iter2);
   kNN.insert(dist, iter2);
  }
  storage.put(iter, kNN.toKNNList());
  getLogger().incrementProcessed(progress);
 }
 getLogger().ensureCompleted(progress);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki-index-preprocessed

@Override
protected void preprocess() {
 DistanceQuery<O> distanceQuery = relation.getDistanceQuery(distanceFunction);
 storage = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_STATIC, KNNList.class);
 FiniteProgress progress = getLogger().isVerbose() ? new FiniteProgress("Materializing random-sample k nearest neighbors (k=" + k + ")", relation.size(), getLogger()) : null;
 final ArrayDBIDs ids = DBIDUtil.ensureArray(relation.getDBIDs());
 final int samplesize = (int) (ids.size() * share);
 Random random = rnd.getSingleThreadedRandom();
 for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
  KNNHeap kNN = DBIDUtil.newHeap(k);
  DBIDs rsamp = DBIDUtil.randomSample(ids, samplesize, random);
  for(DBIDIter iter2 = rsamp.iter(); iter2.valid(); iter2.advance()) {
   double dist = distanceQuery.distance(iter, iter2);
   kNN.insert(dist, iter2);
  }
  storage.put(iter, kNN.toKNNList());
  getLogger().incrementProcessed(progress);
 }
 getLogger().ensureCompleted(progress);
}

代码示例来源:origin: de.lmu.ifi.dbs.elki/elki

@Override
protected void preprocess() {
 DistanceQuery<O> distanceQuery = relation.getDistanceQuery(distanceFunction);
 storage = DataStoreUtil.makeStorage(relation.getDBIDs(), DataStoreFactory.HINT_STATIC, KNNList.class);
 FiniteProgress progress = getLogger().isVerbose() ? new FiniteProgress("Materializing random-sample k nearest neighbors (k=" + k + ")", relation.size(), getLogger()) : null;
 final ArrayDBIDs ids = DBIDUtil.ensureArray(relation.getDBIDs());
 final int samplesize = (int) (ids.size() * share);
 Random random = rnd.getSingleThreadedRandom();
 for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
  KNNHeap kNN = DBIDUtil.newHeap(k);
  DBIDs rsamp = DBIDUtil.randomSample(ids, samplesize, random);
  for(DBIDIter iter2 = rsamp.iter(); iter2.valid(); iter2.advance()) {
   double dist = distanceQuery.distance(iter, iter2);
   kNN.insert(dist, iter2);
  }
  storage.put(iter, kNN.toKNNList());
  getLogger().incrementProcessed(progress);
 }
 getLogger().ensureCompleted(progress);
}

相关文章