Questions tagged [pdist]

pdist computes pairwise distance between pairs of objects in m-by-n data matrix in MATLAB.

pdist computes Euclidean distance between pairs of objects in m-by-n data matrix in .

Syntax

D = pdist(X)
D = pdist(X,distance)

Where, X is m-by-n data matrix.

  1. In D = pdist(X), the calculated distance is Euclidean distance.
  2. In D = pdist(X,distance) , the method can be specified by distance, which can be any one of the following
'euclidean'  
'seuclidean'  
'cityblock'  
'minkowski'  
'chebychev'  
'mahalanobis'    
'cosine'  
'correlation'  
'spearman'  
'hamming'     
'jaccard'  

or any custom distance function of form d2 = distfun(XI,XJ)

You should use this tag if your question is related to the use of pdist or any custom distance functions associated with it.

48 questions
1
vote
1 answer

scipy pdist getting only two closest neighbors

I've been computing pairwise distances with scipy, and I am trying to get distances to two of the closest neighbors. My current working solution is: dists = squareform(pdist(xs.todense())) dists = np.sort(dists, axis=1)[:, 1:3] However, the…
sdgaw erzswer
  • 2,182
  • 2
  • 26
  • 45
1
vote
1 answer

train the network with matlab matconvnet

I want to train my network using matlab and matconvnet-1.0-beta25. My problem is regression and I use pdist as loss function to get mse. The inputs data is 56*56*64*6000 and the targets data is 56*56*64*6000 and network architecture is as…
user9218823
1
vote
1 answer

Mahalanobis Distance with a three variables vector

I'm having some trouble in calculating the Mahalanobis Distance between a pair of objects. I followed the documentation of MATLAB where in order to calculate Mahalanobis Distance, I have to use pdist2: "D = pdist2(X,Y,'mahalanobis',C)" A1=[75 87…
FL93
  • 29
  • 5
1
vote
2 answers

Python - Compute similarities between items based on temporal information (instant, interval)

I want to compute similarity between items (0,1,2,3..) based on their temporal information. Temporal information may be time instant (startdate), time interval (startdate,enddate) or null (NaT); see an example of dataframe (df_for)…
kitchenprinzessin
  • 1,023
  • 3
  • 14
  • 30
1
vote
1 answer

How to get the condensed form of pairwise distances directly?

I have a very large scipy sparse csr matrix. It is a 100,000x2,000,000 dimensional matrix. Let's call it X. Each row is a sample vector in a 2,000,000 dimensional space. I need to calculate the cosine distances between each pair of samples very…
JRun
  • 669
  • 1
  • 10
  • 17
1
vote
1 answer

MATLAB - passing parameters to pdist custom distance function

I've implemented a custom distance function for k-medoids algorithm in Matlab, following the directions found in pdist. Basically it compares two vectors, say A and B (which can also have different lengths) and checks if their elements "co-occur…
DanieleT
  • 13
  • 4
1
vote
1 answer

Different behaviour for pdist and pdist2

In a MATLAB code I am using the kullback_leibler_divergence dissimilarity function that can be found here. I have a matrix A and I compute the dissimilarity matrix using the downloaded function. In theory, if I calculate clear A = rand(132,6); %…
gabboshow
  • 5,359
  • 12
  • 48
  • 98
1
vote
1 answer

MATLAB use custom function with pdist

I have a custom function to calculate the weight between two pixels (that represent nodes on a graph) of an image function [weight] = getWeight(a,b,img, r, L) ac = num2cell(a); bc = num2cell(b); imgint1 = img(sub2ind(size(img),ac{:})); …
zeellos
  • 139
  • 11
1
vote
1 answer

python compute distance matrix from dictionary data

I want to compute a distance matrix from a dictionary data like the following: y = {"a": ndarray1, "b": ndarry2, "c": ndarry3} The value of each key ("a", "b", "c") is a np.ndarry with different size. And I have a dist() function that can compute…
Rain Lee
  • 511
  • 2
  • 6
  • 11
1
vote
0 answers

knn classifier with own distance function

I am using a Knn classifier in MATLAB. Here is my Code: load fisheriris x = meas(:,3:4); newpoint = [5 1.45]; [n,d] = knnsearch(x,newpoint,'k',10, 'Distance', 'euclidean'); Now I would like to use my own distance function. To be sure, that it is…
user2576458
  • 161
  • 3
  • 9
0
votes
1 answer

Euclidean distance and indicator from a large dataframe

I have a large Dataframe (189090, 8), I need to calculate Euclidean distance and the similarity. My approach: from scipy.spatial import KDTree from scipy.spatial.distance import pdist scaler = MinMaxScaler() scaled = scaler.fit_transform(ds) Y =…
0
votes
1 answer

What is the fastest way to generate a matrix for distances between location with lat and lon?

Thank you for reading this. Currently I have a lot of latitude and longitude for many locations, and I need to create a matrix of distances for locations within 10km. (It's okay to fill the matrix with 0 distances between locations far more than…
ddd
  • 37
  • 6
0
votes
0 answers

"could not convert string to float" when using pdist

I am new to python and I am trying to compute the condensed distance matrix of the elements from a dataframe column using pdist. This is what the data looks like and I want to use the "Sequence" column : In [90]: print(a_10) Sequence …
mantunes
  • 25
  • 5
0
votes
0 answers

how to calculate distance between points using pdist2 in Matlab

I am looking to find the distance between a set of points and the coordinates of a grid. x = 177136 x 1 y = 177136 x 1 I have the following query points to which I am trying to find the distance to x and y; xtrack = 1 x 1166 ytrack = 1 x 1166 I…
nico1234
  • 9
  • 8
0
votes
1 answer

Using Additional kwargs with a Custom Function for Scipy's cdist (or pdist)?

I am using a custom metric function with scipy's cdist function. The custom function is something like def cust_metric(u,v): dist = np.cumsum(np.gcd(u,v) * k) return dist where k is an arbitrary coefficient. Ideally, I was hoping to pass k as…
Sam m
  • 3
  • 1