Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Nov 14, 2021
1 parent 58991fa commit 427cf61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
10 changes: 6 additions & 4 deletions src/stats/precision.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getConfidenceInterval } from './confidence.js'
import { getEnvDev } from './env_dev/main.js'
import { getMoe, getRmoe } from './moe.js'
import { getVariance, getStdev, getRstdev } from './variance.js'
import { getVarianceStats } from './variance.js'

// Retrieve stats related to `stdev` and precision.
export const getPrecisionStats = function ({
Expand All @@ -22,9 +22,11 @@ export const getPrecisionStats = function ({
return getPerfectPrecisionStats(mean)
}

const variance = getVariance(measures, { minIndex, maxIndex, mean })
const stdev = getStdev(variance)
const rstdev = getRstdev(stdev, mean)
const { variance, stdev, rstdev } = getVarianceStats(measures, {
minIndex,
maxIndex,
mean,
})

const { envDev } = getEnvDev(unsortedMeasures, {
mean,
Expand Down
23 changes: 11 additions & 12 deletions src/stats/variance.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// Retrieve all variance-related stats.
// 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 })
const stdev = Math.sqrt(variance)
const rstdev = stdev / mean
return { variance, stdev, rstdev }
}

// 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 Expand Up @@ -29,15 +40,3 @@ const getSumDeviation = function ({ array, minIndex, maxIndex, mean }) {

return sum
}

// Retrieve standard deviation
export const getStdev = function (variance) {
return Math.sqrt(variance)
}

// 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, mean) {
return stdev / mean
}

0 comments on commit 427cf61

Please sign in to comment.