44 lines
1.3 KiB
JavaScript
44 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) * MULTIPLIER;
|
|
}));
|
|
// 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() {
|
|
springForce = false;
|
|
simulation.stop();
|
|
p1 = performance.now();
|
|
|
|
simulation
|
|
.alphaDecay(1 - Math.pow(0.001, 1 / ITERATIONS))
|
|
.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) * MULTIPLIER;
|
|
}));
|
|
// Restart the simulation.
|
|
simulation.alpha(1).restart();
|
|
}
|