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