distance

Parallel construction of a distance matrix

坚强是说给别人听的谎言 提交于 2019-12-14 04:28:05
问题 I work on hierarchical agglomerative clustering on large amounts of multidimensional vectors, and I noticed that the biggest bottleneck is the construction of the distance matrix. A naive implementation for this task is the following (here in Python): ''' v = an array (N,d), where rows are the observations and columns the dimensions''' def create_dist_matrix(v): N = v.shape[0] D = np.zeros((N,N)) for i in range(N): for j in range(i+1): D[i,j] = cosine(v[i,:],v[j,:]) # scipy.spatial.distance

Does a function like dist/rdist exist which handles NAs?

烂漫一生 提交于 2019-12-14 02:40:14
问题 I'm using rdist function from fields package, but now I want to handle NAs in my matrix, like the dist function does. There exist such a function? One solution would be to use dist directly, but my matrix has over 150K rows, so this is not an option. Edit: Note than removing rows or columns with complete.cases or na.omit is not the solution I'm looking for. The intended behaviour is described in the help dist function: Missing values are allowed, and are excluded from all computations

What formula to use to calculate a small distance

被刻印的时光 ゝ 提交于 2019-12-14 01:45:42
问题 Hy! I need to calculate the distance between 2 GPS Points. I read this question Formulas to Calculate Geo Proximity but i my english is too bad. My Problem is that the 2 points are at most 1 km away. I need the most excatly formula because of the small distance A example in PHP or pseudo code would be great 回答1: See this page. It contains great-circle distance calculation functions for various programming languages. In PHP: function getDistance($latitude1, $longitude1, $latitude2, $longitude2

Google Distance Matrix ZERO_RESULTS returned

点点圈 提交于 2019-12-14 01:23:38
问题 Preface I've been working with the Google Maps API for quite some time, previously being able to successfully use the Distance Matrix service here. Then I decided to do some refactoring and issues arose... Current Issue When trying to get the results of the Distance Matrix service, the rows object contains an empty ( status: ZERO_RESULTS ) array of objects. The empty object during runtime below: Normally it would look like this below: The code An array of coords gets passed into the

Biggest diameter of a set with a distance function

老子叫甜甜 提交于 2019-12-13 20:06:21
问题 I have a set of elements with a distance function between elements satisfying the triangle inequality. I want to find the pair of elements separated by the greatest distance. Is there any known solution better than trying all pairs? 回答1: If you measure the distance from point a to points b, c and d, and you find that |ab| + |ac| < |ad|, then you know that |bc| is shorter than |ad|, and there's no need to measure |bc|. So not all pairs need to be checked to find the longest distance. A

Finding the nearest distances between a vector of points and a polygon in R

孤街醉人 提交于 2019-12-13 16:16:18
问题 I have a data frame of lat/long coordinates and a polygon, which represents a coastline. I am trying to find the distance between each point and the nearest coastline feature. I would like to end up with an output data frame that includes columns for my original lat/long values and a new distance column. I have attempted to use the gDistance function after reading answers to similar questions online, but I think that I am missing a few steps and am having trouble figuring it out. At present,

Python - how to speed up calculation of distances between cities

∥☆過路亽.° 提交于 2019-12-13 11:51:27
问题 I have 55249 cities in my database. Every single one has got latitude longitude values. For every city I want to calculate distances to every other city and store those that are no further than 30km. Here is my algorithm: # distance function from math import sin, cos, sqrt, atan2, radians def distance(obj1, obj2): lat1 = radians(obj1.latitude) lon1 = radians(obj1.longitude) lat2 = radians(obj2.latitude) lon2 = radians(obj2.longitude) dlon = lon2 - lon1 dlat = lat2 - lat1 a = (sin(dlat/2))**2

Haversine Fomula with MySQL get nearby locations [closed]

这一生的挚爱 提交于 2019-12-13 11:17:32
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm trying to use the haversine formula in my PHP/MySQL to get nearby locations to where I am I'm using AJAX to get only nearby markers on my google map. What I know is that my query isn't returning anything. I know that there is a location within the distance of where I'm looking. Basically, what's wrong with

JavaScript Closest point from mouse

纵饮孤独 提交于 2019-12-13 09:54:02
问题 Before you comment, yes i have checked other questions aswell... like this article, or this one, or maybe even this one. However, i couldn't find how to set the point of origin. So, let's say i have an array picture X coords and picture Y coords (on a grid of 100*100) x /y 92/81 82/47 81/03 Now i have the mouseX and mouseY. Does anyone know how to make a function that gives you the closest point x and y values in JavaScript? Thanks in advance! 回答1: Just do some vecor math. Given the images

How to compute big geographic distance matrix

醉酒当歌 提交于 2019-12-13 07:24:32
问题 I have a dataframe of ids and coordinates. I need to calculate the geographic distance between all my ids, drop the ones that are too far from each other, and then go on with my analysis. I have 30k ids, which would generate a 30k x 30k matrix. Here is a sample: latitude longitude id -23.52472 -46.47785 917_62346 -23.62010 -46.69345 244_42975 -23.61636 -46.48148 302_75289 -23.53826 -46.46756 917_96304 -23.58266 -46.54495 302_84126 -23.47005 -46.70921 233_97098 -23.49235 -46.49342 917_62953