euclidean-distance

Euclidean Distance

隐身守侯 提交于 2019-12-11 05:04:18
问题 I have some problem understanding euclidean distance. I have two different entities and I want to measure the similarity between these entities. Lets suppose that entity A has 2 feature vectors and entity B has 1 feature vector only. How am I supposed to calculate the euclidean distance between these two entities in order to know the similarity? Thanks a lot. 回答1: you can calculate the eucledean distance only for vectors of the same dimension. But you could define some default values for the

How to select n objects from a set of N objects, maximizing the sum of pairwise distances between them

浪子不回头ぞ 提交于 2019-12-11 00:20:03
问题 You have a set of N=400 objects, each having its own coordinates in a, say, 19-dimensional space. You calculate the (Euclidean) distance matrix (all pairwise distances). Now you want to select n=50 objects, such that the sum of all pairwise distances between the selected objects is maximal. I devised a way to solve this by linear programming (code below, for a smaller example), but it seems inefficient to me, because I am using N*(N-1)/2 binary variables, corresponding to all the non

Pairwise Euclidean distance with pandas ignoring NaNs

情到浓时终转凉″ 提交于 2019-12-10 23:19:58
问题 I start with a dictionary, which is the way my data was already formatted: import pandas as pd dict2 = {'A': {'a':1.0, 'b':2.0, 'd':4.0}, 'B':{'a':2.0, 'c':2.0, 'd':5.0}, 'C':{'b':1.0,'c':2.0, 'd':4.0}} I then convert it to a pandas dataframe: df = pd.DataFrame(dict2) print(df) A B C a 1.0 2.0 NaN b 2.0 NaN 1.0 c NaN 2.0 2.0 d 4.0 5.0 4.0 Of course, I can get the difference one at a time by doing this: df['A'] - df['B'] Out[643]: a -1.0 b NaN c NaN d -1.0 dtype: float64 I figured out how to

Distance between points on haskell

假如想象 提交于 2019-12-10 19:14:21
问题 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 made the distance between just two points like this distance (x1 , y1) (x2 , y2) = sqrt (x'*x' + y'*y') where x' = x1 - x2 y' = y1 - y2 But dont know how do to it with a variable list size, thanks 回答1: We can rename this function to distance2 to specify that it calculates the distance between two points:

How to compare great circle distance with euclidean distance of two sphere points using python?

╄→尐↘猪︶ㄣ 提交于 2019-12-10 17:49:16
问题 I am trying to check the error that is introduced when you compute the distance of two points on earth with the euclidean distance instead of using the great circle distance (gcd). I have two points that are defined by their lattitude and longtitude. I used the python geopy framework for the great circle distance. Here the code for the gcd: def measure(self, a, b): a, b = Point(a), Point(b) lat1, lng1 = radians(degrees=a.latitude), radians(degrees=a.longitude) lat2, lng2 = radians(degrees=b

Euclidean distances (python3, sklearn): efficiently compute closest pairs and their corresponding distances

空扰寡人 提交于 2019-12-10 10:53:45
问题 I'm given a 2-D numpy array X consisting of floating values and need to compute the euclidean distances between all pairs of rows, then compute the top k row indices with the smallest distances and return them (where k > 0). I'm testing with a small array and this is what I have so far... import numpy as np from sklearn.metrics.pairwise import euclidean_distances X_testing = np.asarray([[1,2,3.5],[4,1,2],[0,0,2],[3.4,1,5.6]]) test = euclidean_distances(X_testing, X_testing) print(test) The

Caffe Iteration loss versus Train Net loss

戏子无情 提交于 2019-12-09 15:55:47
问题 I'm using caffe to train a CNN with a Euclidean loss layer at the bottom, and my solver.prototxt file configured to display every 100 iterations. I see something like this, Iteration 4400, loss = 0 I0805 11:10:16.976716 1936085760 solver.cpp:229] Train net output #0: loss = 2.92436 (* 1 = 2.92436 loss) I'm confused as to what the difference between the Iteration loss and Train net loss is. Usually the iteration loss is very small (around 0) and the Train net output loss is a bit larger. Can

Fastest way to calculate the distance between two CGPoints?

风流意气都作罢 提交于 2019-12-09 08:35:35
问题 Distance between two points: sqrt((x1-x2)^2 + (y1-y2)^2) Is there a way to do this math faster in objective-C ? EDIT: I think I need to clarify above. I wrote the formula above just to clarify what formula I am using to calculate the distance. ^ is not meant to represent xor - I just wanted to represent the mathematical formula without using any functions like pow or anything, so I meant to use ^ to "raise to the power off". I was wondering if anyone knows if using bitwise operators, or

Calculate the euclidean distance in scipy csr matrix

回眸只為那壹抹淺笑 提交于 2019-12-09 00:46:45
问题 I need to calculate the Euclidean Distance between all points that is stored in csr sparse matrix and some lists of points. It would be easier for me to convert the csr to a dense one, but I couldn't due to the lack of memory, so I need to keep it as csr. So for example I have this data_csr sparse matrix (view in both, csr and dense): data_csr (0, 2) 4 (1, 0) 1 (1, 4) 2 (2, 0) 2 (2, 3) 1 (3, 5) 1 (4, 0) 4 (4, 2) 3 (4, 3) 2 data_csr.todense() [[0, 0, 4, 0, 0, 0] [1, 0, 0, 0, 2, 0] [2, 0, 0, 1,

Fastest way to calculate Euclidean distance in c

谁说胖子不能爱 提交于 2019-12-08 21:37:46
问题 I need to calculate euclidean distance between two points in the fastest way possible. In C. My code is this and seems a little bit slow: float distance(int py, int px, int jy, int jx){ return sqrtf((float)((px)*(px)+(py)*(py))); } Thanks in advance. EDIT: I'm sorry I hadn't been clear. I'd better specify the context: I'm working with images and I need the euclidean distance from each pixel to all the other pixels. So I have to calculate it a lot of times. I can't use the square of the