• Post Reply Bookmark Topic Watch Topic
  • New Topic

Euclidean distance calculation  RSS feed

 
nvayin agha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


I calculate the euclidean distance for two vector arr1, arr2 , then calculate it for X which is:
X={{arr1} ,{arr2}}. but ,
I have different results:

the code is :




 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, are you asking why the results are different?
 
nvayin agha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , I do not understand why they are not same ?
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're summing the square of the difference in calculateDistance but not in Euclideanorm.
 
nvayin agha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes , i realize that , how we can calculate euclidean distance in this case : data is 2D ??
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In "this" case meaning which of the two cases you have there?

You are already calculating distance correctly in your calculateDistance method; the other method I don't know whether it's correct because I don't know what it's supposed to do. It has no comments explaining its purpose and a name which doesn't mean anything to me.
 
nvayin agha
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@paul the second method euclideanorm is same euclidean distance but the data which i use with second method is 2D array , iam confused with it ?
 
Piet Souris
Master Rancher
Posts: 2044
75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi nvayin,

what you do in your method 'Euclideanorm' is to calculate the sum of all the elements, and returning the square root of that sum.
Now, I don't know what the mathematical meaning of this is.
But given a 2D array, you can calculate the distance between any two columns or any two rows, like you do in your 'calculateDistance' method.
 
Knute Snortum
Sheriff
Posts: 4281
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nvayin agha wrote:Yes , i realize that , how we can calculate euclidean distance in this case : data is 2D ??

Well, you don't really need the second for-loop. Use index [0] for one element and index [1] for the other.
 
Paul Clapham
Sheriff
Posts: 22832
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:Well, you don't really need the second for-loop. Use index [0] for one element and index [1] for the other.


I suppose that might be the meaning of that mysterious "Euclideanorm" thing. But we haven't been told that yet, even though several people have asked.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!