Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate distance between two vectors of different length

There are different methods to calculate distance between two vectors of the same length: Euclidean, Manhattan, Hamming ...

I'm wondering about any method that would calculate distance between vectors of different length.

like image 774
user1155073 Avatar asked Feb 16 '12 16:02

user1155073


People also ask

Can you find the distance between two points in different dimensions?

Distance in One Dimension d(A,B)=∣x1​−x2​∣. In the plane, we can consider the x x x-axis as a one-dimensional number line, so we can compute the distance between any two points lying on the x x x-axis as the absolute value of the difference of their x x x-coordinates.

How do you find the distance between two different points?

The formula to find the distance between the two points is usually given by d=√((x2 – x1)² + (y2 – y1)²). This formula is used to find the distance between any two points on a coordinate plane or x-y plane.

What is the distance between the vectors u 1 and V?

The distance between u and v ∈ V is given by dist(u, v) = u − v. Example: • The Euclidean distance between to points x and y ∈ IR3 is x − y = √(x1 − y1)2 + (x2 − y2)2 + (x3 − y3)2. Theorem 1 Let V be a vector space and u, v ∈ V . Then, u + v = u − v ⇔ (u, v)=0.


2 Answers

The Euclidean distance formula finds the distance between any two points in Euclidean space.

A point in Euclidean space is also called a Euclidean vector.

You can use the Euclidean distance formula to calculate the distance between vectors of two different lengths.

For vectors of different dimension, the same principle applies.

Suppose a vector of lower dimension also exists in the higher dimensional space. You can then set all of the missing components in the lower dimensional vector to 0 so that both vectors have the same dimension. You would then use any of the mentioned distance formulas for computing the distance.

For example, consider a 2-dimensional vector A in with components (a1,a2), and a 3-dimensional vector B in with components (b1,b2,b3).

To express A in , you would set its components to (a1,a2,0). Then, the Euclidean distance d between A and B can be found using the formula:

d² = (b1 - a1)² + (b2 - a2)² + (b3 - 0)²

d = sqrt((b1 - a1)² + (b2 - a2)² + b3²)

For your particular case, the components will be either 0 or 1, so all differences will be -1, 0, or 1. The squared differences will then only be 0 or 1.

If you're using integers or individual bits to represent the components, you can use simple bitwise operations instead of some arithmetic (^ means XOR or exclusive or):

d = sqrt(b1 ^ a1 + b2 ^ a2 + ... + b(n-1) ^ a(n-1) + b(n) ^ a(n))

And we're assuming the trailing components of A are 0, so the final formula will be:

d = sqrt(b1 ^ a1 + b2 ^ a2 + ... + b(n-1) + b(n))
like image 81
ardnew Avatar answered Oct 15 '22 22:10

ardnew


You cannot directly compute distances between vectors of differing length.

All suggestions here start with a function that maps the lower-length vector to a higher-length one, then doing the calculation as normal.

There are many, many functions (infinitely many, in fact) that one can use:

  • Fill up with zeroes. It's the easiest thing to do. Say, if you have a car and need to compute its distance to an airplane, this places the car at sea level.
  • Look up the missing values somewhere. With the car-airplane example, you'd fire up your geo database and look up heights from longitude/latitude.
  • Use some mathematical function.

Since the result of the distance calculation strongly depends on the function that converts the shorter vector to the longer, everybody needs to be clear about what function is used. Either because everybody in the fields agrees that only one function makes sense, or because the function used in the conversion is noted down.

like image 41
toolforger Avatar answered Oct 15 '22 22:10

toolforger