euclidean-distance

Matlab formula optimization: Radial Basis Function

空扰寡人 提交于 2019-11-29 10:50:34
z - matrix of doubles, size Nx2; x - matrix of doubles, size Nx2; sup = x(i, :); phi(1, i) = {@(z) exp(-g * sum((z - sup(ones([size(z, 1) 1]),:)) .^ 2, 2))}; this is a Radial Basis Function (RBF) for logistic regression. Here is the formula: I need your advice, can i optimize this formula? coz it calls millions times, and it takes a lot of time... It seems in your recent edits, you introduced some syntax errors, but I think I understood what you were trying to do (from the first version). Instead of using REPMAT or indexing to repeat the vector x(i,:) to match the rows of z , consider using

How to calculate Euclidian distance between two points defined by matrix containing x, y?

a 夏天 提交于 2019-11-29 07:03:03
I am very lost in Euclidean distance calculation . I have found functions dist2{SpatialTools} or rdist{fields} to do this, but they doesn´t work as expected. I suppose that one point has two coordinates in carthesian system, so [x,y]. To measure distance between 2 points (defined by row), I need 4 coordinates for 2 points, so point A: [x1,y1] point B: [x2,y2] Points coordinations: A[0,1] B[0,0] C[1,1] D[1,1] I have two matrices: x1 (A and C are there, defined by rows) and x2 (contain B and D). Written in matrix: library("SpatialTools") x1<-matrix(c(0,1,1,1), nrow = 2, ncol=2, byrow=TRUE) x2<

Example of increasing the work per thread in CUDA

浪尽此生 提交于 2019-11-29 03:58:46
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 per block. ( 1 * 128 ). QUESTION : The program runs successfully with the expected results but the

How do I create a simliarity matrix in MATLAB?

时光怂恿深爱的人放手 提交于 2019-11-28 14:15:20
I am working towards comparing multiple images. I have these image data as column vectors of a matrix called "images." I want to assess the similarity of images by first computing their Eucledian distance. I then want to create a matrix over which I can execute multiple random walks. Right now, my code is as follows: % clear % clc % close all % % load tea.mat; images = Input.X; M = zeros(size(images, 2), size (images, 2)); for i = 1:size(images, 2) for j = 1:size(images, 2) normImageTemp = sqrt((sum((images(:, i) - images(:, j))./256).^2)); %Need to accurately select the value of gamma_i gamma

Compute Euclidean distance between rows of two pandas dataframes

大城市里の小女人 提交于 2019-11-28 13:41:44
I have two pandas dataframes d1 and d2 that look like these: d1 looks like: output value1 value2 value2 1 100 103 87 1 201 97.5 88.9 1 144 54 85 d2 looks like: output value1 value2 value2 0 100 103 87 0 201 97.5 88.9 0 144 54 85 0 100 103 87 0 201 97.5 88.9 0 144 54 85 The column output has a value of 1 for all rows in d1 and 0 for all rows in d2. It's a grouping variable. I need to find euclidean distance between each rows of d1 and d2 (not within d1 or d2). If d1 has m rows and d2 has n rows, then the distance matrix will have m rows and n columns By using scipy.spatial.distance.cdist :

Finding euclidean distance in R{spatstat} between points, confined by an irregular polygon window

跟風遠走 提交于 2019-11-28 12:34:15
I'm trying to find the euclidean distance between two points, confined by an irregular polygon. (ie. the distance would have to be calculated as a route through the window given) Here is an reproducible example: library(spatstat) #Simple example of a polygon and points. ex.poly <- data.frame(x=c(0,5,5,2.5,0), y=c(0,0,5,2.5,5)) points <- data.frame(x=c(0.5, 2.5, 4.5), y=c(4,1,4)) bound <- owin(poly=data.frame(x=ex.poly$x, y=ex.poly$y)) test.ppp <- ppp(x=points$x, y=points$y, window=bound) pairdist.ppp(test.ppp)#distance between every point #The distance result from this function between point 1

What is the most efficient way to compute the square euclidean distance between N samples and clusters centroids?

被刻印的时光 ゝ 提交于 2019-11-28 09:08:52
问题 I am looking for an efficient way ( no for loops ) to compute the euclidean distance between a set of samples and a set of clusters centroids. Example: import numpy as np X = np.array([[1,2,3],[1, 1, 1],[0, 2, 0]]) y = np.array([[1,2,3], [0, 1, 0]]) Expected output: array([[ 0., 11.], [ 5., 2.], [10., 1.]]) This is the squared euclidean distance between each sample in X to each centroid in y. I came up with 2 solutions: Solution 1 : def dist_2(X,y): X_square_sum = np.sum(np.square(X), axis =

Matlab formula optimization: Radial Basis Function

喜夏-厌秋 提交于 2019-11-28 03:57:50
问题 z - matrix of doubles, size Nx2; x - matrix of doubles, size Nx2; sup = x(i, :); phi(1, i) = {@(z) exp(-g * sum((z - sup(ones([size(z, 1) 1]),:)) .^ 2, 2))}; this is a Radial Basis Function (RBF) for logistic regression. Here is the formula: I need your advice, can i optimize this formula? coz it calls millions times, and it takes a lot of time... 回答1: It seems in your recent edits, you introduced some syntax errors, but I think I understood what you were trying to do (from the first version)

How to calculate Euclidian distance between two points defined by matrix containing x, y?

China☆狼群 提交于 2019-11-28 00:34:07
问题 I am very lost in Euclidean distance calculation . I have found functions dist2{SpatialTools} or rdist{fields} to do this, but they doesn´t work as expected. I suppose that one point has two coordinates in carthesian system, so [x,y]. To measure distance between 2 points (defined by row), I need 4 coordinates for 2 points, so point A: [x1,y1] point B: [x2,y2] Points coordinations: A[0,1] B[0,0] C[1,1] D[1,1] I have two matrices: x1 (A and C are there, defined by rows) and x2 (contain B and D)

Efficiently Calculating a Euclidean Distance Matrix Using Numpy

冷暖自知 提交于 2019-11-27 18:51:52
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 coordinates of each object are stored in its class. However, I could also update them in a numpy array when I