nearest-neighbor

Nearest Neighbor Searching using Voronoi Diagrams

╄→尐↘猪︶ㄣ 提交于 2019-11-29 01:47:46
I've successfully implemented a way to generate Voronoi diagrams in 2 dimensions using Fortune's method. But now I'm trying to use it for nearest neighbor queries for a point (which is not one of the original points used to generate the diagram). I keep seeing people saying that it can be done in O(lg n) time (and I believe them), but I can't find a description of how it's actually done. I'm familiar with binary searches, but I can't figure out a good criteria to guarantee that upper bound. I also figured maybe it could have to do with inserting the point into the diagram and updating

Algorithm to find for all points in set A the nearest neighbor in set B

旧时模样 提交于 2019-11-28 21:54:00
Suppose we have two sets of points A, B, and we want to find for every point in set A its nearest neighbor in set B. There are many good algorithms to find the nearest neighbor for one point. Is there some way to use the information we got for a_1, to more efficiently search for the nearest neighbor for a_2 or other points in the set? I am thinking something like: use triangular inequlity to get a interval for possible distance between every point in B and new point a_2, and sort the max and min of the intervals, and then I can search only the points in B which falls in the first interval.

Distance of point feature to nearest polygon in R

拥有回忆 提交于 2019-11-28 19:55:05
I working on a project at the moment, where I have a point feature -- the point feature includes a 142 points -- and multiple polygon (around 10). I want to calculate the distance between every single point and the nearest polygon feature in R. My current approach is tedious and a bit long winded. I am currently planning to calculate the distance between every single point and every single polygon. For example, I would calculate the distance between the 142 points and Polygon A, the distance between the 142 points and Polygon B, the distance between 142 points and Polygon C, etc. Here is a

HTML5 Canvas Image Scaling Issue

这一生的挚爱 提交于 2019-11-28 19:16:04
问题 I am trying to make a pixel art themed game in HTML5 canvas, and as part of that I take 10x20 or so sized images and draw them onto the canvas with the following code: ctx.drawImage(image, 20, 20, 100, 200); However the canvas uses bicubic image scaling and hence the pixel art images look terrible at 2x and up. Is there a way to force canvas to use nearest neighbor scaling or possibly use a custom method to scale images? If not does that mean the images have to be scaled beforehand in

Confusion in hashing used by LSH

不羁的心 提交于 2019-11-28 14:21:15
Matrix M is the signatures matrix, which is produced via Minhashing of the actual data, has documents as columns and words as rows. So a column represents a document. Now it says that every stripe ( b in number, r in length) has its columns hashed, so that a column falls in a bucket. If two columns fall in the same bucket, for >= 1 stripes, then they are potentially similar. So that means that I should create b hashtables and find b independent hash functions? Or just one is enough and every stripe sends its columns to the same collections of buckets (but wouldn't this cancel the stripes)?

Filing the entire volume of a cube with small cubes in MATLAB

隐身守侯 提交于 2019-11-28 13:51:36
I have built a hollow cube in MATLAB, I want to completely fill its volume with small cubes. Then I want to find a way to access these cubes and make paths through them, i.e if cube x is currently accessed, there should be a way to know what is its right, left, top, bottom, front, and back closest neighbors (closest neighbors= the cubes directly beside the current cube). I think we have 6 neighbors, because we have 6 different faces of the cube. By knowing the nearest cube at every direction, a path through the cubes can be defined as a series of steps (eg, right, left, left, top, right, front

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

浪尽此生 提交于 2019-11-28 12:37:43
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]) = { euclideanDistance(a,row).compare(euclideanDistance(b,row))*(-1) } }) (row,neighbours.toSeq) }) And it Gives the following error on spark Submit 15/04/29 21:15:39 WARN TaskSetManager: Lost task 0.0 in stage 1.0 (TID 2, 192.168.1.7): org.apache.spark

R: find nearest index

五迷三道 提交于 2019-11-28 11:23:09
I have two vectors with a few thousand points, but generalized here: A <- c(10, 20, 30, 40, 50) b <- c(13, 17, 20) How can I get the indicies of A that are nearest to b ? The expected outcome would be c(1, 2, 2) . I know that findInterval can only find the first occurrence, and not the nearest, and I'm aware that which.min(abs(b[2] - A)) is getting warmer, but I can't figure out how to vectorize it to work with long vectors of both A and b . You can just put your code in a sapply. I think this has the same speed as a for loop so isn't technically vectorized though: sapply(b,function(x)which

Search in locality sensitive hashing

杀马特。学长 韩版系。学妹 提交于 2019-11-28 09:35:13
问题 I'm trying to understand the section 5. of this paper about LSH, in particular how to bucket the generated hashes. Quoting the linked paper: Given bit vectors consisting of d bits each, we choose N = O(n 1/(1+epsilon) ) random permutations of the bits. For each random permutation σ, we maintain a sorted order O σ of the bit vectors, in lexicographic order of the bits permuted by σ. Given a query bit vector q, we find the approximate nearest neighbor by doing the following: For each permu-

Variation on “How to plot decision boundary of a k-nearest neighbor classifier from Elements of Statistical Learning?”

放肆的年华 提交于 2019-11-28 09:21:41
This is a question related to https://stats.stackexchange.com/questions/21572/how-to-plot-decision-boundary-of-a-k-nearest-neighbor-classifier-from-elements-o For completeness, here's the original example from that link: library(ElemStatLearn) require(class) x <- mixture.example$x g <- mixture.example$y xnew <- mixture.example$xnew mod15 <- knn(x, xnew, g, k=15, prob=TRUE) prob <- attr(mod15, "prob") prob <- ifelse(mod15=="1", prob, 1-prob) px1 <- mixture.example$px1 px2 <- mixture.example$px2 prob15 <- matrix(prob, length(px1), length(px2)) par(mar=rep(2,4)) contour(px1, px2, prob15, levels=0