-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
49 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
// Retrieve the confidence interval. | ||
// This is represented as `stats.medianMin` and `stats.medianMax`. | ||
// When `showPrecision` is `true`, this is reported instead of `stats.median`. | ||
// This allows reporting both the approximate median and its precision at once. | ||
// - When this happens, `stats.median` is not reported | ||
// - This is easier to understand than reporting `stats.median` and | ||
// This is represented as `stats.meanMin` and `stats.meanMax`. | ||
// When `showPrecision` is `true`, this is reported instead of `stats.mean`. | ||
// This allows reporting both the approximate mean and its precision at once. | ||
// - When this happens, `stats.mean` is not reported | ||
// - This is easier to understand than reporting `stats.mean` and | ||
// `stats.moe|rmoe` because it is easier to visualize and to compare with | ||
// other combinations. | ||
// We do not allow `stats.medianMin|medianMax` to go beyond `stats.min|max`: | ||
// We do not allow `stats.meanMin|meanMax` to go beyond `stats.min|max`: | ||
// - This is very unlikely to happen, although technically possible providing | ||
// both: | ||
// - The number of loops is very low | ||
// - `stats.rstdev` is very high, i.e. the distribution is very skewed | ||
// - This allows `stats.min|max` to be used in reporting as extreme boundaries | ||
export const getConfidenceInterval = function ({ median, moe, min, max }) { | ||
const medianMin = Math.max(median - moe, min, 0) | ||
const medianMax = Math.min(median + moe, max) | ||
return { medianMin, medianMax } | ||
export const getConfidenceInterval = function ({ mean, moe, min, max }) { | ||
const meanMin = Math.max(mean - moe, min, 0) | ||
const meanMax = Math.min(mean + moe, max) | ||
return { meanMin, meanMax } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,37 @@ | ||
// Retrieve standard deviation of an array of floats (cannot be NaN/Infinity). | ||
// Array must not be empty. | ||
// We use the median, not the mean, because it is more stable and is privileged | ||
// in reporting. | ||
// We use the absolute standard deviation, as opposed to making it relative to | ||
// the median (as a percentage) | ||
// the mean (as a percentage) | ||
// - It makes it easier to understand: | ||
// - the spread of a given combination | ||
// - its relation to moe and distribution-related stats such as percentiles | ||
// (that are also not percentages) | ||
// - On the flipside, it makes it harder to compare combinations (since they | ||
// most likely have different medians) | ||
export const getStdev = function (array, { minIndex, maxIndex, median }) { | ||
// most likely have different means) | ||
export const getStdev = function (array, { minIndex, maxIndex, mean }) { | ||
const length = maxIndex - minIndex + 1 | ||
const variance = | ||
getSumDeviation({ array, minIndex, maxIndex, median }) / (length - 1) | ||
getSumDeviation({ array, minIndex, maxIndex, mean }) / (length - 1) | ||
return Math.sqrt(variance) | ||
} | ||
|
||
// We use a separate function from `getSum()` because it is much more performant | ||
const getSumDeviation = function ({ array, minIndex, maxIndex, median }) { | ||
const getSumDeviation = function ({ array, minIndex, maxIndex, mean }) { | ||
// eslint-disable-next-line fp/no-let | ||
let sum = 0 | ||
|
||
// eslint-disable-next-line fp/no-loops, fp/no-let, fp/no-mutation | ||
for (let index = minIndex; index <= maxIndex; index += 1) { | ||
// eslint-disable-next-line fp/no-mutation | ||
sum += (array[index] - median) ** 2 | ||
sum += (array[index] - mean) ** 2 | ||
} | ||
|
||
return sum | ||
} | ||
|
||
// Retrieve stdev relative to the median. | ||
// Retrieve stdev relative to the mean. | ||
// This is more useful than stdev when comparing different combinations, or when | ||
// targetting a specific precision threshold. | ||
export const getRstdev = function (stdev, median) { | ||
return stdev / median | ||
export const getRstdev = function (stdev, mean) { | ||
return stdev / mean | ||
} |