Interp almost-complete brute-force interpolation

This commit is contained in:
Pitchaya Boonsarngsuk
2018-01-16 21:24:47 +00:00
parent a615ef199d
commit 7b6b5e46c6
4 changed files with 82 additions and 94 deletions

View File

@@ -16,34 +16,34 @@ export default function (nodes, config) {
FullneighbourSize = config.hasOwnProperty("fullNeighbourSize") ? config.fullNeighbourSize : 6,
FullsampleSize = config.hasOwnProperty("fullSampleSize") ? config.fullSampleSize : 3,
FulldistanceRange = config.hasOwnProperty("fullDistanceRange") ? config.fullDistanceRange : 10,
distanceFn = config.hasOwnProperty("distanceFn") ? config.distance : constant(300),
distanceFn = config.hasOwnProperty("distanceFn") ? config.distanceFn : constant(300),
PIVOTS = config.hasOwnProperty("pivots") ? config.pivots : false,
NUMPIVOTS = config.hasOwnProperty("numPivots") ? config.numPivots : 3,
event = d3.dispatch("sampleTick", "fullTick", "startFull", "end");
var sets = sampleFromNodes(nodes, nodes.length, Math.sqrt(nodes.length));
var sets = sampleFromNodes(nodes, Math.sqrt(nodes.length));
var sample = sets.sample;
var remainder = sets.remainder;
var interpSubset = sampleFromNodes(sample, sample.length, Math.sqrt(sample.length)).sample;
var sampleSubset = sampleFromNodes(sample, Math.sqrt(sample.length)).sample;
var sampleSimulation = d3.forceSimulation(sample)
.stop()
.alphaDecay(1 - Math.pow(0.001, 1 / SAMPLE_ITERATIONS));
sampleSimulation
.alphaDecay(1 - Math.pow(0.001, 1 / SAMPLE_ITERATIONS))
.on("tick", function () {
event.call("sampleTick", sampleSimulation);
})
.on("end", ended)
.force("neighbourSampling", neighbourSamplingDistance()
.on("end", ended);
sampleSimulation.force("forces", neighbourSamplingDistance()
.neighbourSize(neighbourSize)
.sampleSize(sampleSize)
.distanceRange(distanceRange)
.distance(distanceFn)
)
.alpha(1).restart();
);
sampleSimulation.alpha(1).restart();
function ended() {
event.call("startFull");
console.log("Ended sample simulation");
/*
if (PIVOTS) {
@@ -52,12 +52,16 @@ export default function (nodes, config) {
interpolation(sample, remainder, interpSubset, distance);
}
*/
if (FULL_ITERATIONS==0) return;
event.call("fullTick");
alert('About to Full run');
if (FULL_ITERATIONS==0) {
event.call("end");
return;
}
fullSimulation = d3.forceSimulation()
.stop()
.alphaDecay(1 - Math.pow(0.001, 1 / FULL_ITERATIONS));
event.call("startFull", fullSimulation);
fullSimulation
.force("neighbourSampling", neighbourSamplingDistance()
@@ -139,8 +143,9 @@ export default function (nodes, config) {
}
function sampleFromNodes(nodes, max, size) {
var randElements = [];
function sampleFromNodes(nodes, size) {
let randElements = [],
max = nodes.length;
for (var i = 0; i < size; ++i) {
var rand = nodes[Math.floor((Math.random() * max))];