All Questions

Filter by
Sorted by
Tagged with
41 votes
4 answers
35k views

Vector Space Model: Cosine Similarity vs Euclidean Distance

I have corpora of classified text. From these I create vectors. Each vector corresponds to one document. Vector components are word weights in this document computed as TFIDF values. Next I build a ...
Anton Ashanin's user avatar
13 votes
2 answers
5k views

Efficiently compute pairwise squared Euclidean distance in Matlab

Given two sets of d-dimensional points. How can I most efficiently compute the pairwise squared euclidean distance matrix in Matlab? Notation: Set one is given by a (numA,d)-matrix A and set two is ...
matheburg's user avatar
  • 2,120
6 votes
5 answers
16k views

How to calculate Euclidean length of a matrix without loops?

It seems like the answer to this should be simple, but I am stumped. I have a matrix of Nx3 matrix where there 1st 2nd and 3rd columns are the X Y and Z coordinates of the nth item. I want to ...
Miebster's user avatar
  • 2,405
6 votes
2 answers
5k views

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

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 ...
DKangeyan's user avatar
  • 533
5 votes
5 answers
14k views

Calculating distance between two points in 3D

My assignment is to create main class in which I initialize the value of any point to be at (0,0,0) and to be able to access and mutate all three values (x,y,z) individually. To do this I have used ...
Idan Gelber's user avatar
5 votes
7 answers
419 views

Find a shortest distance between two buckets of numbers

I have two buckets (unordered, 1-dimentional data structures) of numbers and I want to calculate a minimal distance between any elements of the two buckets. Is there a way to find the shortest ...
oleksii's user avatar
  • 35.7k
5 votes
2 answers
3k views

r distance between rows

I apologize this is my attempt at redeeming myself after a disastrous earlier attempt . Now I have a bit more clarity. So here I go again. My goal is to find rows that are similar. So first I am ...
Emily Fassbender's user avatar
4 votes
1 answer
131 views

Wrong Euclidean distance H2O calculations R

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),...
Jesus's user avatar
  • 462
3 votes
3 answers
3k views

Distance between points on haskell

im new to haskell and i have to do a function that takes a list and calculates the distance recursively. For example: distance [(0,0),(2,0),(2,5)] ->7 distance [(1,1),(3,4)] ->3.6055512 I ...
John's user avatar
  • 45
3 votes
1 answer
3k views

Calculate euclidean distance in a faster way

I want to calculate the euclidean distances between rows of a dataframe with 30.000 observations. A simple way to do this is the dist function (e.g., dist(data)). However, since my dataframe is large, ...
Joachim Schork's user avatar
3 votes
2 answers
228 views

How to get m pair of points among n points that have the largest distance between them

Say I have the following points defined in a one dimensional space: x = np.array([[0.70710678], [0.70710678], [0. ], [1.41421356]]) I want to get m pair ...
Alejandro's user avatar
  • 899
3 votes
2 answers
2k views

fastest way to get closest 10 euclidean neighbors of large feature vector in python

I have a numpy array that has 10,000 vectors with 3,000 elements in each. I want to return the top 10 indices of the closest pairs with the distance between them. So if row 5 and row 7 have the ...
Mike El Jackson's user avatar
3 votes
0 answers
109 views

Distance Metric different units

I am trying to cluster a radar database. The observations of a radar are given in Azimuth angle and range. For processing speed reasons I do not want to transform this polar data into a Cartesian ...
Metz's user avatar
  • 73
2 votes
2 answers
227 views

Compute the difference matrix between a matrix and another matrix in MATLAB

Given a matrix A in matlab with: 3 1 4 5 7 8 and another matrix B which could be referred to as some reference points (each row is reference point that is to be compared to each row of A), 1 ...
Jesujoba Oluwadara ALABI's user avatar
2 votes
2 answers
3k views

How can I return coordinates inside a radius in pure PHP? (without MySQL)

I've been doing this in MySQL for years, but how can I do this in PHP? Example CoordinateArray: http://pastebin.com/grVsbgL9 I'd like to return all the coordinates within 100 miles of a given ...
Ryan's user avatar
  • 15k
2 votes
1 answer
3k views

Distance metrics in Scikit Learn

