nearest-neighbor

Nearest neighbor search with periodic boundary conditions

蹲街弑〆低调 提交于 2019-12-03 12:08:05
问题 In a cubic box I have a large collection points in R^3. I'd like to find the k nearest neighbors for each point. Normally I'd think to use something like a k-d tree, but in this case I have periodic boundary conditions. As I understand it, a k-d tree works by partitioning the space by cutting it into hyper planes of one less dimension, i.e. in 3D we would split the space by drawing 2D planes. For any given point, it is either on the plane, above it, or below it. However, when you split the

Nearest Neighbours using Quaternions

血红的双手。 提交于 2019-12-03 09:55:31
问题 Given a quaternion value, I would like to find its nearest neighbour in a set of quaternions. To do this, I clearly need a way to compare the "distance" between two quaternions. What distance representation is needed for such a comparison and how is it computed? Thanks, Josh 回答1: Is your quaternion just a point in 3D space with an orientation? Then the distance between two quaternions x1,y1,z1,w1 and x2,y2,x2,w2 is given by: distance = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2) , assuming that

Nearest Neighbor Search in Python without k-d tree

99封情书 提交于 2019-12-03 07:28:58
I'm beginning to learn Python coming from a C++ background. What I am looking for is a quick and easy way to find the closest (nearest neighbor) of some multidimensional query point in an 2D (numpy) array of multidimensional points (also numpy arrays). I know that scipy has a k-d tree, but I don't think this is what I want. First of all, I will be changing the values of the multidimensional points in the 2D array. Secondly, the position (coordinates) of each point in the 2D array matters as I will also be changing their neighbors. I could write a function that goes through the 2D array and

Incremental Nearest Neighbor Algorithm in Python

烈酒焚心 提交于 2019-12-03 07:19:48
Is anyone aware of a nearest neighbor algorithm implemented in Python that can be updated incrementally? All the ones I've found, such as this one , appear to be batch processes. Is it possible to implement an incremental NN algorithm? RandomGuy I think the problem with incremental construction of a KD-tree or KNN-tree is, as you've alluded to in a comment, that the tree will eventually become unbalanced and you can't do simple tree rotation to fix balance problems and keep consistency. At the minimum, the re-balancing task is not trivial and one would definitely not want to do it at each

How does the KD-tree nearest neighbor search work?

♀尐吖头ヾ 提交于 2019-12-03 07:08:25
问题 I am looking at the Wikipedia page for KD trees. As an example, I implemented, in python, the algorithm for building a kd tree listed. The algorithm for doing KNN search with a KD tree, however, switches languages and isn't totally clear. The English explanation starts making sense, but parts of it (such as the area where they "unwind recursion" to check other leaf nodes) don't really make any sense to me. How does this work, and how can one do a KNN search with a KD tree in python? This isn

Image interpolation mode in Chrome/Safari?

谁说胖子不能爱 提交于 2019-12-03 04:52:55
I need to have an image render with nearest-neighbor resizing and not the bicubic way that is currently used. I currently use the following: ms-interpolation-mode: nearest-neighbor; image-rendering: -moz-crisp-edges; This works in IE and Firefox, but not in Chrome and Safari. Are there any webkit alternatives or any other way to achieve this effect? thirtydot Edit: It's now possible with image-rendering: -webkit-optimize-contrast; . https://developer.mozilla.org/en-US/docs/CSS/image-rendering#Examples This doesn't work in current versions of Chrome, here are some useful links: http:/

How to find the closest 2 points in a 100 dimensional space with 500,000 points?

梦想与她 提交于 2019-12-03 03:54:35
问题 I have a database with 500,000 points in a 100 dimensional space, and I want to find the closest 2 points. How do I do it? Update: Space is Euclidean, Sorry. And thanks for all the answers. BTW this is not homework. 回答1: You could try the ANN library, but that only gives reliable results up to 20 dimensions. 回答2: There's a chapter in Introduction to Algorithms devoted to finding two closest points in two-dimensional space in O(n*logn) time. You can check it out on google books. In fact, I

ERROR: subquery in FROM cannot refer to other relations of same query level

我们两清 提交于 2019-12-03 03:52:49
I'm working with PostgreSQL 9 and I want to find the nearest neighbor inside table RP for all tuples in RQ , comparing the dates ( t ), but I get this error: ERROR: subquery in FROM cannot refer to other relations of same query level using this query: SELECT * FROM RQ, (SELECT * FROM RP ORDER BY ABS(RP.t - RQ.t) LIMIT 1) AS RA RQ.t in subquery seems to be the problem. How can I avoid this error? How can I get access from subquery to RQ ? Erwin Brandstetter Update: LATERAL joins allow that and were introduced with Postgres 9.3. Details: What is the difference between LATERAL and a subquery in

Nearest neighbor search with periodic boundary conditions

☆樱花仙子☆ 提交于 2019-12-03 03:27:32
In a cubic box I have a large collection points in R^3. I'd like to find the k nearest neighbors for each point. Normally I'd think to use something like a k-d tree, but in this case I have periodic boundary conditions. As I understand it, a k-d tree works by partitioning the space by cutting it into hyper planes of one less dimension, i.e. in 3D we would split the space by drawing 2D planes. For any given point, it is either on the plane, above it, or below it. However, when you split the space with periodic boundary conditions a point could be considered to be on either side! What's the most

Nearest Neighbours using Quaternions

爱⌒轻易说出口 提交于 2019-12-03 00:27:10
Given a quaternion value, I would like to find its nearest neighbour in a set of quaternions. To do this, I clearly need a way to compare the "distance" between two quaternions. What distance representation is needed for such a comparison and how is it computed? Thanks, Josh Olhovsky Is your quaternion just a point in 3D space with an orientation? Then the distance between two quaternions x1,y1,z1,w1 and x2,y2,x2,w2 is given by: distance = sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2) , assuming that the w component is used for orientation. I.e. this is the same as the distance between two 3D points