nearest-neighbor

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

▼魔方 西西 提交于 2019-11-27 08:01:23
问题 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,

R: find nearest index

非 Y 不嫁゛ 提交于 2019-11-27 06:08:38
问题 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 . 回答1: You can just put your code in a sapply. I

How to efficiently find k-nearest neighbours in high-dimensional data?

梦想与她 提交于 2019-11-27 05:43:13
问题 So I have about 16,000 75-dimensional data points, and for each point I want to find its k nearest neighbours (using euclidean distance, currently k=2 if this makes it easiser) My first thought was to use a kd-tree for this, but as it turns out they become rather inefficient as the number of dimension grows. In my sample implementation, its only slightly faster than exhaustive search. My next idea would be using PCA (Principal Component Analysis) to reduce the number of dimensions, but I was

Pixel neighbors in 2d array (image) using Python

爷,独闯天下 提交于 2019-11-27 04:26:14
问题 I have a numpy array like this: x = np.array([[1,2,3],[4,5,6],[7,8,9]]) I need to create a function let's call it "neighbors" with the following input parameter: x: a numpy 2d array (i,j): the index of an element in a 2d array d: neighborhood radius As output I want to get the neighbors of the cell i,j with a given distance d . So if I run neighbors(im, i, j, d=1) with i = 1 and j = 1 (element value = 5) I should get the indices of the following values: [1,2,3,4,6,7,8,9] . I hope I make it

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

房东的猫 提交于 2019-11-27 02:58:46
问题 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

How To Rotate Image By Nearest Neighbor Interpolation Using Matlab

…衆ロ難τιáo~ 提交于 2019-11-27 02:50:32
问题 My Plain Code without interpolation: im1 = imread('lena.jpg');imshow(im1); [m,n,p]=size(im1); thet = rand(1); m1=m*cos(thet)+n*sin(thet); n1=m*sin(thet)+n*cos(thet); for i=1:m for j=1:n t = uint16((i-m/2)*cos(thet)-(j-n/2)*sin(thet)+m1/2); s = uint16((i-m/2)*sin(thet)+(j-n/2)*cos(thet)+n1/2); if t~=0 && s~=0 im2(t,s,:)=im1(i,j,:); end end end figure; imshow(im2); This code creates black spot, the problem is how to do interpolation? Thank you all for any illumination. P.S. Not asking for build

Suitable choice of data structure and algorithm for fast k-Nearest Neighbor search in 2D

こ雲淡風輕ζ 提交于 2019-11-27 01:52:37
问题 I have a dataset of approximately 100,000 (X, Y) pairs representing points in 2D space. For each point, I want to find its k-nearest neighbors. So, my question is - what data-structure / algorithm would be a suitable choice, assuming I want to absolutely minimise the overall running time? I'm not looking for code - just a pointer towards a suitable approach. I'm a bit daunted by the range of choices that seem relevent - quad-trees, R-trees, kd-trees, etc. I'm thinking the best approach is to

All k nearest neighbors in 2D, C++

扶醉桌前 提交于 2019-11-26 20:45:36
问题 I need to find for each point of the data set all its nearest neighbors. The data set contains approx. 10 million 2D points. The data are close to the grid, but do not form a precise grid... This option excludes (in my opinion) the use of KD Trees, where the basic assumption is no points have same x coordinate and y coordinate. I need a fast algorithm O(n) or better (but not too difficult for implementation :-)) ) to solve this problem ... Due to the fact that boost is not standardized, I do

Comparison of the runtime of Nearest Neighbor queries on different data structures

半城伤御伤魂 提交于 2019-11-26 18:36:28
问题 Given n points in d-dimensional space, there are several data structures, such as Kd-Trees, Quadtrees, etc. to index the points. On these data structures it is possible to implement straight-forward algorithm for nearest neighbor queries around a given input point. Is there a book, paper, survey, ... that compares the theoretical (mostly expected) runtime of the nearest neighbor query on different data structures? The data I am looking at is composed of fairly small point clouds, so it can

Nearest-neighbor interpolation algorithm in MATLAB

巧了我就是萌 提交于 2019-11-26 17:45:19
I am trying to write my own function for scaling up an input image by using the Nearest-neighbor interpolation algorithm. The bad part is I am able to see how it works but cannot find the algorithm itself. I will be grateful for any help. Here's what I tried for scaling up the input image by a factor of 2: function output = nearest(input) [x,y]=size(input); output = repmat(uint8(0),x*2,y*2); [newwidth,newheight]=size(output); for i=1:y for j=1:x xloc = round ((j * (newwidth+1)) / (x+1)); yloc = round ((i * (newheight+1)) / (y+1)); output(xloc,yloc) = input(j,i); end end Here is the output