Recursively search for the k nearest neighbors to target.
@param target target point
@param maxDistance maximum distance
@param k number of neighbors to find
195029
private PriorityQueue<HeapItem> search(final double[] target, double maxDistance, final int k) {
		PriorityQueue<HeapItem> heap = new PriorityQueue<HeapItem>();
		if (root == null) {
			return heap;
		}

		double tau = maxDistance;
		final FastQueue<Node> nodes = new FastQueue<Node>(20, Node.class, false);
		nodes.add(root);

		while (nodes.size() > 0) {
			final Node node = nodes.removeTail();
			final double dist = distance(items[node.index], target);

			if (dist <= tau) {
				if (heap.size() == k) {
					heap.poll();
				}
				heap.add(new HeapItem(node.index, dist));
				if (heap.size() == k) {
					tau = heap.element().dist;
				}
			}

			if (node.left != null && dist - tau <= node.threshold) {
				nodes.add(node.left);
			}

			if (node.right != null && dist + tau >= node.threshold) {
				nodes.add(node.right);
			}
		}

		return heap;
	}
717102
protected void matchPointsToClusters(List<double[]> points) {
		sumDistance = 0;
		for (int i = 0; i < points.size(); i++) {
			double[]p = points.get(i);

			// find the cluster which is closest to the point
			int bestCluster = findBestMatch(p);

			// sum up all the points which are members of this cluster
			double[] c = workClusters.get(bestCluster);
			for (int j = 0; j < c.length; j++) {
				c[j] += p[j];
			}
			memberCount.data[bestCluster]++;
			labels.data[i] = bestCluster;
			sumDistance += bestDistance;
		}
	}
71976
@VisibleForTesting static long calculateTargetReps(long reps, long nanos, long targetNanos,
      double gaussian) {
    double targetReps = (((double) reps) / nanos) * targetNanos;
    return Math.max(1L, Math.round((gaussian * (targetReps / 5)) + targetReps));
  }
96416
function findClosestPoint (sources, target) {
  const distances = [];
  let minDistance;

  sources.forEach(function (source, index) {
    const d = distance(source, target);

    distances.push(d);

    if (index === 0) {
      minDistance = d;
    } else {
      minDistance = Math.min(d, minDistance);
    }
  });

  const index = distances.indexOf(minDistance);


  return sources[index];
}
1130560
public void setBounds(int minOccurs, int maxOccurs) {
    if (minOccurs < 0 || maxOccurs < -1)
      throw new IllegalArgumentException("Bounds cannot be negative");
    else if (maxOccurs > 0 && minOccurs > maxOccurs)
      throw new IllegalArgumentException("Minimum bounds less than maximum bounds");
    limits = new int[] { minOccurs, maxOccurs };
  }
1055693
protected static void updateKDistance(int kn, LofPoint targetPoint, LofDataSet dataSet)
    {
        // 対象点のK距離、K距離近傍を算出する。
        KDistanceResult kResult = calculateKDistance(kn, targetPoint, dataSet);
        targetPoint.setkDistance(kResult.getkDistance());
        targetPoint.setkDistanceNeighbor(kResult.getkDistanceNeighbor());
    }
522027
public static double calculateLofNoIntermediate(int kn, LofPoint targetPoint, LofDataSet dataSet)
    {
        // 対象点のK距離、K距離近傍を算出する。
        KDistanceResult kResult = calculateKDistance(kn, targetPoint, dataSet);

        LofPoint tmpTargetPoint = targetPoint.deepCopy();
        tmpTargetPoint.setkDistance(kResult.getkDistance());
        tmpTargetPoint.setkDistanceNeighbor(kResult.getkDistanceNeighbor());

        // データセット用の学習データモデルを一時的に生成する。
        LofDataSet tmpDataSet = dataSet.deepCopy();
        initDataSet(kn, tmpDataSet);

        updateLrd(tmpTargetPoint, tmpDataSet);

        // 対象の局所外れ係数を算出する。
        double lof = calculateLof(tmpTargetPoint, tmpDataSet);
        return lof;
    }
268280
private void checkTargetDistance(double dist)
    {
        if (distAttack.includes(dist))
        {
            if (checker.canAttack())
            {
                state = AttackState.ATTACKING;
            }
        }
        else if (tick.elapsed(attackPause))
        {
            for (final AttackerListener listener : listeners)
            {
                listener.notifyReachingTarget(target);
            }
        }
    }
142511
private boolean incrementalDistanceMatrixComputation(int from,int to,Bounds i) {
		logger.fine("Propagating (quad) with (#TPs,#cons) = (" + this.MAX_USED + "," + this.theNetwork.getConstraints().length + ") (call num.: " + (++quadPropCount) + ")");

		if (distance[to][from] != APSPSolver.INF && sum(i.max,distance[to][from]) < 0) return false;
		if (distance[from][to] != APSPSolver.INF && sum(-i.min,distance[from][to]) < 0) return false;
		
//		System.out.println("a)" + sum(i.max,distance[to][from]));
//		System.out.println("b)" + sum(-i.min,distance[from][to]));
		
		long sum1;
		long sum2;
		long sum3;
		long sum4;
		long temp;
		
		for (int u = 0; u < MAX_USED+1; u++) {
			if (tPoints[u].isUsed()) {
				for (int v = 0; v < MAX_USED+1;v++) {
					if (tPoints[v].isUsed()) {
						//min{distance[u][v];(distance[u][from]+i.max+distance[to][v]);(distance[u][to]-i.minl+distance[from][v])}
						sum1 = sum(distance[u][to],-i.min);
						sum2 = sum(sum1,distance[from][v]);
						sum3 = sum(distance[u][from],i.max);
						sum4 = sum(sum3,distance[to][v]);
						temp = Math.min(sum2,sum4);
												
						if (distance[u][v] > temp) {
							//long oldD = distance[u][v];
							distance[u][v] = temp;
							if (u == v && distance[u][v] != 0) {
								//logger.info("==================> Updated distance[" + u + "][" + v + "] from " + oldD + " to " + temp);
								//throw new Error("Found negative cycle in incremental propagation while adding (from,to,i) (" + from + "," + to + "," + i + ")");
								return false;
							}
						}
					}
				}
			}
		}
		return true;
	}
