Calculate the distance between two vectors of different lengths
There are different ways to calculate the distance between two vectors of the same length: Euclid, Manhattan, Hamming
I want to know any method that can calculate the distance between vectors of different lengths
Solution
Euclidean distance formula finds the distance between any two points in Euclidean space
A point in Euclidean space is also called Euclidean vector
You can use the Euclidean distance formula to calculate the distance between two vectors of different lengths
The same principle applies to vectors of different dimensions
It is assumed that lower dimensional vectors also exist in higher dimensional space You can then set all missing components in the lower dimension vector to 0 so that both vectors have the same dimension You will then use any of the above distance formulas to calculate the distance
For example, consider 2-dimensional vector a of components (A1, A2) in R 2 and 3-dimensional vector B with components (B1, B2, B3) in R 3
To express a in R, you can set its components to (A1, a2,0) Then, the Euclidean distance d between a and B can be expressed by the formula:
d² = (b1 - a1)² + (b2 - a2)² + (b3 - 0)² d = sqrt((b1 - a1)² + (b2 - a2)² + b3²)
For your specific case, the component will be 0 or 1, so all differences will be - 1,0 or 1 The square difference is only 0 or 1
If you use integers or single bits to represent components, you can use simple bitwise operations instead of some arithmetic (^ for XOR or exclude or):
d = sqrt(b1 ^ a1 + b2 ^ a2 + ... + b(n-1) ^ a(n-1) + b(n) ^ a(n))
We assume that the trailing component of a is 0, so the final formula is:
d = sqrt(b1 ^ a1 + b2 ^ a2 + ... + b(n-1) + b(n))