euclidean-distance

Calculate squared Euclidean distance matrix on GPU

隐身守侯 提交于 2019-12-04 13:35:18
问题 Let p be a matrix of first set of locations where each row gives the coordinates of a particular point. Similarly, let q be a matrix of second set of locations where each row gives the coordinates of a particular point. Then formula for pairwise squared Euclidean distance is: k(i,j) = (p(i,:) - q(j,:))*(p(i,:) - q(j,:))', where p(i,:) denotes i -th row of matrix p , and p' denotes the transpose of p . I would like to compute matrix k on CUDA-enabled GPU (NVidia Tesla) in C++. I have OpenCV v

Euclidean Minimum Spanning Tree Without Triangulation

爱⌒轻易说出口 提交于 2019-12-04 05:51:20
问题 I was looking through some text about finding the EMST (Euclidean MST) using Delaunay triangulation technique, but also read somewhere that the EMST can be found through a sweep line algorithm. Since this would easier implementing, I would like to implement this rather than using a existing library. Can anyone guide me/ direct me to a link to a (possibly free) paper/source that has this algorithm explained? 回答1: From this and going by the abstracts, this and this should get you started. They

Wrong Euclidean distance H2O calculations R

老子叫甜甜 提交于 2019-12-04 03:37:11
问题 I am using H2O with R to calculate the euclidean distance between 2 data.frames: set.seed(121) #create the data df1<-data.frame(matrix(rnorm(1000),ncol=10)) df2<-data.frame(matrix(rnorm(300),ncol=10)) #init h2o h2o.init() #transform to h2o df1.h<-as.h2o(df1) df2.h<-as.h2o(df2) if I use normal calculations, i.e. the first row: distance1<-sqrt(sum((df1[1,]-df2[1,])^2)) And If I use the H2O library: distance.h2o<-h2o.distance(df1.h[1,],df2.h[1,],"l2") print(distance1) print(distance.h2o) The

Distance calculation between rows in Pandas Dataframe using a distance matrix

余生颓废 提交于 2019-12-04 02:48:23
I have the following Pandas DataFrame: In [31]: import pandas as pd sample = pd.DataFrame({'Sym1': ['a','a','a','d'],'Sym2':['a','c','b','b'],'Sym3':['a','c','b','d'],'Sym4':['b','b','b','a']},index=['Item1','Item2','Item3','Item4']) In [32]: print(sample) Out [32]: Sym1 Sym2 Sym3 Sym4 Item1 a a a b Item2 a c c b Item3 a b b b Item4 d b d a and I want to find the elegant way to get the distance between each Item according to this distance matrix: In [34]: DistMatrix = pd.DataFrame({'a': [0,0,0.67,1.34],'b':[0,0,0,0.67],'c':[0.67,0,0,0],'d':[1.34,0.67,0,0]},index=['a','b','c','d']) print

Calculate Euclidean distance between 4-dimensional vectors

谁都会走 提交于 2019-12-04 02:46:12
Let's say I have two 4-dimensional vectors (i.e. a and b) as follows: a = {a1, a2, a3, a4} b= {b1, b2, b3, b4} How do I compute the Euclidean distance between these vectors? The euclidian distance calculus is independent of dimensions. In your case, the euclidian distance between a and b can be written as: d(a,b) = sqrt(sum_{i=1}^{4} (a[i] - b[i])^2). Or, more specifically: d(a,b) = sqrt( (a1-b1)^2 + (a2-b2)^2 + (a3-b3)^2 + (a4-b4)^2 ). public static float ndistance(float[] a, float[] b) { float total = 0, diff; for (int i = 0; i < a.length; i++) { diff = b[i] - a[i]; total += diff * diff; }

MATLAB - efficient way of computing distances between points in a graph/network using the adjacency matrix and coordinates

半腔热情 提交于 2019-12-04 02:11:38
问题 I have the network representation in a 2D coordinate space. I have an adjacency matrix Adj (which is sparse) and a coordinate matrix with the x,y values of all the points/nodes/vertices in the graph which are drawn. I would like to compute as efficiently as possible the distance between these points. I would like to avoid cycling through the entries in the matrix and computing the pairwise distances one by one. 回答1: [n, d] = size(coordinate); assert(d == 2); resi = sparse(Adj * diag(1:n));

calculating the euclidean dist between each row of a dataframe with all other rows in another dataframe

跟風遠走 提交于 2019-12-04 00:54:09
问题 I need to generate a dataframe with minimum euclidean distance between each row of a dataframe and all other rows of another dataframe.Both my dataframes are large (approx 40,000 rows).This is what I could work out till now. x<-matrix(c(3,6,3,4,8),nrow=5,ncol=7,byrow = TRUE) y<-matrix(c(1,4,4,1,9),nrow=5,ncol=7,byrow = TRUE) sed.dist<-numeric(5) for (i in 1:(length(sed.dist))) { sed.dist[i]<-(sqrt(sum((y[i,1:7] - x[i,1:7])^2))) } But this only works when i=j.What I essentially need is to find

OpenCV euclidean distance between two vectors

只愿长相守 提交于 2019-12-03 13:23:08
I want to calculate the euclidean distance between two vectors (or two Matrx rows, doesn't matter). Is there a good function for that in OpenCV? yes. Mat a,b; // num of rows/cols/channels does not matter, they just have to be equal for both double dist = norm(a,b,NORM_L2); rafaoc Source: OpenCV, C++: Distance between two points Mat pts1(nPts, 1, CV_8UC2), pts2(nPts, 1, CV_8UC2); // populate them Mat diffPts = pts1-pts2; Mat ptsx, ptsy; // split your points in x and y vectors. maybe separate them from start Mat dist; magnitude(ptsx, ptsy, dist); // voila! Same for python : dist = cv2.norm(pts -

python numpy euclidean distance calculation between matrices of row vectors

血红的双手。 提交于 2019-12-03 11:13:01
问题 I am new to Numpy and I would like to ask you how to calculate euclidean distance between points stored in a vector. Let's assume that we have a numpy.array each row is a vector and a single numpy.array. I would like to know if it is possible to calculate the euclidean distance between all the points and this single point and store them in one numpy.array. Here is an interface: points #2d list of row-vectors singlePoint #one row-vector listOfDistances= procedure( points,singlePoint) Can we

Compare similarity algorithms

▼魔方 西西 提交于 2019-12-03 00:41:19
问题 I want to use string similarity functions to find corrupted data in my database. I came upon several of them: Jaro, Jaro-Winkler, Levenshtein, Euclidean and Q-gram, I wanted to know what is the difference between them and in what situations they work best? 回答1: Expanding on my wiki-walk comment in the errata and noting some of the ground-floor literature on the comparability of algorithms that apply to similar problem spaces, let's explore the applicability of these algorithms before we