euclidean-distance

Example of increasing the work per thread in CUDA

点点圈 提交于 2019-11-27 17:58:43
问题 Algorithm : I'm writing a program with CUDA and the problem is the following: Two matrices A (n * 128) and B (m * 128) I take the first row of A, and I compute the distance between that vector and all the rows of B, one by one. I write the result of each distance on a row of a matrix C, so the element C(i,j) of C contains the distance between row i of A and row j of B. and I proceed with the next row of A. I've implemented it this way: I've got a grid made by ( n * m ) blocks, and 128 threads

R - How to get row & column subscripts of matched elements from a distance matrix

血红的双手。 提交于 2019-11-27 02:12:23
I have an integer vector vec1 and I am generating a distant matrix using dist function. I want to get the coordinates (row and column) of element of certain value in the distance matrix. Essentially I would like to get the pair of elements that are d-distant apart. For example: vec1 <- c(2,3,6,12,17) distMatrix <- dist(vec1) # 1 2 3 4 #2 1 #3 4 3 #4 10 9 6 #5 15 14 11 5 Say, I am interested in pair of elements in the vector that are 5 unit apart. I wanted to get the coordinate1 which are the rows and coordinate2 which are the columns of the distance matrix. In this toy example, I would expect

pdist2 equivalent in MATLAB version 7

情到浓时终转凉″ 提交于 2019-11-26 23:04:53
I need to calculate the euclidean distance between 2 matrices in matlab. Currently I am using bsxfun and calculating the distance as below( i am attaching a snippet of the code ): for i=1:4754 test_data=fea_test(i,:); d=sqrt(sum(bsxfun(@minus, test_data, fea_train).^2, 2)); end Size of fea_test is 4754x1024 and fea_train is 6800x1024 , using his for loop is causing the execution of the for to take approximately 12 minutes which I think is too high. Is there a way to calculate the euclidean distance between both the matrices faster? I was told that by removing unnecessary for loops I can reduce

Efficiently Calculating a Euclidean Distance Matrix Using Numpy

白昼怎懂夜的黑 提交于 2019-11-26 19:37:34
问题 I have a set of points in 2-dimensional space and need to calculate the distance from each point to each other point. I have a relatively small number of points, maybe at most 100. But since I need to do it often and rapidly in order to determine the relationships between these moving points, and since I'm aware that iterating through the points could be as bad as O(n^2) complexity, I'm looking for ways to take advantage of numpy's matrix magic (or scipy). As it stands in my code, the

pdist2 equivalent in MATLAB version 7

穿精又带淫゛_ 提交于 2019-11-26 09:14:00
问题 I need to calculate the euclidean distance between 2 matrices in matlab. Currently I am using bsxfun and calculating the distance as below( i am attaching a snippet of the code ): for i=1:4754 test_data=fea_test(i,:); d=sqrt(sum(bsxfun(@minus, test_data, fea_train).^2, 2)); end Size of fea_test is 4754x1024 and fea_train is 6800x1024 , using his for loop is causing the execution of the for to take approximately 12 minutes which I think is too high. Is there a way to calculate the euclidean

R - How to get row & column subscripts of matched elements from a distance matrix

拈花ヽ惹草 提交于 2019-11-26 08:36:24
问题 I have an integer vector vec1 and I am generating a distant matrix using dist function. I want to get the coordinates (row and column) of element of certain value in the distance matrix. Essentially I would like to get the pair of elements that are d-distant apart. For example: vec1 <- c(2,3,6,12,17) distMatrix <- dist(vec1) # 1 2 3 4 #2 1 #3 4 3 #4 10 9 6 #5 15 14 11 5 Say, I am interested in pair of elements in the vector that are 5 unit apart. I wanted to get the coordinate1 which are the

Minimum Euclidean distance between points in two different Numpy arrays, not within

只愿长相守 提交于 2019-11-26 06:21:48
问题 I have two arrays of x - y coordinates, and I would like to find the minimum Euclidean distance between each point in one array with all the points in the other array. The arrays are not necessarily the same size. For example: xy1=numpy.array( [[ 243, 3173], [ 525, 2997]]) xy2=numpy.array( [[ 682, 2644], [ 277, 2651], [ 396, 2640]]) My current method loops through each coordinate xy in xy1 and calculates the distances between that coordinate and the other coordinates. mindist=numpy.zeros(len

How can the Euclidean distance be calculated with NumPy?

…衆ロ難τιáo~ 提交于 2019-11-26 03:13:49
问题 I have two points in 3D: (xa, ya, za) (xb, yb, zb) And I want to calculate the distance: dist = sqrt((xa-xb)^2 + (ya-yb)^2 + (za-zb)^2) What\'s the best way to do this with NumPy, or with Python in general? I have: a = numpy.array((xa ,ya, za)) b = numpy.array((xb, yb, zb)) 回答1: Use numpy.linalg.norm: dist = numpy.linalg.norm(a-b) Theory Behind this: as found in Introduction to Data Mining This works because Euclidean distance is l2 norm and the default value of ord parameter in numpy.linalg