From 6335389c7c98ad464c5ac0de36e48462f5c78a5c Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 16 Mar 2018 10:19:13 +0700 Subject: [PATCH] Update 'src/interpolation/interpBruteForce.js' --- src/interpolation/interpBruteForce.js | 96 +++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/interpolation/interpBruteForce.js b/src/interpolation/interpBruteForce.js index 794de7a..14231ed 100644 --- a/src/interpolation/interpBruteForce.js +++ b/src/interpolation/interpBruteForce.js @@ -1,48 +1,48 @@ -import {pointOnCircle, takeSampleFrom} from "./helpers"; -import {placeNearToNearestNeighbour} from "./interpCommon"; - -/** - * Perform interpolation where the "parent" node is found by brute-force. - * A "parent" of a node to be interpolated is a node whose position in 2D space - * is already known and have the least high-dimensional distance to the node in - * question. - * For each point to be interpolated: - * - Phase 1: find the "parent" by comparing high-d distance against every - points already plotted on the graph. - this is essentially a nearest neighbour finding problem. - * - Phase 2 and 3 are passed onto placeNearToNearestNeighbour - * @param {list} sampleSet - nodes already plotted on the 2D graph - * @param {list} remainderSet - nodes to be interpolated onto the graph - * @param {function} distanceFn - f(nodex, nodey) that calculate high-dimensional - * distance between 2 nodes - * @param {number} endingIts - for phase 3, how many iterations to refine the - * placement of each interpolated point - */ -export default function(sampleSet, remainderSet, distanceFn, endingIts) { - let - sampleSubset = takeSampleFrom(sampleSet, Math.sqrt(sampleSet.length)).sample, - sampleSubsetDistanceCache = []; - - // For each datapoint "node" to be interpolated - for (let i = remainderSet.length-1; i>=0; i--) { - let - node = remainderSet[i], - nearestSample, minDist, sample, dist, index; - - // 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; - } - - index = sampleSubset.indexOf(sample); - if (index !== -1) - sampleSubsetDistanceCache[index] = dist; - } - - placeNearToNearestNeighbour(node, nearestSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts); - } -} +import {takeSampleFrom} from "./helpers"; +import {placeNearToNearestNeighbour} from "./interpCommon"; + +/** + * Perform interpolation where the "parent" node is found by brute-force. + * A "parent" of a node to be interpolated is a node whose position in 2D space + * is already known and have the least high-dimensional distance to the node in + * question. + * For each point to be interpolated: + * - Phase 1: find the "parent" by comparing high-d distance against every + points already plotted on the graph. + this is essentially a nearest neighbour finding problem. + * - Phase 2 and 3 are passed onto placeNearToNearestNeighbour + * @param {list} sampleSet - nodes already plotted on the 2D graph + * @param {list} remainderSet - nodes to be interpolated onto the graph + * @param {function} distanceFn - f(nodex, nodey) that calculate high-dimensional + * distance between 2 nodes + * @param {number} endingIts - for phase 3, how many iterations to refine the + * placement of each interpolated point + */ +export default function(sampleSet, remainderSet, distanceFn, endingIts) { + let + sampleSubset = takeSampleFrom(sampleSet, Math.sqrt(sampleSet.length)).sample, + sampleSubsetDistanceCache = []; + + // For each datapoint "node" to be interpolated + for (let i = remainderSet.length-1; i>=0; i--) { + let + node = remainderSet[i], + nearestSample, minDist, sample, dist, index; + + // 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; + } + + index = sampleSubset.indexOf(sample); + if (index !== -1) + sampleSubsetDistanceCache[index] = dist; + } + + placeNearToNearestNeighbour(node, nearestSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts); + } +}