Refactor / optimize for loop for interpolations
This commit is contained in:
@@ -14,21 +14,26 @@ import {placeNearToNearestNeighbour} from "./interpCommon";
|
||||
* @param {number} endingIts - for phase 3, how many iterations to refine the
|
||||
* placement of each interpolated point
|
||||
*/
|
||||
export default function(sampleSet, remainderSet, distanceFn) {
|
||||
export default function(sampleSet, remainderSet, distanceFn, endingIts) {
|
||||
let sampleSubset = takeSampleFrom(sampleSet, Math.sqrt(sampleSet.length)).sample;
|
||||
|
||||
for (let node of remainderSet) {
|
||||
let nearestSample, minDist,
|
||||
sampleSubsetDistanceCache = [];
|
||||
// For each datapoint "node" to be interpolated
|
||||
for (let i = remainderSet.length-1; i>=0; i--) {
|
||||
let
|
||||
node = remainderSet[i],
|
||||
sampleSubsetDistanceCache = [],
|
||||
nearestSample, minDist, sample, dist, index;
|
||||
|
||||
for (let sample of sampleSet) {
|
||||
let dist = distanceFn(node, sample);
|
||||
// For each datapoint "sample" in the sample set
|
||||
for (let j = sampleSet.length-1; j>=0; j--) {
|
||||
sample = sampleSet[j];
|
||||
dist = distanceFn(node, sample);
|
||||
if (nearestSample === undefined || dist < minDist) {
|
||||
minDist = dist;
|
||||
nearestSample = sample;
|
||||
}
|
||||
|
||||
let index = sampleSubset.indexOf(sample);
|
||||
index = sampleSubset.indexOf(sample);
|
||||
if (index !== -1)
|
||||
sampleSubsetDistanceCache[index] = dist;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user