แก้ coding style ภาค 5
This commit is contained in:
@@ -9,6 +9,7 @@ rules:
|
|||||||
semi:
|
semi:
|
||||||
- error
|
- error
|
||||||
- always
|
- always
|
||||||
|
no-return-assign: 0
|
||||||
/*
|
/*
|
||||||
no-extra-parens: 1
|
no-extra-parens: 1
|
||||||
curly: 0
|
curly: 0
|
||||||
|
|||||||
@@ -67,11 +67,12 @@ export default function (sim, forceS, forceF) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set default value for interpDistanceFn if not been specified yet
|
// Set default value for interpDistanceFn if not been specified yet
|
||||||
if(interpDistanceFn === undefined) {
|
if (interpDistanceFn === undefined) {
|
||||||
if(forceFull.distance == 'function')
|
if (forceFull.distance == 'function') {
|
||||||
interpDistanceFn = forceFull.distance();
|
interpDistanceFn = forceFull.distance();
|
||||||
else
|
} else {
|
||||||
interpDistanceFn = constant(300);
|
interpDistanceFn = constant(300);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -39,8 +39,7 @@ export default function (sampleSet, remainderSet, distanceFn, endingIts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
index = sampleSubset.indexOf(sample);
|
index = sampleSubset.indexOf(sample);
|
||||||
if (index !== -1)
|
if (index !== -1) { sampleSubsetDistanceCache[index] = dist; }
|
||||||
sampleSubsetDistanceCache[index] = dist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
placeNearToNearestNeighbour(node, nearestSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts);
|
placeNearToNearestNeighbour(node, nearestSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts);
|
||||||
|
|||||||
@@ -38,15 +38,11 @@ export function placeNearToNearestNeighbour (node, nearNeighbour, radius, sample
|
|||||||
|
|
||||||
// Determine the closest quadrant
|
// Determine the closest quadrant
|
||||||
if (dist0 == dist180) {
|
if (dist0 == dist180) {
|
||||||
if (dist90 > dist270)
|
if (dist90 > dist270) { lowBound = highBound = 270; }
|
||||||
lowBound = highBound = 270;
|
else { lowBound = highBound = 90; }
|
||||||
else
|
|
||||||
lowBound = highBound = 90;
|
|
||||||
} else if (dist90 == dist270) {
|
} else if (dist90 == dist270) {
|
||||||
if (dist0 > dist180)
|
if (dist0 > dist180) { lowBound = highBound = 180; }
|
||||||
lowBound = highBound = 180;
|
else { lowBound = highBound = 0; }
|
||||||
else
|
|
||||||
lowBound = highBound = 0;
|
|
||||||
} else if (dist0 > dist180) {
|
} else if (dist0 > dist180) {
|
||||||
if (dist90 > dist270) {
|
if (dist90 > dist270) {
|
||||||
lowBound = 180;
|
lowBound = 180;
|
||||||
@@ -122,13 +118,14 @@ function binarySearchMin (lb, hb, fn) {
|
|||||||
valLowerHalf = fn(lb + range / 4),
|
valLowerHalf = fn(lb + range / 4),
|
||||||
valHigherHalf = fn(lb + range * 3 / 4);
|
valHigherHalf = fn(lb + range * 3 / 4);
|
||||||
|
|
||||||
if (valLowerHalf > valHigherHalf)
|
if (valLowerHalf > valHigherHalf) {
|
||||||
lb = Math.floor((lb + hb) / 2);
|
lb = Math.floor((lb + hb) / 2);
|
||||||
else if (valLowerHalf < valHigherHalf)
|
}
|
||||||
|
else if (valLowerHalf < valHigherHalf) {
|
||||||
hb = Math.ceil((lb + hb) / 2);
|
hb = Math.ceil((lb + hb) / 2);
|
||||||
else {
|
} else {
|
||||||
lb += Math.floor(range/4);
|
lb += Math.floor(range / 4);
|
||||||
hb -= Math.ceil(range/4);
|
hb -= Math.ceil(range / 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -44,8 +44,9 @@ export default function (sampleSet, remainderSet, numPivots, distanceFn, endingI
|
|||||||
let distCache = []; // [ For each non-pivot sample:[For each Pivot: distance] ]
|
let distCache = []; // [ For each non-pivot sample:[For each Pivot: distance] ]
|
||||||
let bucketWidths = []; // [ For each Pivot: width of each bucket ]
|
let bucketWidths = []; // [ For each Pivot: width of each bucket ]
|
||||||
|
|
||||||
for (let i = 0; i < nonPivotSamples.length; i++)
|
for (let i = 0; i < nonPivotSamples.length; i++) {
|
||||||
distCache[i] = [];
|
distCache[i] = [];
|
||||||
|
}
|
||||||
|
|
||||||
for (let j = 0; j < numPivots; j++) {
|
for (let j = 0; j < numPivots; j++) {
|
||||||
let pivot = pivots[j];
|
let pivot = pivots[j];
|
||||||
@@ -54,8 +55,9 @@ export default function (sampleSet, remainderSet, numPivots, distanceFn, endingI
|
|||||||
for (let i = 0; i < numNonPivots; i++) {
|
for (let i = 0; i < numNonPivots; i++) {
|
||||||
let sample = nonPivotSamples[i];
|
let sample = nonPivotSamples[i];
|
||||||
distCache[i][j] = distanceFn(pivot, sample);
|
distCache[i][j] = distanceFn(pivot, sample);
|
||||||
if (distCache[i][j] > maxDist)
|
if (distCache[i][j] > maxDist) {
|
||||||
maxDist = distCache[i][j];
|
maxDist = distCache[i][j];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bucketWidths.push(maxDist / numBuckets);
|
bucketWidths.push(maxDist / numBuckets);
|
||||||
@@ -109,12 +111,11 @@ export default function (sampleSet, remainderSet, numPivots, distanceFn, endingI
|
|||||||
for (let j = pivotsBuckets[p][bucketNumber].length - 1; j >= 0; j--) {
|
for (let j = pivotsBuckets[p][bucketNumber].length - 1; j >= 0; j--) {
|
||||||
let candidateNode = pivotsBuckets[p][bucketNumber][j];
|
let candidateNode = pivotsBuckets[p][bucketNumber][j];
|
||||||
let index = sampleSubset.indexOf(candidateNode);
|
let index = sampleSubset.indexOf(candidateNode);
|
||||||
if (index !== -1 && sampleSubsetDistanceCache[index] !== undefined)
|
if (index !== -1 && sampleSubsetDistanceCache[index] !== undefined) {
|
||||||
dist = sampleSubsetDistanceCache[index]
|
dist = sampleSubsetDistanceCache[index];
|
||||||
else {
|
} else {
|
||||||
dist = distanceFn(candidateNode, node);
|
dist = distanceFn(candidateNode, node);
|
||||||
if (index !== -1)
|
if (index !== -1) { sampleSubsetDistanceCache[index] = dist; }
|
||||||
sampleSubsetDistanceCache[index] = dist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dist < minDist) {
|
if (dist < minDist) {
|
||||||
@@ -126,8 +127,9 @@ export default function (sampleSet, remainderSet, numPivots, distanceFn, endingI
|
|||||||
|
|
||||||
// Fill in holes in cache
|
// Fill in holes in cache
|
||||||
for (let k = 0; k < sampleSubset.length; k++) {
|
for (let k = 0; k < sampleSubset.length; k++) {
|
||||||
if (sampleSubsetDistanceCache[k] === undefined)
|
if (sampleSubsetDistanceCache[k] === undefined) {
|
||||||
sampleSubsetDistanceCache[k] = distanceFn(node, sampleSubset[k]);
|
sampleSubsetDistanceCache[k] = distanceFn(node, sampleSubset[k]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
placeNearToNearestNeighbour(node, nearSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts);
|
placeNearToNearestNeighbour(node, nearSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user