Created
November 12, 2014 18:09
-
-
Save spolu/306067f40f4684ff718b to your computer and use it in GitHub Desktop.
Similarity / Cosinus computation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var simil = related_top.map(function(rel_top) { | |
var product = rel_top.map(function(v, i) { | |
return v * hashtag_top[i]; | |
}).reduce(function(prev, curr) { | |
return prev + curr; | |
}); | |
var norm_x = Math.sqrt(rel_top.map(function(v, i) { | |
return v * v; | |
}).reduce(function(prev, curr) { | |
return prev + curr; | |
})); | |
var norm_y = Math.sqrt(hashtag_top.map(function(v, i) { | |
return v * v; | |
}).reduce(function(prev, curr) { | |
return prev + curr; | |
})); | |
return product / (norm_x * norm_y); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment