0

I have a code for calculating euclidean distance like this :

for(int j=0;j<inputdimension;j++){
        distance += Math.pow((vector1[j] - vector2.get(j)), 2);
    }

and i've an example of data with different array size that i want to calculate with this euclidean distance function for those two array. for example :

vector1[] = {0.5,0.1,0.3,1.5}
vector2[] = {1.4,3.2,3.4,0.1,7.8,0.2,8.3,8.4}

So far i've encountered example for calculating the euclidean distance with the same array size. So i come up with a solution to remove the remaining array so they go balance like this for example :

vector1[] = {0.5,0.1,0.3,1.5}
vector2[] = {1.4,3.2,3.4,0.1}

The problem is, i dont know if its right or not? is there any other way to balance this data?

Idham Choudry
  • 589
  • 10
  • 31
  • I'm having a hard time interpreting what an 8 dimensional vector means. That said I think you should assume all vectors are the same as the largest length and their extra elements are all zero. – markspace Mar 29 '16 at 05:50
  • this array example i'm using is the example of sound signal that i've been processed using mfcc and i want to train it with LVQ method – Idham Choudry Mar 29 '16 at 06:13

1 Answers1

1

The answer is simple. You cannot find euclidean distance between two points which have different number of dimensions. If you eliminate remaining array like that, the answer would be unrealistic and inconsistent. However you can add zeros to smaller array, if this is a must for you. The result will be better, but it will be still unrealistic in my opinion.

P.S. You need to use Math.sqrt(distance) method after for loop.

Raptor
  • 187
  • 1
  • 2
  • 11