Fix bugs, clean up comments
This commit is contained in:
@@ -12,7 +12,7 @@ export function takeSampleFrom(sourceList, amount) {
|
||||
let randElements = [],
|
||||
max = sourceList.length;
|
||||
|
||||
if (amount <= max) {
|
||||
if (amount >= max) {
|
||||
return {sample: sourceList, remainder: {}};
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import jiggle from "./jiggle";
|
||||
import {getStress} from "./stress";
|
||||
|
||||
/**
|
||||
* The implementation of Chalmers' 1996 Neighbour and Sampling algorithm.
|
||||
* An implementation of Chalmers' 1996 Neighbour and Sampling algorithm.
|
||||
* It uses random sampling to find the most suited neighbours from the
|
||||
* data set.
|
||||
*/
|
||||
@@ -23,7 +23,7 @@ export default function () {
|
||||
dataSizeFactor;
|
||||
|
||||
/**
|
||||
* Apply spring forces at each iteration.
|
||||
* Apply spring forces at each simulation iteration.
|
||||
* @param {number} alpha - multiplier for amount of force applied
|
||||
*/
|
||||
function force(alpha) {
|
||||
@@ -48,7 +48,7 @@ export default function () {
|
||||
for (let [sampleID, highDDist] of samples) {
|
||||
setVelocity(node, nodes[sampleID], highDDist, alpha);
|
||||
}
|
||||
// Replace neighbours with better ones found in the samples
|
||||
|
||||
neighbours[i] = findNewNeighbours(neighbours[i], samples);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ export default function () {
|
||||
velocityDiff /= n*(neighbourSize+sampleSize);
|
||||
|
||||
if(stableVeloHandler!==null && velocityDiff<stableVelocity){
|
||||
//TODO remove console logs
|
||||
console.log("Neighbour sampling is now", velocityDiff, ", calling stableVeloHandler().")
|
||||
stableVeloHandler();
|
||||
}
|
||||
@@ -91,6 +92,7 @@ export default function () {
|
||||
source.vy += y;
|
||||
}
|
||||
|
||||
// Called on nodes change and added to a simulation
|
||||
function initialize() {
|
||||
if (!nodes) return;
|
||||
|
||||
@@ -168,15 +170,14 @@ export default function () {
|
||||
}
|
||||
|
||||
|
||||
// API for initializing the algorithm, setting parameters and querying
|
||||
// metrics.
|
||||
// API for initializing the algorithm and setting parameters
|
||||
force.initialize = function (_) {
|
||||
nodes = _;
|
||||
initialize();
|
||||
};
|
||||
|
||||
force.neighbourSize = function (_) {
|
||||
return arguments.length ? (neighbourSize = +_, initDataSizeFactor(), force) : neighbourSize;
|
||||
return arguments.length ? (neighbourSize = +_, initialize(), force) : neighbourSize;
|
||||
};
|
||||
|
||||
force.sampleSize = function (_) {
|
||||
|
||||
Reference in New Issue
Block a user