Pivot cache number of pivots to a variable

This commit is contained in:
Pitchaya Boonsarngsuk
2018-01-31 16:04:48 +00:00
parent 0b0cd6d545
commit 28c27df551

View File

@@ -25,6 +25,7 @@ import {placeNearToNearestNeighbour} from "./interpCommon";
export default function(sampleSet, remainderSet, numPivots, distanceFn, endingIts) {
// Pivot based parent finding
let numBuckets = Math.floor(Math.sqrt(sampleSet.length));
let numNonPivots = sampleSet.length - numPivots;
let sets = takeSampleFrom(sampleSet, numPivots);
let pivots = sets.sample;
let nonPivotSamples = sets.remainder;
@@ -49,7 +50,7 @@ export default function(sampleSet, remainderSet, numPivots, distanceFn, endingIt
let pivot = pivots[j];
let maxDist = -1;
for (let i = 0; i < nonPivotSamples.length; i++) {
for (let i = 0; i < numNonPivots; i++) {
let sample = nonPivotSamples[i];
distCache[i][j] = distanceFn(pivot, sample);
if (distCache[i][j] > maxDist)
@@ -62,7 +63,7 @@ export default function(sampleSet, remainderSet, numPivots, distanceFn, endingIt
// Put samples (pivot not included) into buckets
for (let j = 0; j < numPivots; j++) {
let bucketWidth = bucketWidths[j];
for (let i = 0; i < nonPivotSamples.length; i++) {
for (let i = 0; i < numNonPivots; i++) {
let sample = nonPivotSamples[i];
let bucketNumber = Math.floor(distCache[i][j] / bucketWidth);
if (bucketNumber >= numBuckets) {