I was looking at some of the distance metrics implemented for pairwise distances in Scikit Learn. They include ‘cityblock’ ‘euclidean’ ‘l1’ ‘l2’ ‘manhattan’ Now I always assumed (based e.g. on here ...
patrick's user avatar
  • 4,643
2 votes
1 answer
895 views

Calculate distance matrix for 3D points

I have the lists xA, yA, zA and the lists xB, yB, zB in Matlab. The contain the the x,y and z coordinates of points of type A and type B. There may be different numbers of type A and type B points. I ...
EXIT_FAILURE's user avatar
2 votes
4 answers
5k views

Find shortest distance between multiple points

Imagine a small dataset of xy coordinates. These points are grouped by a variable called indexR, there are 3 groups in total. All xy coordinates are in the same units. The data looks approximately ...
Quinn's user avatar
  • 419
2 votes
2 answers
1k views

Find which points are within a given distance of each point

I have a dataframe that has a list of places and their geographical locations in UTM (Universal Transverse Mercator) coordinates. It looks something like this: Place X_UTM Y_UTM 1 574262.0 ...
Leandro Zipitria's user avatar
2 votes
1 answer
3k views

Fastest way to calculate Euclidean and Minkowski distance between all the vectors in a list of lists python

I have been trying for a while now to calculate the Euclidean and Minkowski distance between all the vectors in a list of lists. I don't have much advanced mathematical knowledge. I am usually ...
Gidon's user avatar
  • 21
2 votes
1 answer
383 views

Finding the 10 nearest points in 3D Euclidean space, for EACH element in a 5-million element catalog

Suppose I have a catalog of 5 million points, with their x,y,z location in 3D space. For EACH of these 5 million points, I want to find the 10 points closest to it (straightforward 3D Euclidean ...
quantumflash's user avatar
2 votes
1 answer
3k views

Calculate the minimum distance between two given circular arcs

I'm trying to find a way to calculate the minimum distance between two given circular arcs. I found a solution in this link. It seems true but I don't know why that is correct!Can anyone prove it ...
sani's user avatar
  • 23
2 votes
2 answers
4k views

Hausdorff Distance between Points of two meshes

I have to implement the Hausdorff distance for 2 meshes. The meshes are different segmentation results of an human organ and I have to compare them, one mesh is a gold seg. and the second one the ...
toobee's user avatar
  • 2,682
2 votes
2 answers
387 views

For each element A[i] of array A, find the closest j such that A[j] > A[i]

Given : An array A[1..n] of real numbers. Goal : An array D[1..n] such that D[i] = min{ distance(i,j) : A[j] > A[i] } or some default value (like 0) when there is no higher-valued element. I ...
SamH's user avatar
  • 95
2 votes
1 answer
980 views

R: distance between point and line in n-dimensions

I'd like to calculate the distance between a point and a line in any number (i.e., n) of dimensions. An excellent example for 2- and 3- dimensions is found here. Is there a way to generalize this ...
Ken Thompson's user avatar
1 vote
1 answer
4k views

R: pairwise Euclidean distance between columns of two matrices

The following loop takes too lonng to run (2mins/iteration) The tumor_signals is size 950000x422 The normal_signals is size 950000x772 Any ideas for how to speed it up? for(i in 1:ncol(tumor_signals))...
Cal Philic's user avatar
1 vote
1 answer
4k views

Find distance between two points using MKMapKit

I'm attempting to find the euclidean distance in meters between two points on an MKMapView using iPhone OS 3.2. The problem is that I have these coordinates in terms of latitude and longitude, which, ...
mag725's user avatar
  • 695
1 vote
4 answers
6k views

Get closest point based on coordinates

I'd like to snap single points to other points based on their distance in R. In detail, I have a bunch of points defined by X and Y coordinate pairs. In addition I have single different points, that I ...
Johannes's user avatar
  • 1,034
1 vote
1 answer
274 views

The distance from center of the binary image to the furthest point of the contour [closed]

The main idea is to find the furthest point coordinates of the contour from the center of the image in Python. Normally it is possible to find the extreme points of the contour using findcontours and ...
Miro's user avatar
  • 13
1 vote
3 answers
281 views

If/else if: pick first matching record within set distance only after first condition is not met in R

I would like to pick the closest previous owner within a set distance only after the first search condition isn't met. The locations are called reflo (reference location), and they have a ...
Blundering Ecologist's user avatar
1 vote
1 answer
3k views

Finding shortest distance between a point and a line segment

I need to find the shortest distance between a point and a line segment (point defined as x y, line defined using endpoints ax ay and bx by). I have written some code but it doesn't seem to work for ...
386blastprocessing's user avatar
1 vote
2 answers
3k views

SAS: Calculating average (Euclidean) distance from each customer to all other customers in table

I have a SAS dataset of 60k customers with the following attributes: 1) customer number 2) X coordinate 3) Y coordinate 4) store visits I need to calculate the average weighted distance from each ...
Adam L's user avatar
  • 11
1 vote
1 answer
34 views

Determine the next point 2D after some distance from initial point

Hi I'm creating a simple program to create create lines. When the user is drawing a line, first he needs to draw the first point *ignore '5cm' information for above image The second point (mouse ...
Lucas Moura's user avatar
1 vote
1 answer
1k views

Calculate euclidean distance between multiple vectors in R

