Compare commits
1 Commits
withConsol
...
pivotHitRa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd32d7b38c |
@@ -30,6 +30,7 @@ export default function(sampleSet, remainderSet, numPivots, distanceFn, endingIt
|
|||||||
let sets = takeSampleFrom(sampleSet, numPivots);
|
let sets = takeSampleFrom(sampleSet, numPivots);
|
||||||
let pivots = sets.sample;
|
let pivots = sets.sample;
|
||||||
let nonPivotSamples = sets.remainder;
|
let nonPivotSamples = sets.remainder;
|
||||||
|
let correct = 0, wrong = 0, percentsOff = [];
|
||||||
|
|
||||||
let pivotsBuckets = []; // [ For each Pivot:[For each bucket:[each point in bucket]] ]
|
let pivotsBuckets = []; // [ For each Pivot:[For each bucket:[each point in bucket]] ]
|
||||||
for (let i = 0; i < numPivots; i++) {
|
for (let i = 0; i < numPivots; i++) {
|
||||||
@@ -130,6 +131,45 @@ export default function(sampleSet, remainderSet, numPivots, distanceFn, endingIt
|
|||||||
if (sampleSubsetDistanceCache[k] === undefined)
|
if (sampleSubsetDistanceCache[k] === undefined)
|
||||||
sampleSubsetDistanceCache[k] = distanceFn(node, sampleSubset[k]);
|
sampleSubsetDistanceCache[k] = distanceFn(node, sampleSubset[k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let nearestSample, nearestMinDist, sample, dist;
|
||||||
|
for (let j = sampleSet.length-1; j>=0; j--) {
|
||||||
|
sample = sampleSet[j];
|
||||||
|
dist = distanceFn(node, sample);
|
||||||
|
if (nearestSample === undefined || dist < nearestMinDist) {
|
||||||
|
nearestMinDist = dist;
|
||||||
|
nearestSample = sample;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(minDist-nearestMinDist == 0) correct++;
|
||||||
|
else {
|
||||||
|
wrong++;
|
||||||
|
if(nearestMinDist!=0)percentsOff.push(minDist/nearestMinDist)
|
||||||
|
}
|
||||||
|
|
||||||
placeNearToNearestNeighbour(node, nearSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts);
|
placeNearToNearestNeighbour(node, nearSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts);
|
||||||
}
|
}
|
||||||
|
console.log("Correct", correct);
|
||||||
|
console.log("Wrong", wrong);
|
||||||
|
console.log("Correct percent", 100*correct/(correct+wrong));
|
||||||
|
StandardDeviation(percentsOff)
|
||||||
|
}
|
||||||
|
|
||||||
|
function StandardDeviation(numbersArr) {
|
||||||
|
//--CALCULATE AVAREGE--
|
||||||
|
var total = 0;
|
||||||
|
for(var key in numbersArr)
|
||||||
|
total += numbersArr[key];
|
||||||
|
var meanVal = total / numbersArr.length;
|
||||||
|
console.log("Average percent off", meanVal);
|
||||||
|
//--CALCULATE AVAREGE--
|
||||||
|
|
||||||
|
//--CALCULATE STANDARD DEVIATION--
|
||||||
|
var SDprep = 0;
|
||||||
|
for(var key in numbersArr)
|
||||||
|
SDprep += Math.pow((parseFloat(numbersArr[key]) - meanVal),2);
|
||||||
|
var SDresult = Math.sqrt(SDprep/numbersArr.length);
|
||||||
|
//--CALCULATE STANDARD DEVIATION--
|
||||||
|
console.log("SD percent off", SDresult);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user