Skip to content

Commit

Permalink
Add identical variance
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Dec 19, 2021
1 parent f0d3c51 commit ff0d0fb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/stats/precision.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export const getPrecisionStats = function ({
const { variance, stdev, rstdev } = getVarianceStats(measures, {
minIndex,
maxIndex,
min,
max,
mean,
})
const envDev = getEnvDev(unsortedMeasures, { mean, variance, filter })
Expand Down
21 changes: 19 additions & 2 deletions src/stats/variance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
// Rstdev is stdev relative to the mean.
// This is more useful than stdev when comparing different combinations, or when
// targetting a specific precision threshold.
export const getVarianceStats = function (array, { minIndex, maxIndex, mean }) {
const variance = getVariance(array, { minIndex, maxIndex, mean })
export const getVarianceStats = function (
array,
{ minIndex, maxIndex, min, max, mean },
) {
const variance =
min === max
? getIdenticalVariance({ minIndex, maxIndex, mean })
: getVariance(array, { minIndex, maxIndex, mean })
const stdev = Math.sqrt(variance)
const rstdev = stdev / mean
return { variance, stdev, rstdev }
}

const getIdenticalVariance = function ({ minIndex, maxIndex, mean }) {
const sumDeviation = getIdenticalSumDeviation(mean)
return computeVariance(sumDeviation, minIndex, maxIndex + 1)
}

const getIdenticalSumDeviation = function (mean) {
return (mean * IDENTICAL_VARIANCE_SHIFT) ** 2
}

const IDENTICAL_VARIANCE_SHIFT = 1e-2

// Retrieve variance of an array of floats (cannot be NaN/Infinity).
// Array must not be empty.
// We use the absolute variance, as opposed to making it relative to the mean
Expand Down

0 comments on commit ff0d0fb

Please sign in to comment.