FAQ Database Discussion Community

## Fastest k nearest neighbor with arbitrary metric?

algorithm,math,discrete-mathematics,nearest-neighbor
The gotcha with this question is "arbitrary metric". If you don't know what that is, it's just the way to measure distance between points. (In the "real" world, the 1-dimensinal distance is just the absolute magnitude of the difference between the two points). Enough of the pre-lims. I'm trying to...

## how to get k nearest neighbors using weka kdtree

java,nullpointerexception,weka,nearest-neighbor
I'm trying to get k nearest neighbors using weka KDTree implementation like this: ArrayList<ArrayList<Double>> ar = new ArrayList<ArrayList<Double>>(); ArrayList<Double> d1 = new ArrayList<Double>(); d1.add(1.1); d1.add(1.1); ArrayList<Double> d2 = new ArrayList<Double>(); d2.add(2.2); d2.add(2.2); ArrayList<Double> d3 = new ArrayList<Double>(); d3.add(3.3); d3.add(3.3); ar.add(d1); ar.add(d2); ar.add(d3); Attribute a1 = new Attribute("attr1", 0); Attribute a2...

## Finding the id of the nearest neighbour in SQL

sql-server,geolocation,greatest-n-per-group,nearest-neighbor
I have a table, #geo, with points in geolocation. Id geolocation 9201 0xE6100000010CE33995EB71164CC054791243B87441C0 9202 0xE6100000010C56B77A4E7A1B4CC0D15790662C6E41C0 I calculated the distance to the nearest neighbour for each data point. I have 1000 points for 24 month. Now I replicate my code with the first 19 points in a month create table #Geo...

## How to compare every element in the RDD with every other element in the RDD ?

scala,apache-spark,nearest-neighbor
I'm Trying to perform a K nearest neighbor search using spark. I have a RDD[Seq[Double]] and I'm planing to return a RDD[(Seq[Double],Seq[Seq[Double]])] with the actual row and a list of neighbors val out = data.map(row => { val neighbours = data.top(num = 3)(new Ordering[Seq[Double]] { override def compare(a:Seq[Double],b:Seq[Double]) = {...

## Algorithm to find k neighbors in a certain range?

algorithm,data-structures,graph-algorithm,nearest-neighbor,point-clouds
Suppose there is a point cloud having 50 000 points in the x-y-z 3D space. For every point in this cloud, what algorithms or data strictures should be implemented to find k neighbours of a given point which are within a distance of [R,r]? Naive way is to go through...

## NearestNeighbors tradeoff - run faster with less accurate results

python,scikit-learn,smooth,nearest-neighbor
I'm working with a medium size dataset (shape=(14013L, 46L)). I want to smooth each sample with its knn. I'm training my model with: NearestNeighbors(n_neighbors, algorithm='ball_tree', metric=sklearn.metrics.pairwise.cosine_distances) And the smooth is as follows: def smooth(x,nbrs,data,alpha): """ input: alpha: the smoothing factor nbrs: trained NearestNeighbors from sklearn data: the original data (since...

## Avoid clash of positions in a matrix algorithm

algorithm,matrix,nearest-neighbor,neighbours
Assume you have a n x m matrix. In this matrix, you will be randomly positioning FOUR different objects say a, b, c, d. There will be many of each. Now what is the best algorithm so that when they are randomly placed, their positions don't clash? My approach would...

## Python find list of surrounding neighbours of a node in 2D array

python,arrays,nearest-neighbor
I've been working on a code (Py 2.7) that generates an array of elements with each node assigned some random numbers. Now, I wish to make a list of the surrounding elements, and find the index of the max value. The array size is variable (I considered col = array...

## Can't find certain Boost library function

c#,c++,boost,tree,nearest-neighbor
I am trying to implement a k-d tree in C# and the source I'm looking at is in C++ with Boost. The function I'm trying to find is util::subtract(). I've searched all through Boost's documentation and I can't find it anywhere. Line number 94 is the function I'm trying to...