แก้ coding style ภาค 10

This commit is contained in:
Pitchaya Boonsarngsuk
2018-03-22 16:40:27 +00:00
parent 400eab7e80
commit cd0f3687cb
14 changed files with 104 additions and 109 deletions

View File

@@ -1,10 +1,10 @@
/**
* Initialize the hybrid layout algorithm and start simulation.
*/
function startHybridSimulation() {
console.log("startHybridSimulation");
function startHybridSimulation () {
console.log('startHybridSimulation');
springForce = false;
d3.selectAll(".nodes").remove();
d3.selectAll('.nodes').remove();
manualStop = false;
simulation.stop();
p1 = performance.now();
@@ -17,33 +17,33 @@ function startHybridSimulation() {
.neighbourSize(NEIGHBOUR_SIZE)
.sampleSize(SAMPLE_SIZE)
.stableVelocity(0) // Change here
.distance(distance)
.distance(distance);
let forceFull = d3.forceNeighbourSampling()
.neighbourSize(FULL_NEIGHBOUR_SIZE)
.sampleSize(FULL_SAMPLE_SIZE)
.stableVelocity(0) // Change here
.distance(distance)
.distance(distance);
let hybridSimulation = d3.hybridSimulation(simulation, forceSample, forceFull)
.sampleIterations(ITERATIONS)
.fullIterations(FULL_ITERATIONS)
.numPivots(PIVOTS ? NUM_PIVOTS:-1)
.numPivots(PIVOTS ? NUM_PIVOTS : -1)
.interpFindTuneIts(INTERP_ENDING_ITS)
.interpDistanceFn(distance)
.on("sampleTick", ticked)
.on("fullTick", ticked)
.on("startInterp", startedFull)
.on("end", ended);
.on('sampleTick', ticked)
.on('fullTick', ticked)
.on('startInterp', startedFull)
.on('end', ended);
let sample = hybridSimulation.subSet();
addNodesToDOM(sample);
hybridSimulation.restart();
function startedFull() {
console.log("startedFull");
d3.selectAll(".nodes").remove();
function startedFull () {
console.log('startedFull');
d3.selectAll('.nodes').remove();
addNodesToDOM(nodes);
}
}

View File

@@ -1,8 +1,8 @@
/**
* Initialize the link force algorithm and start simulation.
*/
function startLinkSimulation() {
console.log("startLinkSimulation")
function startLinkSimulation () {
console.log('startLinkSimulation');
springForce = false;
alreadyRanIterations = 0;
manualStop = true;
@@ -12,26 +12,25 @@ function startLinkSimulation() {
if (tweakedVerOfLink) {
force = d3.forceLinkCompleteGraph()
.distance(function (n, m) {
return distanceFunction(n, m, props, norm);
})
.stableVelocity(0) // Change here
.onStableVelo(ended);
}
else {
for (i = nodes.length-1; i >= 1; i--) {
for (j = i-1; j >= 0; j--) {
.distance(function (n, m) {
return distanceFunction(n, m, props, norm);
})
.stableVelocity(0) // Change here
.onStableVelo(ended);
} else {
for (i = nodes.length - 1; i >= 1; i--) {
for (j = i - 1; j >= 0; j--) {
links.push({
source: nodes[i],
target: nodes[j],
target: nodes[j]
});
}
}
force = d3.forceLink()
.distance(function (n) {
return distanceFunction(n.source, n.target, props, norm);
})
.links(links);
.distance(function (n) {
return distanceFunction(n.source, n.target, props, norm);
})
.links(links);
}
/* Add force
@@ -51,9 +50,9 @@ function startLinkSimulation() {
simulation
.alphaDecay(0)
.alpha(1)
.on("tick", ticked)
.on("end", ended)
//.velocityDecay(0.8)
.force(forceName,force)
.on('tick', ticked)
.on('end', ended)
// .velocityDecay(0.8)
.force(forceName, force)
.restart();
}

View File

@@ -1,28 +1,28 @@
/**
* Initialize the Chalmers' 1996 algorithm and start simulation.
*/
function startNeighbourSamplingSimulation() {
console.log("startNeighbourSamplingSimulation");
//springForce = true;
function startNeighbourSamplingSimulation () {
console.log('startNeighbourSamplingSimulation');
// springForce = true;
alreadyRanIterations = 0;
manualStop = true;
simulation.stop();
p1 = performance.now();
let force = d3.forceNeighbourSampling()
.neighbourSize(NEIGHBOUR_SIZE)
.sampleSize(SAMPLE_SIZE)
.distance(function (s, t) {
return distanceFunction(s, t, props, norm);
})
.stableVelocity(0) // Change here
.onStableVelo(ended);
.neighbourSize(NEIGHBOUR_SIZE)
.sampleSize(SAMPLE_SIZE)
.distance(function (s, t) {
return distanceFunction(s, t, props, norm);
})
.stableVelocity(0) // Change here
.onStableVelo(ended);
simulation
.alphaDecay(0)
.alpha(1)
.on("tick", ticked)
.on("end", ended)
.on('tick', ticked)
.on('end', ended)
.force(forceName, force);
// Restart the simulation.
simulation.restart();

View File

@@ -1,7 +1,7 @@
/**
* Initialize the t-SNE algorithm and start simulation.
*/
function starttSNE() {
function starttSNE () {
springForce = false;
simulation.stop();
p1 = performance.now();
@@ -25,20 +25,20 @@ function starttSNE() {
/**
* Initialize the Barnes-Hut algorithm and start simulation.
*/
function startBarnesHutSimulation() {
console.log("startBarnesHutSimulation")
function startBarnesHutSimulation () {
console.log('startBarnesHutSimulation');
alreadyRanIterations = 0;
manualStop = false;
springForce = false;
p1 = performance.now();
simulation.alphaDecay(1 - Math.pow(0.001, 1 / ITERATIONS))
.on("tick", ticked)
.on("end", ended)
.force(forceName, d3.forceBarnesHut()
// The distance function that will be used to calculate distances
// between nodes.
.distance(function(s, t) { return distanceFunction(s, t, props, norm); }));
.on('tick', ticked)
.on('end', ended)
.force(forceName, d3.forceBarnesHut()
// The distance function that will be used to calculate distances
// between nodes.
.distance(function (s, t) { return distanceFunction(s, t, props, norm); }));
// Restart the simulation.
simulation.alpha(1).restart();
}

View File

@@ -5,14 +5,14 @@
* @param {array} properties - the properties of the 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;
// console.log(properties);
// Iterate through every column of data
for (var i = 0; i < properties.length; 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],
t = target[property];
@@ -26,7 +26,7 @@ function calculateCosineSimilarity(source, target, properties, normArgs) {
return Math.abs(numerator / denominator);
}
function squareRooted(node, properties, normArgs) {
function squareRooted (node, properties, normArgs) {
var sum = 0.0;
for (var i = 0, s; i < properties.length; i++) {

View File

@@ -5,14 +5,14 @@
* @param {array} properties - the properties of the 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;
// console.log(properties);
// Iterate through every column of data
for (var i = 0; i < properties.length; 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],
t = target[property];

View File

@@ -6,23 +6,23 @@
* @param {object} normArgs - the normalization arguments.
* @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,
sumDiff = 0.0,
ordDiff = 1.0,
ORD_FACTOR = 0.75,
cols = 0,
average = normArgs.avg,
sigma = normArgs.sig,
st_dev = normArgs.st_d;
sumDiff = 0.0,
ordDiff = 1.0,
ORD_FACTOR = 0.75,
cols = 0,
average = normArgs.avg,
sigma = normArgs.sig,
st_dev = normArgs.st_d;
// 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() !== "index" && property.toLowerCase() !== "type") {
if (source.hasOwnProperty(property) && target.hasOwnProperty(property) &&
property.toLowerCase() !== 'index' && property.toLowerCase() !== 'type') {
var s = source[property],
t = target[property];
t = target[property];
// Comparing Floats and Integers
if ((isNumeric(s) && isNumeric(t))) {
@@ -32,7 +32,7 @@ function calculateDistance(source, target, properties, normArgs) {
val1 = (val1 - 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++;
// Comparing strings
} 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
var parsedDateS = Date.parse(s);
var parsedDateT = Date.parse(t);
if (isNaN(s) && !isNaN(parsedDateS)
&& isNaN(t) && !isNaN(parsedDateT)) {
if (isNaN(s) && !isNaN(parsedDateS) &&
isNaN(t) && !isNaN(parsedDateT)) {
val1 = parsedDateS.valueOf(),
val2 = parsedDateT.valueOf();
@@ -52,7 +51,7 @@ function calculateDistance(source, target, properties, normArgs) {
val1 = (val1 - 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++;
}
}
@@ -62,9 +61,9 @@ function calculateDistance(source, target, properties, normArgs) {
sumDiff *= ordDiff;
if (cols > 0) {
sumDiff *= properties.length/cols;
sumDiff *= properties.length / cols;
}
//console.log(sumDiff);
// console.log(sumDiff);
return sumDiff;
}

View File

@@ -6,33 +6,33 @@
* @param {node} target
* @return {number} the distance between source and target nodes.
*/
function calculateDistancePoker(source, target) {
function calculateDistancePoker (source, target) {
var sumDiff = 0.0,
ordDiff = 1.0,
ORD_FACTOR = 1.5,
cards = ["C1", "C2", "C3", "C4", "C5"],
cols = 0;
ordDiff = 1.0,
ORD_FACTOR = 1.5,
cards = ['C1', 'C2', 'C3', 'C4', 'C5'],
cols = 0;
// Iterate through cards
for (var i = 0; i < cards.length; i++) {
card = cards[i];
if (source.hasOwnProperty(card) && target.hasOwnProperty(card)) {
var s = parseInt(source[card]),
t = parseInt(target[card]);
t = parseInt(target[card]);
// Calculate the squared difference.
sumDiff += (s-t) * (s-t);
sumDiff += (s - t) * (s - t);
}
}
// Class of poker hands describes the similarities the best
// so give it more priority than checking the differences between cards.
if (source.hasOwnProperty("CLASS") && target.hasOwnProperty("CLASS")) {
var s = parseInt(source["CLASS"]),
t = parseInt(target["CLASS"]);
if (source.hasOwnProperty('CLASS') && target.hasOwnProperty('CLASS')) {
var s = parseInt(source['CLASS']),
t = parseInt(target['CLASS']);
// If classes differ, then scale them by a factor.
if (s !== t) {
ordDiff *= (ORD_FACTOR * (Math.abs(s-t)))
ordDiff *= (ORD_FACTOR * (Math.abs(s - t)));
}
}

View File

@@ -5,14 +5,14 @@
* @param {array} properties - the properties of the 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;
// console.log(normArgs);
// Iterate through every column of data
for (var i = 0; i < properties.length; 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],
t = target[property];

View File

@@ -5,7 +5,7 @@
* @param {array} properties - the properties of the 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,
sumX = 0.0,
sumY = 0.0;
@@ -15,7 +15,7 @@ function calculateEuclideanDistanceTSNE(source, target, properties, normArgs) {
for (var i = 0; i < properties.length; i++) {
property = properties[i];
if (source.hasOwnProperty(property) && target.hasOwnProperty(property) &&
property.toLowerCase() !== "class") {
property.toLowerCase() !== 'class') {
var s = source[property],
t = target[property];

View File

@@ -5,14 +5,14 @@
* @param {array} properties - the properties of the 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;
// console.log(properties);
// Iterate through every column of data
for (var i = 0; i < properties.length; 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],
t = target[property];

View File

@@ -5,7 +5,7 @@
* @param {array} properties - the properties of the 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,
cols = 0;
@@ -13,7 +13,7 @@ function calculateManhattanDistance(source, target, properties, normArgs) {
// Iterate through every column of data
for (var i = 0; i < properties.length; 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],
t = target[property];

View File

@@ -3,7 +3,7 @@
* @param {array} nodes
* @return {object} that contains the normalization parameters.
*/
function calculateNormalization(nodes) {
function calculateNormalization (nodes) {
var STANDARD_DEV = 2.0,
properties = Object.keys(nodes[0]),
sums = calculateSums(nodes, properties),
@@ -23,10 +23,8 @@ function calculateNormalization(nodes) {
};
}
function standardDevation(nodes, properties, avg) {
var stDev = new Array(properties.length).fill(0)
function standardDevation (nodes, properties, avg) {
var stDev = new Array(properties.length).fill(0);
for (var i = 0; i < properties.length; i++) {
var sum = 0;
@@ -48,11 +46,10 @@ function standardDevation(nodes, properties, avg) {
sum += Math.pow(val - propAvg, 2);
});
stDev[i] = Math.sqrt(sum/nodes.length);
stDev[i] = Math.sqrt(sum / nodes.length);
}
return stDev;
}
// 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
* and the squared sums.
*/
function calculateSums(nodes, properties) {
function calculateSums (nodes, properties) {
var sumOfValues = new Array(properties.length).fill(0),
sumOfSquares = new Array(properties.length).fill(0);

View File

@@ -3,6 +3,6 @@
* @param {object} n - object to check.
* @return {Boolean} true, if it is a number, false otherwise.
*/
function isNumeric(n) {
function isNumeric (n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}