433655
public int findClosest( P p , double maxDistance ) {
		int best = -1;
		bestDistance = maxDistance;

		for( int i = 0; i < points.size(); i++ ) {
			P c = points.get(i);

			double distanceC = distance.distance(p,c);

			if( distanceC <= bestDistance ) {
				bestDistance = distanceC;
				best = i;
			}
		}

		return best;
	}
500809
protected int[] computeNearestCoarseIndices(double[] vector, int k) {
		BoundedPriorityQueue<Result> bpq = new BoundedPriorityQueue<Result>(new Result(), k);

		double lowest = Double.MAX_VALUE;
		for (int i = 0; i < numCoarseCentroids; i++) {
			boolean skip = false;
			double l2distance = 0;
			for (int j = 0; j < vectorLength; j++) {
				l2distance += (coarseQuantizer[i][j] - vector[j]) * (coarseQuantizer[i][j] - vector[j]);
				if (l2distance > lowest) {
					skip = true;
					break;
				}
			}
			if (!skip) {
				bpq.offer(new Result(i, l2distance));
				if (i >= k) {
					lowest = bpq.last().getDistance();
				}
			}
		}
		int[] nn = new int[k];
		for (int i = 0; i < k; i++) {
			nn[i] = bpq.poll().getId();
		}
		return nn;
	}
1288224
@Override
	public KdTree.Node findNeighbor(P target) {
		if( tree.root == null )
			return null;

		this.target = target;
		this.closest = null;
		this.bestDistanceSq = maxDistanceSq;

		stepClosest(tree.root);

		return closest;
	}
200765
@Override
  protected void integrityCheckParameters(MkMaxEntry parentEntry, MkMaxTreeNode<O> parent, int index, AbstractMTree<O, MkMaxTreeNode<O>, MkMaxEntry, ?> mTree) {
    super.integrityCheckParameters(parentEntry, parent, index, mTree);
    // test if knn distance is correctly set
    MkMaxEntry entry = parent.getEntry(index);
    double knnDistance = kNNDistance();
    if(Math.abs(entry.getKnnDistance() - knnDistance) > 0) {
      throw new RuntimeException("Wrong knnDistance in node " + parent.getPageID() + " at index " + index + " (child " + entry + ")" + "\nsoll: " + knnDistance + ",\n ist: " + entry.getKnnDistance());
    }
  }
901084
public void setReferenceDistance (float distance)
    {
        if (_referenceDistance != distance) {
            AL10.alSourcef(_id, AL10.AL_REFERENCE_DISTANCE, _referenceDistance = distance);
        }
    }
687466
protected ApproximationLine conservativeKnnDistanceApproximation(int k_max) {
    // determine k_0, y_1, y_kmax
    int k_0 = k_max;
    double y_1 = Double.NEGATIVE_INFINITY;
    double y_kmax = Double.NEGATIVE_INFINITY;

    for(int i = 0; i < getNumEntries(); i++) {
      MkCoPEntry entry = getEntry(i);
      ApproximationLine approx = entry.getConservativeKnnDistanceApproximation();
      k_0 = Math.min(approx.getK_0(), k_0);
    }

    for(int i = 0; i < getNumEntries(); i++) {
      MkCoPEntry entry = getEntry(i);
      ApproximationLine approx = entry.getConservativeKnnDistanceApproximation();
      double entry_y_1 = approx.getValueAt(k_0);
      double entry_y_kmax = approx.getValueAt(k_max);
      if(!Double.isInfinite(entry_y_1)) {
        y_1 = Math.max(entry_y_1, y_1);
      }

      if(!Double.isInfinite(entry_y_kmax)) {
        y_kmax = Math.max(entry_y_kmax, y_kmax);
      }
    }

    // determine m and t
    double m = (y_kmax - y_1) / (FastMath.log(k_max) - FastMath.log(k_0));
    double t = y_1 - m * FastMath.log(k_0);

    return new ApproximationLine(k_0, m, t);
  }
187371
public AVIMConversationsQuery whereWithinMiles(String key, AVGeoPoint point, double maxDistance) {
    conditions.whereWithinMiles(key, point, maxDistance);
    return this;
  }
633990
public double distance( NccFeature observed , List<NccFeature> candidates ) {

		double maximum = -Double.MAX_VALUE;

		// The feature which has the best fit will maximize the score
		for( NccFeature f : candidates ) {
			double score = DescriptorDistance.ncc(observed, f);
			if( score > maximum )
				maximum = score;
		}

		return 1-0.5*(maximum + 1);
	}