Questions tagged [distance-matrix]

A distance matrix is a matrix containing the pairwise distances between the elements of a set. The "distance" may rely on the concept of metric.

The distance matrix for an N-elements set is a NxN matrix in which entry (i,j) contains the distance between items i and j.
The distance might be related to the concept of metric (e.g. Euclidean distance, Mahlanobis distance, and so on) but there are also non-metric distance matrices: an adjacency matrix is an example of such non-metric distance matrices.

174 questions
12
votes
1 answer

How to calculate pairwise distance matrix on the GPU

The bottleneck in my code is the area where I calculate a pairwise distance matrix. Since this is the slowest part by far, I have spent much time in speeding up my code. I have found many speedups using articles online, but the gains have been…
Paul Terwilliger
  • 1,596
  • 1
  • 20
  • 45
11
votes
1 answer

Example of increasing the work per thread in CUDA

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…
user3734420
10
votes
3 answers

How to compute the distance matrix in spark?

I have tried pairing the samples but it costs huge amount of memory as 100 samples leads to 9900 samples which is more costly. What could be the more effective way of computing distance matrix in distributed environment in spark Here is a snippet of…
Manoj Kondapaka
  • 101
  • 1
  • 5
7
votes
1 answer

Optimizing execution of a CUDA kernel for Triangular Matrix calculation

I am developing my first Cuda application, and I have a kernel with "below-expected throughput", which seems to be the biggest bottleneck at the moment. The task of the kernel is to compute an N by N sized matrix (DD) containing squared distances…
casparjespersen
  • 3,460
  • 5
  • 38
  • 63
7
votes
1 answer

How can I create a distance matrix containing the mean absolute scores between each row?

Given the matrix, df <- read.table(text=" X1 X2 X3 X4 X5 1 2 3 2 1 2 3 4 4 3 3 4 4 6 2 4 5 5 5 4 2 3 3 3 6 5 6 2 8 4", header=T) I want to create a distance matrix containing the absolute mean difference between…
Werner Hertzog
  • 2,002
  • 3
  • 24
  • 36
6
votes
2 answers

Creating a distance matrix from a list of coordinates in R

I have a csv file with a list of co-ordinate positions for over 2000 farms, with the following structure; FarmID | Latidue | Longitude | ------ |---------|-----------| 1 | y1 | x1 | 2 | y2 | x2 | 3 | y3 …
sruby52
  • 83
  • 1
  • 6
5
votes
0 answers

Gower distance on big data

I want to perform clustering on geographical data to classify types of landscape within my region. My data consist of five variables (temperature, amplitude of temperature, precipitation, altitude and soil type) for each field of regular grid. I…
5
votes
1 answer

Convert adjacency matrix to a distance or hop matrix

Is it possible to convert an adjacency matrix of ones and zeros as defined here into a distance matrix as defined here where each link would be of unit length 1?
pyCthon
  • 11,746
  • 20
  • 73
  • 135
4
votes
1 answer

Distance matrix for custom distance

From what I understand, the scipy function scipy.spatial.distance_matrix returns the Minkowski distance for any pair of vectors from the provided matrices of vectors. Is there a way to get the same result for a different distance? Something that…
usernumber
  • 1,958
  • 1
  • 21
  • 58
4
votes
1 answer

as.matrix on a distance object is extremely slow; how to make it faster?

I found an R package Rlof which uses multithreading to calculate distance matrices and it does a wonderful job. However, the output of the function distmc is a vector rather than a matrix. Applying as.matrix to this "dist" object turns out much more…
Omry Atia
  • 2,411
  • 2
  • 14
  • 27
4
votes
0 answers

vizualize distance matrix as network in R

I'm trying to find a way to visualize distance matrices as a network. I came across this answer to a similar question: https://stackoverflow.com/a/37832966/8767973 While very helpful, I don't have enough familiarity with R to know what the…
Haley Sapers
  • 103
  • 10
4
votes
1 answer

What is the complexity of dist()?

I used the dist function in R and I am wondering the time complexity of it. I know that the hierarchical clustering has a N^2*logN time complexity. And hierarchical clustering is composed of two parts as below codes in R. > d <-…
sclee1
  • 1,095
  • 1
  • 15
  • 36
4
votes
4 answers

Google Map distance-matrix api Serverside multiple address by latlong

In https://www.npmjs.com/package/google-distance-matrix example we can add multiple destincation as latlong pair, The server side code is like string Test =…
VISHMAY
  • 699
  • 5
  • 20
4
votes
2 answers

Extract diagonals from a distance matrix in R

I would like to know how can I extract the values of the first diagonal from a distance matrix. For example: > mymatrix [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 6 4 [4,] 8 6 > dist(mymatrix) 1 2 3 2…
pateto777
  • 249
  • 1
  • 11
3
votes
2 answers

Distance Map for every pixel in python

I need some help in implementing a distance map in Python. I have a binary Maze (1=walls, 0=free space) in numpy format in which I would like to implement a distance map which is outgoing from a certain point in the Maze. The distance maps shall not…
VincentWin
  • 31
  • 4
1
2 3
11 12