แก้ coding style ภาค 10
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
* 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,13 +17,13 @@ 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)
|
||||||
@@ -31,10 +31,10 @@ function startHybridSimulation() {
|
|||||||
.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);
|
||||||
@@ -42,8 +42,8 @@ function startHybridSimulation() {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* 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;
|
||||||
@@ -17,13 +17,12 @@ function startLinkSimulation() {
|
|||||||
})
|
})
|
||||||
.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]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,8 +50,8 @@ 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();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* 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;
|
||||||
@@ -21,8 +21,8 @@ function startNeighbourSamplingSimulation() {
|
|||||||
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();
|
||||||
|
|||||||
@@ -26,15 +26,15 @@ 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.
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ function calculateCosineSimilarity(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];
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ function calculateDiceDissimilarity(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];
|
||||||
|
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ function calculateDistance(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 (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];
|
||||||
|
|
||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ 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
|
||||||
@@ -26,13 +26,13 @@ function calculateDistancePoker(source, target) {
|
|||||||
|
|
||||||
// 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)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ function calculateEuclideanDistance(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" && 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];
|
||||||
|
|
||||||
|
|||||||
@@ -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];
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ function calculateJaccardDissimilarity(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];
|
||||||
|
|
||||||
|
|||||||
@@ -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];
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -52,7 +50,6 @@ function standardDevation(nodes, properties, avg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return stDev;
|
return stDev;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the sum of values and the squared sum
|
// Calculate the sum of values and the squared sum
|
||||||
|
|||||||
Reference in New Issue
Block a user