distance

Calculating distance between two points in 3D

此生再无相见时 提交于 2019-12-21 16:50:33
问题 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 getters and setters. My next task is to create a method within my main class (which I shall call "distanceTo") that calculates the distance between two points. How do I go about creating the method " distanceTo " that calculates the distance between two points by taking in the x,y,z coordinates ? I

How to use R to compute Tanimoto/Jacquard Score as distance matrix

旧巷老猫 提交于 2019-12-21 05:41:05
问题 I would like to calculate the distance matrix of the rows in an array in R using Tanimoto/Jacquard Score as distance matrix. Is it possible to be done? If yes, could you mind to teach me how to do it? 回答1: vegan package has a vegdist function that can calculate, among other things, the Jaccard index. Assuming that's what you're after. It's use is pretty straightforward. library(vegan) data(varespec) vare.dist <- vegdist(varespec, method = "jaccard") Other available methods are method

using k-NN in R with categorical values

人走茶凉 提交于 2019-12-21 05:12:16
问题 I'm looking to perform classification on data with mostly categorical features. For that purpose, Euclidean distance (or any other numerical assuming distance) doesn't fit. I'm looking for a kNN implementation for [R] where it is possible to select different distance methods, like Hamming distance. Is there a way to use common kNN implementations like the one in {class} with different distance metric functions? I'm using R 2.15 回答1: As long as you can calculate a distance/dissimilarity matrix

SQL Server 2008 R2 Geography Distance?

二次信任 提交于 2019-12-21 04:19:19
问题 I have created a table with the following columns: Text:varchar(255) Location:geography They contain a few city's from The Netherlands as data (got the coordinates from google maps): Rotterdam - POINT (51.925637 4.493408 4326) Utrecht - POINT (52.055868 5.103149 4326) Nijmegen - POINT (51.801822 5.828247 4326) Breda - POINT (51.542919 4.77356 4326) I want to know the distance between all city's in the DB from Rotterdam, so I perform this query: Select Text, Location, Location.STDistance

Cosine distance as vector distance function for k-means

醉酒当歌 提交于 2019-12-21 03:41:32
问题 I have a graph of N vertices where each vertex represents a place. Also I have vectors, one per user, each one of N coefficients where the coefficient's value is the duration in seconds spent at the corresponding place or 0 if that place was not visited. E.g. for the graph: the vector: v1 = {100, 50, 0 30, 0} would mean that we spent: 100secs at vertex 1 50secs at vertex 2 and 30secs at vertex 4 (vertices 3 & 5 where not visited, thus the 0s). I want to run a k-means clustering and I've

Is Triangle inequality necessary for kmeans?

你。 提交于 2019-12-21 02:44:34
问题 I wonder if Triangle inequality is necessary for the distance measure used in kmeans. 回答1: k-means is designed for Euclidean distance, which happens to satisfy triangle inequality. Using other distance functions is risky, as it may stop converging . The reason however is not the triangle inequality, but the mean might not minimize the distance function . (The arithmetic mean minimizes the sum-of-squares, not arbitrary distances!) There are faster methods for k-means that exploit the triangle

Efficiently finding the closest coordinate pair from a set in Python

一曲冷凌霜 提交于 2019-12-20 18:42:39
问题 The Problem Imagine I am stood in an airport. Given a geographic coordinate pair, how can one efficiently determine which airport I am stood in? Inputs A coordinate pair (x,y) representing the location I am stood at. A set of coordinate pairs [(a1,b1), (a2,b2)...] where each coordinate pair represents one airport. Desired Output A coordinate pair (a,b) from the set of airport coordinate pairs representing the closest airport to the point (x,y) . Inefficient Solution Here is my inefficient

Efficiently finding the closest coordinate pair from a set in Python

一个人想着一个人 提交于 2019-12-20 18:42:26
问题 The Problem Imagine I am stood in an airport. Given a geographic coordinate pair, how can one efficiently determine which airport I am stood in? Inputs A coordinate pair (x,y) representing the location I am stood at. A set of coordinate pairs [(a1,b1), (a2,b2)...] where each coordinate pair represents one airport. Desired Output A coordinate pair (a,b) from the set of airport coordinate pairs representing the closest airport to the point (x,y) . Inefficient Solution Here is my inefficient

Python calculate lots of distances quickly

大兔子大兔子 提交于 2019-12-20 14:01:43
问题 I have an input of 36,742 points which means if I wanted to calculate the lower triangle of a distance matrix (using the vincenty approximation) I would need to generate 36,742*36,741*0.5 = 1,349,974,563 distances. I want to keep the pair combinations which are within 50km of each other. My current set-up is as follows shops= [[id,lat,lon]...] def lower_triangle_mat(points): for i in range(len(shops)-1): for j in range(i+1,len(shops)): yield [shops[i],shops[j]] def return_stores_cutoff(points

2D Game: Fast(est) way to find x closest entities for another entity - huge amount of entities, highly dynamic

本秂侑毒 提交于 2019-12-20 10:44:03
问题 I'm working on a 2D game that has a huge amount of dynamic entities. For fun's sake, let's call them soldiers, and let's say there are 50000 of them (which I just randomly thought up, it might be much more or much less :)). All these soldiers are moving every frame according to rules - think boids / flocking / steering behaviour. For each soldier, to update it's movement I need the X soldiers that are closest to the one I'm processing. What would be the best spatial hierarchy to store them to