Files
d3-spring-model/examples/js/distances/euclideanDistanceInTSNE.js
2018-03-22 16:40:27 +00:00

34 lines
980 B
JavaScript

/**
* 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;
}