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

45 lines
1.3 KiB
JavaScript

/**
* Initialize the t-SNE algorithm and start simulation.
*/
function starttSNE () {
springForce = false;
simulation.stop();
p1 = performance.now();
simulation
.alphaDecay(1 - Math.pow(0.001, 1 / ITERATIONS))
.force(forceName, d3.tSNE()
// Set the parameter for the algorithm (optional).
.perplexity(PERPLEXITY)
.learningRate(LEARNING_RATE)
// 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.
console.log(simulation.force(forceName).perplexity(), simulation.force(forceName).learningRate());
simulation.alpha(1).restart();
}
/**
* Initialize the Barnes-Hut algorithm and start simulation.
*/
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); }));
// Restart the simulation.
simulation.alpha(1).restart();
}