แก้ coding style ภาค 10
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* Initialize the hybrid layout algorithm and start simulation.
|
* Initialize the hybrid layout algorithm and start simulation.
|
||||||
*/
|
*/
|
||||||
function startHybridSimulation() {
|
function startHybridSimulation () {
|
||||||
console.log("startHybridSimulation");
|
console.log('startHybridSimulation');
|
||||||
springForce = false;
|
springForce = false;
|
||||||
d3.selectAll(".nodes").remove();
|
d3.selectAll('.nodes').remove();
|
||||||
manualStop = false;
|
manualStop = false;
|
||||||
simulation.stop();
|
simulation.stop();
|
||||||
p1 = performance.now();
|
p1 = performance.now();
|
||||||
@@ -17,33 +17,33 @@ function startHybridSimulation() {
|
|||||||
.neighbourSize(NEIGHBOUR_SIZE)
|
.neighbourSize(NEIGHBOUR_SIZE)
|
||||||
.sampleSize(SAMPLE_SIZE)
|
.sampleSize(SAMPLE_SIZE)
|
||||||
.stableVelocity(0) // Change here
|
.stableVelocity(0) // Change here
|
||||||
.distance(distance)
|
.distance(distance);
|
||||||
|
|
||||||
let forceFull = d3.forceNeighbourSampling()
|
let forceFull = d3.forceNeighbourSampling()
|
||||||
.neighbourSize(FULL_NEIGHBOUR_SIZE)
|
.neighbourSize(FULL_NEIGHBOUR_SIZE)
|
||||||
.sampleSize(FULL_SAMPLE_SIZE)
|
.sampleSize(FULL_SAMPLE_SIZE)
|
||||||
.stableVelocity(0) // Change here
|
.stableVelocity(0) // Change here
|
||||||
.distance(distance)
|
.distance(distance);
|
||||||
|
|
||||||
let hybridSimulation = d3.hybridSimulation(simulation, forceSample, forceFull)
|
let hybridSimulation = d3.hybridSimulation(simulation, forceSample, forceFull)
|
||||||
.sampleIterations(ITERATIONS)
|
.sampleIterations(ITERATIONS)
|
||||||
.fullIterations(FULL_ITERATIONS)
|
.fullIterations(FULL_ITERATIONS)
|
||||||
.numPivots(PIVOTS ? NUM_PIVOTS:-1)
|
.numPivots(PIVOTS ? NUM_PIVOTS : -1)
|
||||||
.interpFindTuneIts(INTERP_ENDING_ITS)
|
.interpFindTuneIts(INTERP_ENDING_ITS)
|
||||||
.interpDistanceFn(distance)
|
.interpDistanceFn(distance)
|
||||||
.on("sampleTick", ticked)
|
.on('sampleTick', ticked)
|
||||||
.on("fullTick", ticked)
|
.on('fullTick', ticked)
|
||||||
.on("startInterp", startedFull)
|
.on('startInterp', startedFull)
|
||||||
.on("end", ended);
|
.on('end', ended);
|
||||||
|
|
||||||
let sample = hybridSimulation.subSet();
|
let sample = hybridSimulation.subSet();
|
||||||
addNodesToDOM(sample);
|
addNodesToDOM(sample);
|
||||||
|
|
||||||
hybridSimulation.restart();
|
hybridSimulation.restart();
|
||||||
|
|
||||||
function startedFull() {
|
function startedFull () {
|
||||||
console.log("startedFull");
|
console.log('startedFull');
|
||||||
d3.selectAll(".nodes").remove();
|
d3.selectAll('.nodes').remove();
|
||||||
addNodesToDOM(nodes);
|
addNodesToDOM(nodes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* Initialize the link force algorithm and start simulation.
|
* Initialize the link force algorithm and start simulation.
|
||||||
*/
|
*/
|
||||||
function startLinkSimulation() {
|
function startLinkSimulation () {
|
||||||
console.log("startLinkSimulation")
|
console.log('startLinkSimulation');
|
||||||
springForce = false;
|
springForce = false;
|
||||||
alreadyRanIterations = 0;
|
alreadyRanIterations = 0;
|
||||||
manualStop = true;
|
manualStop = true;
|
||||||
@@ -12,26 +12,25 @@ function startLinkSimulation() {
|
|||||||
|
|
||||||
if (tweakedVerOfLink) {
|
if (tweakedVerOfLink) {
|
||||||
force = d3.forceLinkCompleteGraph()
|
force = d3.forceLinkCompleteGraph()
|
||||||
.distance(function (n, m) {
|
.distance(function (n, m) {
|
||||||
return distanceFunction(n, m, props, norm);
|
return distanceFunction(n, m, props, norm);
|
||||||
})
|
})
|
||||||
.stableVelocity(0) // Change here
|
.stableVelocity(0) // Change here
|
||||||
.onStableVelo(ended);
|
.onStableVelo(ended);
|
||||||
}
|
} else {
|
||||||
else {
|
for (i = nodes.length - 1; i >= 1; i--) {
|
||||||
for (i = nodes.length-1; i >= 1; i--) {
|
for (j = i - 1; j >= 0; j--) {
|
||||||
for (j = i-1; j >= 0; j--) {
|
|
||||||
links.push({
|
links.push({
|
||||||
source: nodes[i],
|
source: nodes[i],
|
||||||
target: nodes[j],
|
target: nodes[j]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
force = d3.forceLink()
|
force = d3.forceLink()
|
||||||
.distance(function (n) {
|
.distance(function (n) {
|
||||||
return distanceFunction(n.source, n.target, props, norm);
|
return distanceFunction(n.source, n.target, props, norm);
|
||||||
})
|
})
|
||||||
.links(links);
|
.links(links);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add force
|
/* Add force
|
||||||
@@ -51,9 +50,9 @@ function startLinkSimulation() {
|
|||||||
simulation
|
simulation
|
||||||
.alphaDecay(0)
|
.alphaDecay(0)
|
||||||
.alpha(1)
|
.alpha(1)
|
||||||
.on("tick", ticked)
|
.on('tick', ticked)
|
||||||
.on("end", ended)
|
.on('end', ended)
|
||||||
//.velocityDecay(0.8)
|
// .velocityDecay(0.8)
|
||||||
.force(forceName,force)
|
.force(forceName, force)
|
||||||
.restart();
|
.restart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,28 +1,28 @@
|
|||||||
/**
|
/**
|
||||||
* Initialize the Chalmers' 1996 algorithm and start simulation.
|
* Initialize the Chalmers' 1996 algorithm and start simulation.
|
||||||
*/
|
*/
|
||||||
function startNeighbourSamplingSimulation() {
|
function startNeighbourSamplingSimulation () {
|
||||||
console.log("startNeighbourSamplingSimulation");
|
console.log('startNeighbourSamplingSimulation');
|
||||||
//springForce = true;
|
// springForce = true;
|
||||||
alreadyRanIterations = 0;
|
alreadyRanIterations = 0;
|
||||||
manualStop = true;
|
manualStop = true;
|
||||||
simulation.stop();
|
simulation.stop();
|
||||||
p1 = performance.now();
|
p1 = performance.now();
|
||||||
|
|
||||||
let force = d3.forceNeighbourSampling()
|
let force = d3.forceNeighbourSampling()
|
||||||
.neighbourSize(NEIGHBOUR_SIZE)
|
.neighbourSize(NEIGHBOUR_SIZE)
|
||||||
.sampleSize(SAMPLE_SIZE)
|
.sampleSize(SAMPLE_SIZE)
|
||||||
.distance(function (s, t) {
|
.distance(function (s, t) {
|
||||||
return distanceFunction(s, t, props, norm);
|
return distanceFunction(s, t, props, norm);
|
||||||
})
|
})
|
||||||
.stableVelocity(0) // Change here
|
.stableVelocity(0) // Change here
|
||||||
.onStableVelo(ended);
|
.onStableVelo(ended);
|
||||||
|
|
||||||
simulation
|
simulation
|
||||||
.alphaDecay(0)
|
.alphaDecay(0)
|
||||||
.alpha(1)
|
.alpha(1)
|
||||||
.on("tick", ticked)
|
.on('tick', ticked)
|
||||||
.on("end", ended)
|
.on('end', ended)
|
||||||
.force(forceName, force);
|
.force(forceName, force);
|
||||||
// Restart the simulation.
|
// Restart the simulation.
|
||||||
simulation.restart();
|
simulation.restart();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Initialize the t-SNE algorithm and start simulation.
|
* Initialize the t-SNE algorithm and start simulation.
|
||||||
*/
|
*/
|
||||||
function starttSNE() {
|
function starttSNE () {
|
||||||
springForce = false;
|
springForce = false;
|
||||||
simulation.stop();
|
simulation.stop();
|
||||||
p1 = performance.now();
|
p1 = performance.now();
|
||||||
@@ -25,20 +25,20 @@ function starttSNE() {
|
|||||||
/**
|
/**
|
||||||
* Initialize the Barnes-Hut algorithm and start simulation.
|
* Initialize the Barnes-Hut algorithm and start simulation.
|
||||||
*/
|
*/
|
||||||
function startBarnesHutSimulation() {
|
function startBarnesHutSimulation () {
|
||||||
console.log("startBarnesHutSimulation")
|
console.log('startBarnesHutSimulation');
|
||||||
alreadyRanIterations = 0;
|
alreadyRanIterations = 0;
|
||||||
manualStop = false;
|
manualStop = false;
|
||||||
springForce = false;
|
springForce = false;
|
||||||
p1 = performance.now();
|
p1 = performance.now();
|
||||||
|
|
||||||
simulation.alphaDecay(1 - Math.pow(0.001, 1 / ITERATIONS))
|
simulation.alphaDecay(1 - Math.pow(0.001, 1 / ITERATIONS))
|
||||||
.on("tick", ticked)
|
.on('tick', ticked)
|
||||||
.on("end", ended)
|
.on('end', ended)
|
||||||
.force(forceName, d3.forceBarnesHut()
|
.force(forceName, d3.forceBarnesHut()
|
||||||
// The distance function that will be used to calculate distances
|
// The distance function that will be used to calculate distances
|
||||||
// between nodes.
|
// between nodes.
|
||||||
.distance(function(s, t) { return distanceFunction(s, t, props, norm); }));
|
.distance(function (s, t) { return distanceFunction(s, t, props, norm); }));
|
||||||
// Restart the simulation.
|
// Restart the simulation.
|
||||||
simulation.alpha(1).restart();
|
simulation.alpha(1).restart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
* @param {array} properties - the properties of the nodes.
|
* @param {array} properties - the properties of the nodes.
|
||||||
* @return {number} the distance between source and target nodes.
|
* @return {number} the distance between source and target nodes.
|
||||||
*/
|
*/
|
||||||
function calculateCosineSimilarity(source, target, properties, normArgs) {
|
function calculateCosineSimilarity (source, target, properties, normArgs) {
|
||||||
var numerator = 0.0;
|
var numerator = 0.0;
|
||||||
|
|
||||||
// console.log(properties);
|
// console.log(properties);
|
||||||
// Iterate through every column of data
|
// Iterate through every column of data
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
property = properties[i];
|
property = properties[i];
|
||||||
if (property.toLowerCase() !== "class" && property.toLowerCase() !== "app" && property.toLowerCase() !== "user" && property.toLowerCase() !== "weekday") {
|
if (property.toLowerCase() !== 'class' && property.toLowerCase() !== 'app' && property.toLowerCase() !== 'user' && property.toLowerCase() !== 'weekday') {
|
||||||
var s = source[property],
|
var s = source[property],
|
||||||
t = target[property];
|
t = target[property];
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ function calculateCosineSimilarity(source, target, properties, normArgs) {
|
|||||||
return Math.abs(numerator / denominator);
|
return Math.abs(numerator / denominator);
|
||||||
}
|
}
|
||||||
|
|
||||||
function squareRooted(node, properties, normArgs) {
|
function squareRooted (node, properties, normArgs) {
|
||||||
var sum = 0.0;
|
var sum = 0.0;
|
||||||
|
|
||||||
for (var i = 0, s; i < properties.length; i++) {
|
for (var i = 0, s; i < properties.length; i++) {
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
* @param {array} properties - the properties of the nodes.
|
* @param {array} properties - the properties of the nodes.
|
||||||
* @return {number} the distance between source and target nodes.
|
* @return {number} the distance between source and target nodes.
|
||||||
*/
|
*/
|
||||||
function calculateDiceDissimilarity(source, target, properties, normArgs) {
|
function calculateDiceDissimilarity (source, target, properties, normArgs) {
|
||||||
var notShared = 0.0;
|
var notShared = 0.0;
|
||||||
|
|
||||||
// console.log(properties);
|
// console.log(properties);
|
||||||
// Iterate through every column of data
|
// Iterate through every column of data
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
property = properties[i];
|
property = properties[i];
|
||||||
if (property.toLowerCase() !== "class" && property.toLowerCase() !== "app" && property.toLowerCase() !== "user" && property.toLowerCase() !== "weekday") {
|
if (property.toLowerCase() !== 'class' && property.toLowerCase() !== 'app' && property.toLowerCase() !== 'user' && property.toLowerCase() !== 'weekday') {
|
||||||
var s = source[property],
|
var s = source[property],
|
||||||
t = target[property];
|
t = target[property];
|
||||||
|
|
||||||
|
|||||||
@@ -6,23 +6,23 @@
|
|||||||
* @param {object} normArgs - the normalization arguments.
|
* @param {object} normArgs - the normalization arguments.
|
||||||
* @return {number} the distance between source and target nodes.
|
* @return {number} the distance between source and target nodes.
|
||||||
*/
|
*/
|
||||||
function calculateDistance(source, target, properties, normArgs) {
|
function calculateDistance (source, target, properties, normArgs) {
|
||||||
var val1 = 0.0, val2 = 0.0,
|
var val1 = 0.0, val2 = 0.0,
|
||||||
sumDiff = 0.0,
|
sumDiff = 0.0,
|
||||||
ordDiff = 1.0,
|
ordDiff = 1.0,
|
||||||
ORD_FACTOR = 0.75,
|
ORD_FACTOR = 0.75,
|
||||||
cols = 0,
|
cols = 0,
|
||||||
average = normArgs.avg,
|
average = normArgs.avg,
|
||||||
sigma = normArgs.sig,
|
sigma = normArgs.sig,
|
||||||
st_dev = normArgs.st_d;
|
st_dev = normArgs.st_d;
|
||||||
|
|
||||||
// Iterate through every column of data
|
// Iterate through every column of data
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
property = properties[i];
|
property = properties[i];
|
||||||
if (source.hasOwnProperty(property) && target.hasOwnProperty(property)
|
if (source.hasOwnProperty(property) && target.hasOwnProperty(property) &&
|
||||||
&& property.toLowerCase() !== "index" && property.toLowerCase() !== "type") {
|
property.toLowerCase() !== 'index' && property.toLowerCase() !== 'type') {
|
||||||
var s = source[property],
|
var s = source[property],
|
||||||
t = target[property];
|
t = target[property];
|
||||||
|
|
||||||
// Comparing Floats and Integers
|
// Comparing Floats and Integers
|
||||||
if ((isNumeric(s) && isNumeric(t))) {
|
if ((isNumeric(s) && isNumeric(t))) {
|
||||||
@@ -32,7 +32,7 @@ function calculateDistance(source, target, properties, normArgs) {
|
|||||||
val1 = (val1 - average[i]) / (st_dev[i] * sigma[i]);
|
val1 = (val1 - average[i]) / (st_dev[i] * sigma[i]);
|
||||||
val2 = (val2 - average[i]) / (st_dev[i] * sigma[i]);
|
val2 = (val2 - average[i]) / (st_dev[i] * sigma[i]);
|
||||||
}
|
}
|
||||||
sumDiff += (val1-val2) * (val1-val2);
|
sumDiff += (val1 - val2) * (val1 - val2);
|
||||||
cols++;
|
cols++;
|
||||||
// Comparing strings
|
// Comparing strings
|
||||||
} else if (/[a-zA-Z]/.test(s) && /[a-zA-Z]/.test(t) && s === t) {
|
} else if (/[a-zA-Z]/.test(s) && /[a-zA-Z]/.test(t) && s === t) {
|
||||||
@@ -42,9 +42,8 @@ function calculateDistance(source, target, properties, normArgs) {
|
|||||||
// Comparing Dates
|
// Comparing Dates
|
||||||
var parsedDateS = Date.parse(s);
|
var parsedDateS = Date.parse(s);
|
||||||
var parsedDateT = Date.parse(t);
|
var parsedDateT = Date.parse(t);
|
||||||
if (isNaN(s) && !isNaN(parsedDateS)
|
if (isNaN(s) && !isNaN(parsedDateS) &&
|
||||||
&& isNaN(t) && !isNaN(parsedDateT)) {
|
isNaN(t) && !isNaN(parsedDateT)) {
|
||||||
|
|
||||||
val1 = parsedDateS.valueOf(),
|
val1 = parsedDateS.valueOf(),
|
||||||
val2 = parsedDateT.valueOf();
|
val2 = parsedDateT.valueOf();
|
||||||
|
|
||||||
@@ -52,7 +51,7 @@ function calculateDistance(source, target, properties, normArgs) {
|
|||||||
val1 = (val1 - average[i]) / (st_dev[i] * sigma[i]);
|
val1 = (val1 - average[i]) / (st_dev[i] * sigma[i]);
|
||||||
val2 = (val2 - average[i]) / (st_dev[i] * sigma[i]);
|
val2 = (val2 - average[i]) / (st_dev[i] * sigma[i]);
|
||||||
}
|
}
|
||||||
sumDiff += (val1-val2) * (val1-val2);
|
sumDiff += (val1 - val2) * (val1 - val2);
|
||||||
cols++;
|
cols++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,9 +61,9 @@ function calculateDistance(source, target, properties, normArgs) {
|
|||||||
sumDiff *= ordDiff;
|
sumDiff *= ordDiff;
|
||||||
|
|
||||||
if (cols > 0) {
|
if (cols > 0) {
|
||||||
sumDiff *= properties.length/cols;
|
sumDiff *= properties.length / cols;
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(sumDiff);
|
// console.log(sumDiff);
|
||||||
return sumDiff;
|
return sumDiff;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,33 +6,33 @@
|
|||||||
* @param {node} target
|
* @param {node} target
|
||||||
* @return {number} the distance between source and target nodes.
|
* @return {number} the distance between source and target nodes.
|
||||||
*/
|
*/
|
||||||
function calculateDistancePoker(source, target) {
|
function calculateDistancePoker (source, target) {
|
||||||
var sumDiff = 0.0,
|
var sumDiff = 0.0,
|
||||||
ordDiff = 1.0,
|
ordDiff = 1.0,
|
||||||
ORD_FACTOR = 1.5,
|
ORD_FACTOR = 1.5,
|
||||||
cards = ["C1", "C2", "C3", "C4", "C5"],
|
cards = ['C1', 'C2', 'C3', 'C4', 'C5'],
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
|
||||||
// Iterate through cards
|
// Iterate through cards
|
||||||
for (var i = 0; i < cards.length; i++) {
|
for (var i = 0; i < cards.length; i++) {
|
||||||
card = cards[i];
|
card = cards[i];
|
||||||
if (source.hasOwnProperty(card) && target.hasOwnProperty(card)) {
|
if (source.hasOwnProperty(card) && target.hasOwnProperty(card)) {
|
||||||
var s = parseInt(source[card]),
|
var s = parseInt(source[card]),
|
||||||
t = parseInt(target[card]);
|
t = parseInt(target[card]);
|
||||||
// Calculate the squared difference.
|
// Calculate the squared difference.
|
||||||
sumDiff += (s-t) * (s-t);
|
sumDiff += (s - t) * (s - t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Class of poker hands describes the similarities the best
|
// Class of poker hands describes the similarities the best
|
||||||
// so give it more priority than checking the differences between cards.
|
// so give it more priority than checking the differences between cards.
|
||||||
if (source.hasOwnProperty("CLASS") && target.hasOwnProperty("CLASS")) {
|
if (source.hasOwnProperty('CLASS') && target.hasOwnProperty('CLASS')) {
|
||||||
var s = parseInt(source["CLASS"]),
|
var s = parseInt(source['CLASS']),
|
||||||
t = parseInt(target["CLASS"]);
|
t = parseInt(target['CLASS']);
|
||||||
|
|
||||||
// If classes differ, then scale them by a factor.
|
// If classes differ, then scale them by a factor.
|
||||||
if (s !== t) {
|
if (s !== t) {
|
||||||
ordDiff *= (ORD_FACTOR * (Math.abs(s-t)))
|
ordDiff *= (ORD_FACTOR * (Math.abs(s - t)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,4 +40,4 @@ function calculateDistancePoker(source, target) {
|
|||||||
sumDiff *= ordDiff;
|
sumDiff *= ordDiff;
|
||||||
|
|
||||||
return sumDiff;
|
return sumDiff;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
* @param {array} properties - the properties of the nodes.
|
* @param {array} properties - the properties of the nodes.
|
||||||
* @return {number} the distance between source and target nodes.
|
* @return {number} the distance between source and target nodes.
|
||||||
*/
|
*/
|
||||||
function calculateEuclideanDistance(source, target, properties, normArgs) {
|
function calculateEuclideanDistance (source, target, properties, normArgs) {
|
||||||
var sumDiff = 0.0;
|
var sumDiff = 0.0;
|
||||||
|
|
||||||
// console.log(normArgs);
|
// console.log(normArgs);
|
||||||
// Iterate through every column of data
|
// Iterate through every column of data
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
property = properties[i];
|
property = properties[i];
|
||||||
if (property.toLowerCase() !== "class" && property.toLowerCase() !== "app" && property.toLowerCase() !== "user" && property.toLowerCase() !== "weekday" && property.toLowerCase() !== "type") {
|
if (property.toLowerCase() !== 'class' && property.toLowerCase() !== 'app' && property.toLowerCase() !== 'user' && property.toLowerCase() !== 'weekday' && property.toLowerCase() !== 'type') {
|
||||||
var s = source[property],
|
var s = source[property],
|
||||||
t = target[property];
|
t = target[property];
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @param {array} properties - the properties of the nodes.
|
* @param {array} properties - the properties of the nodes.
|
||||||
* @return {number} the distance between source and target nodes.
|
* @return {number} the distance between source and target nodes.
|
||||||
*/
|
*/
|
||||||
function calculateEuclideanDistanceTSNE(source, target, properties, normArgs) {
|
function calculateEuclideanDistanceTSNE (source, target, properties, normArgs) {
|
||||||
var dotProduct = 0.0,
|
var dotProduct = 0.0,
|
||||||
sumX = 0.0,
|
sumX = 0.0,
|
||||||
sumY = 0.0;
|
sumY = 0.0;
|
||||||
@@ -15,7 +15,7 @@ function calculateEuclideanDistanceTSNE(source, target, properties, normArgs) {
|
|||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
property = properties[i];
|
property = properties[i];
|
||||||
if (source.hasOwnProperty(property) && target.hasOwnProperty(property) &&
|
if (source.hasOwnProperty(property) && target.hasOwnProperty(property) &&
|
||||||
property.toLowerCase() !== "class") {
|
property.toLowerCase() !== 'class') {
|
||||||
var s = source[property],
|
var s = source[property],
|
||||||
t = target[property];
|
t = target[property];
|
||||||
|
|
||||||
|
|||||||
@@ -5,14 +5,14 @@
|
|||||||
* @param {array} properties - the properties of the nodes.
|
* @param {array} properties - the properties of the nodes.
|
||||||
* @return {number} the distance between source and target nodes.
|
* @return {number} the distance between source and target nodes.
|
||||||
*/
|
*/
|
||||||
function calculateJaccardDissimilarity(source, target, properties, normArgs) {
|
function calculateJaccardDissimilarity (source, target, properties, normArgs) {
|
||||||
var notShared = 0.0;
|
var notShared = 0.0;
|
||||||
|
|
||||||
// console.log(properties);
|
// console.log(properties);
|
||||||
// Iterate through every column of data
|
// Iterate through every column of data
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
property = properties[i];
|
property = properties[i];
|
||||||
if (property.toLowerCase() !== "class" && property.toLowerCase() !== "app" && property.toLowerCase() !== "user" && property.toLowerCase() !== "weekday") {
|
if (property.toLowerCase() !== 'class' && property.toLowerCase() !== 'app' && property.toLowerCase() !== 'user' && property.toLowerCase() !== 'weekday') {
|
||||||
var s = source[property],
|
var s = source[property],
|
||||||
t = target[property];
|
t = target[property];
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* @param {array} properties - the properties of the nodes.
|
* @param {array} properties - the properties of the nodes.
|
||||||
* @return {number} the distance between source and target nodes.
|
* @return {number} the distance between source and target nodes.
|
||||||
*/
|
*/
|
||||||
function calculateManhattanDistance(source, target, properties, normArgs) {
|
function calculateManhattanDistance (source, target, properties, normArgs) {
|
||||||
var sum = 0.0,
|
var sum = 0.0,
|
||||||
cols = 0;
|
cols = 0;
|
||||||
|
|
||||||
@@ -13,7 +13,7 @@ function calculateManhattanDistance(source, target, properties, normArgs) {
|
|||||||
// Iterate through every column of data
|
// Iterate through every column of data
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
property = properties[i];
|
property = properties[i];
|
||||||
if (property.toLowerCase() !== "class" && property.toLowerCase() !== "app" && property.toLowerCase() !== "user" && property.toLowerCase() !== "weekday") {
|
if (property.toLowerCase() !== 'class' && property.toLowerCase() !== 'app' && property.toLowerCase() !== 'user' && property.toLowerCase() !== 'weekday') {
|
||||||
var s = source[property],
|
var s = source[property],
|
||||||
t = target[property];
|
t = target[property];
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
* @param {array} nodes
|
* @param {array} nodes
|
||||||
* @return {object} that contains the normalization parameters.
|
* @return {object} that contains the normalization parameters.
|
||||||
*/
|
*/
|
||||||
function calculateNormalization(nodes) {
|
function calculateNormalization (nodes) {
|
||||||
var STANDARD_DEV = 2.0,
|
var STANDARD_DEV = 2.0,
|
||||||
properties = Object.keys(nodes[0]),
|
properties = Object.keys(nodes[0]),
|
||||||
sums = calculateSums(nodes, properties),
|
sums = calculateSums(nodes, properties),
|
||||||
@@ -23,10 +23,8 @@ function calculateNormalization(nodes) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function standardDevation (nodes, properties, avg) {
|
||||||
function standardDevation(nodes, properties, avg) {
|
var stDev = new Array(properties.length).fill(0);
|
||||||
|
|
||||||
var stDev = new Array(properties.length).fill(0)
|
|
||||||
|
|
||||||
for (var i = 0; i < properties.length; i++) {
|
for (var i = 0; i < properties.length; i++) {
|
||||||
var sum = 0;
|
var sum = 0;
|
||||||
@@ -48,11 +46,10 @@ function standardDevation(nodes, properties, avg) {
|
|||||||
sum += Math.pow(val - propAvg, 2);
|
sum += Math.pow(val - propAvg, 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
stDev[i] = Math.sqrt(sum/nodes.length);
|
stDev[i] = Math.sqrt(sum / nodes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stDev;
|
return stDev;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the sum of values and the squared sum
|
// Calculate the sum of values and the squared sum
|
||||||
@@ -63,7 +60,7 @@ function standardDevation(nodes, properties, avg) {
|
|||||||
* @return {object} that contains arrays with sum of values
|
* @return {object} that contains arrays with sum of values
|
||||||
* and the squared sums.
|
* and the squared sums.
|
||||||
*/
|
*/
|
||||||
function calculateSums(nodes, properties) {
|
function calculateSums (nodes, properties) {
|
||||||
var sumOfValues = new Array(properties.length).fill(0),
|
var sumOfValues = new Array(properties.length).fill(0),
|
||||||
sumOfSquares = new Array(properties.length).fill(0);
|
sumOfSquares = new Array(properties.length).fill(0);
|
||||||
|
|
||||||
@@ -90,4 +87,4 @@ function calculateSums(nodes, properties) {
|
|||||||
sumOfVal: sumOfValues,
|
sumOfVal: sumOfValues,
|
||||||
sumOfSq: sumOfSquares
|
sumOfSq: sumOfSquares
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
* @param {object} n - object to check.
|
* @param {object} n - object to check.
|
||||||
* @return {Boolean} true, if it is a number, false otherwise.
|
* @return {Boolean} true, if it is a number, false otherwise.
|
||||||
*/
|
*/
|
||||||
function isNumeric(n) {
|
function isNumeric (n) {
|
||||||
return !isNaN(parseFloat(n)) && isFinite(n);
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user