Java Snippet - variable does not stores elements of values

Dear All,

I'm using a Java Snippet node to calculate a Tanimoto similarity for continuous values of two vector objects, i.e. a and b.

The continuous calculation requires the summation of all elements in the vectors divided by magnitude of vector a added to the magnitude of vector b, minus the summation of all vectors.

Say if my vectors have 3 elements each, then for the final loop, the variable 'a' should stores the values for all 3 elements. That goes the same with variable 'b' and 'ab'.

However, I found out that the variables only store the last and the previous value of elements. Meaning, the second and the third. Looks like it excludes the first elements. 

I've embedded my codes below and appreciate if anyone can help me to figure out why. Is it the Java Snippet bug of is it my code? 

 

double a = 0.0;
double b = 0.0;
double ab = 0.0;
double result = 0.0;
Double [] result_array = new Double [vector_a.length];

for (int i = 0; i < vector.length; i++)
{
	a += Math.pow(vector_a[i],2);
	b += Math.pow(vector_b[i],2);
	ab += vector_a[i] * vector_b[i];
	result = ab / (a + b - ab);
	result_array[i] = result;
}

 

Thanks in advanced.

LM

Dear LM,

In this case I declare (double a= 0.0;) variable in "Global variable declaration", not in "methode body"

 

Hope it solve/help

MitchP

Dear Mitch,

 Did you mean put it at 'System Variable' section?

Hello LM

 

See attachment... does it help ?

;-)

Hi Mitch,

Thank you very much for your help and concern, the problem has been solved. There's actually nothing wrong with my code but apparently it is with my dataset. 

Thank you again anyway. You've been very much helpful.

LM