Init from given files
This commit is contained in:
33
examples/js/distances/euclideanDistanceInTSNE.js
Normal file
33
examples/js/distances/euclideanDistanceInTSNE.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Calculate the distances by using the numbers, strings and dates.
|
||||
* @param {node} source
|
||||
* @param {node} target
|
||||
* @param {array} properties - the properties of the nodes.
|
||||
* @return {number} the distance between source and target nodes.
|
||||
*/
|
||||
function calculateEuclideanDistanceTSNE(source, target, properties, normArgs) {
|
||||
var dotProduct = 0.0,
|
||||
sumX = 0.0,
|
||||
sumY = 0.0;
|
||||
|
||||
// console.log(normArgs);
|
||||
// Iterate through every column of data
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
property = properties[i];
|
||||
if (source.hasOwnProperty(property) && target.hasOwnProperty(property) &&
|
||||
property.toLowerCase() !== "class") {
|
||||
var s = source[property],
|
||||
t = target[property];
|
||||
|
||||
dotProduct += s * t;
|
||||
|
||||
sumX += s * s;
|
||||
sumY += t * t;
|
||||
}
|
||||
}
|
||||
|
||||
// console.log("Dot", dotProduct);
|
||||
// console.log((-2 * dotProduct) + sumX + sumY);
|
||||
|
||||
return -2 * dotProduct + sumX + sumY;
|
||||
}
|
||||
Reference in New Issue
Block a user