I'm trying to calculate the euclidean distances between one vector on the one hand and multiple vectors on the other hand using R. So far, I've been following this documentation https://cran.r-project....
MSC's user avatar
  • 23
1 vote
4 answers
2k views

Find the index of points closest to each other in a list

I have been having trouble implementing the function in order to find the closest point, I've tried multiple ways of doing it but I just can't seem to figure it out. Any ideas on how I should go about ...
user avatar
1 vote
2 answers
565 views

distance measure used to calculate k nearest neighbour

I am reading about k nearest neighbour, and the distance measure given in the example is as below. It says Ri is the range of the i-th component. I am confused about which distance measure is used ...
user4046073's user avatar
1 vote
1 answer
589 views

How can I create a boxplot of within-group euclidian distances for grouped data?

Example data: set.seed(1234) a <- matrix(rnorm(250),nrow=25,ncol=10) fac <- as.factor(c(rep("A",8),rep("B",10),rep("C",7))) a.dist <- dist(a, "euclidian") boxplot(a.dist ~ fac) When I try ...
Antsushi's user avatar
  • 177
1 vote
1 answer
373 views

I can't figure out how to find the Euclidean distance within a single dataframe

Here is the data I am working with: rdata <- data.frame(x = c(1, 2, 3, 4, 5), y=c(10, 12, 15, 19, 24)) ext <- rdist::rdist(rdata) View(ext) When I run this code, I receive the following ...
Paul Ibrahim's user avatar
1 vote
2 answers
380 views

Find lowest distances between rows of a large matrix: Allocation limit error

I want to calculate the distances between all rows of a large matrix. For each row, I need to find another row, which has the lowest distance. The final output should be a list, containing of IDs of ...
Joachim Schork's user avatar
1 vote
1 answer
1k views

R function to calculate nearest neighbor distance given [inconsistent] constraint?

I have data consisting of tree growth measurements (diameter and height) for trees at known X & Y coordinates. I'd like to determine the distance to each tree's nearest neighbor of equal or ...
theforestecologist's user avatar
1 vote
1 answer
375 views

Distance from point to box boundary

In a game I'm writing with Pygame, I have a 2D point (x,y) in a box from (0,0) to (1,1) (perfect square with side length 1). I want to calculate the euclidean distance from the point to the box ...
Sagi Shadur's user avatar
1 vote
1 answer
233 views

R using rdist to generate results in a data table

I am trying to speed up a calculation involving a distance matrix. The following code snippet works in the script it came from, but is slow. It selects a particular country, year, and scenario ...
JerryN's user avatar
  • 2,456
1 vote
2 answers
388 views

Average xy points with conditional distance

I have xy coordinates of points and I want to make use distance for averaging points. My data is named qq and I obtain the distance matrix using dist function qq X Y 2 4237.5 4411.5 3 ...
Matias Andina's user avatar
1 vote
1 answer
2k views

Get distances between boundaries from an SpatialPolygon and raster pixels

I am trying to calculate the distance from several pixels of a raster to a boundary of some polygons in R as it is showed in the image. I have two problems: How to correctly define a boundary from a ...
topcat's user avatar
  • 586
1 vote
1 answer
563 views

How to calculate the distance between points and a fixed location in R Studio

I have a data frame containing thousands of rows about houses. For each row, there are two columns with the longitude and the latitude of this geographical point. My aim is to calculate the distance ...
Arthur Lo's user avatar
1 vote
3 answers
1k views

how to calculate Manhattan distance (or L1/ cityblock) for two 2D array?

For 1D vector/array it's easier. For example: array1 = [1, 2, 3] array2 = [1, 1, 1] manhattan distance will be: (0+1+2) which is 3 import numpy as np def cityblock_distance(A, B): result = np....
neo's user avatar
  • 37
1 vote
1 answer
209 views

Alternative to gDistance and how to compute travel distance instead euclidean

I have two questions, first one; I have two different points data frame in a network, let's say position of stores and position of crimes. I want to compute distance matrix and want to see which ...
iHermes's user avatar
  • 314
1 vote
0 answers
617 views

Ellipse distance metric for DBSCAN clustering

I am using the DBSCAN algorithm to determine clusters in a data set obtained by an automotive radar. The paper "Grid-Based DBSCAN for Clustering Extended Objects in Radar Data" from Dominik Kellner, ...
Metz's user avatar
  • 73
1 vote
0 answers
70 views

Which distance measurement fits best for features that have very different value ranges?

I have given record with different features. In total I have 8 features. Some are binary, but some have a value range from 0 to 10 million. My big goal is to cluster the data. At the moment I am still ...
piku's user avatar
  • 21
1 vote
0 answers
139 views

How to calc the similarity of two images

I'm trying to examine two images for similarity with the usage of SIFT. The result should be a percentage. I have understood how to extract the features and descriptors from the images using OpenCV ...
kopsman's user avatar
  • 67