nearest-neighbor

How to implement nearest neighbor search using KDTrees?

本秂侑毒 提交于 2019-12-11 09:48:06
问题 So, I'm implementing a KD-Tree to do a nearest neighbor search. I've got the building the tree part working, but I don't think I understand the search part completely. About traversing the tree to search for the neighbor, the Wikipedia article says the following: Starting with the root node, the algorithm moves down the tree recursively, in the same way that it would if the search point were being inserted (i.e. it goes right or left depending on whether the point is greater or less than the

How can we rotate an RGB image using nearest neighbor interpolation algorithm about a custom pivot point?

倾然丶 夕夏残阳落幕 提交于 2019-12-11 08:47:20
问题 I am trying to understand image interpolation algorithms in computer vision. I realize that there are a ton of interpolation techniques like linear, bicubic, nearest neighbor, etc. for image rotation. It seems that nearest neighbor technique is the simplest algorithm in this area.. I understand the basic concepts like when we rotate an image with a rotation matrix, the new image rows and columns go to floating point values because of cosine and sine operations. Thus we have to truncate the

Finding the neighbors of 2D array

强颜欢笑 提交于 2019-12-11 06:14:10
问题 I've a 2D grid of 75rows by 75 cols, I draw symbols of 2 colors (red and blue) on users clicks, it works fine but I'm stuck on a major problem I want to find the neighbor of those symbols: Example when the user click on a cell, it prints a symbol (oval) now I want that click also checks in its neighbors if the cell are occupied or empty, if occupied, by which symbol. I found the algorithm below which seems to fit the need, but can't figure out how to adapt to my code: private static int[][]

k* reproduction values?

試著忘記壹切 提交于 2019-12-11 05:26:53
问题 I am reading about Product Quantization, from section II.A page 3 of PQ for NNS, that says: ..all subquantizers have the same finite number k* of reproduction values. In that case the number of centroids is (k*)^m where m is the number of subvectors. However, I do not get k* at all! I mean in vector quantization we assign every vector to k centroids. In produce quantization, we assign every subvector to k centroids. How did k* come into play? 回答1: I think k* is the number of centroids in each

Finding elements within distance k from a matrix

99封情书 提交于 2019-12-11 04:39:02
问题 Given a n*n matrix and a value k, how do we find all the neighbors for each element? for example: in a 4*4 matrix, with k=2 say matrix is : [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] where these values are the indexes of the location, the neighbors for 1 are 1,2,3,5,6,9 . The values 3,6 and 9 come only because k =2 and wouldnt be there if k was = 1. similarly the neighbors of 6 will be 1 2 3 5 6 7 8 9 10 11 and 14 Can you please help me to write a c code to implement this in c++. It is the

k nearest neighbor **on a sphere** [closed]

送分小仙女□ 提交于 2019-12-11 04:36:27
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . I am trying to find the k-nearest neighbor on a sphere using R. As I deal with million of points brute force is not an option. Does anyone know how I could do? Thank you 回答1: Using the link provided by Ben Bolker I manage to solve my pb. lonlat2xyz=function (lon, lat, r) { lon = lon * pi/180 lat = lat * pi/180

What is the ε (epsilon) parameter in Locality Sensitive Hashing (LSH)?

好久不见. 提交于 2019-12-11 01:37:10
问题 I've read the original paper about Locality Sensitive Hashing. The complexity is in function of the parameter ε, but I don't understand what it is. Can you explain its meaning please? 回答1: ε is the approximation parameter . LSH (as FLANN & kd-GeRaF) is designed for high dimensional data. In that space, k-NN doesn't work well, in fact it is almost as slow as brute force, because of the curse of dimensionality. For that reason, we focus on solving the aproximate k-NN. Check Definition 1 from

Function reads np.array - produces the mean for k nn to number p in np.array

喜夏-厌秋 提交于 2019-12-10 12:24:20
问题 I need to defina a function which reads a numpy array and produces the mean for k nearest points to number p in the array. Example: array= np.array([1, 2, 3, 4, 5, 6, 7, 50, 24, 32, 9, 11, 12, 10]) p= 15 (**Note this is not a number in the array, I will need to find the number closest to p or p number itself) k = 3 In this case, I would need to generate the mean for ([11, 12, 10)] as they are closest to p = 15 With the above numbers, I will need to find the mean for k number of points closest

Postgres: How to find nearest tsrange from timestamp outside of ranges?

戏子无情 提交于 2019-12-10 11:22:26
问题 I am modeling (in Postgres 9.6.1 / postGIS 2.3.1) a booking system for local services provided by suppliers: create table supplier ( id serial primary key, name text not null check (char_length(title) < 280), type service_type, duration interval, ... geo_position geography(POINT,4326) ... ); Each supplier keeps a calendar with time slots when he/she is available to be booked: create table timeslot ( id serial primary key, supplier_id integer not null references supplier(id), slot tstzrange

Find integer nearest-neighbour in a dict

落花浮王杯 提交于 2019-12-10 09:08:03
问题 I have a dict that takes integer keys: a = {} a[1] = 100 a[55] = 101 a[127] = 102 I would like to be able to take the nearest neighbour when asking : a[20] # should return a[1] = 100 a[58] # should return a[55] = 101 a[167] # should return a[127] = 102 Is there a pythonic way of doing this? (I imagine this can be done by looping on all dict, but that's probably not the most elegant solution?) Same question with double-index (integers as well) : b[90, 1] = 100, b[90, 55] = 101, b[90, 127] =