Skip to content

Commit

Permalink
Rename envDev
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Nov 14, 2021
1 parent de0b1d6 commit 94e2e64
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
12 changes: 6 additions & 6 deletions src/stats/env_dev/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const getEnvDev = function (
const groupsCount = getGroupsCount(samples.length)

if (groupsCount <= 0) {
return { meanStdevRatio: MIN_VARIANCE_RATIO, groups: [] }
return { envDev: MIN_ENV_DEV, groups: [] }
}

const clusterSizes = getClusterSizes(groupsCount)
Expand All @@ -27,12 +27,12 @@ export const getEnvDev = function (
})

if (groups.length === 0) {
return { meanStdevRatio: MIN_VARIANCE_RATIO, groups: [] }
return { envDev: MIN_ENV_DEV, groups: [] }
}

const meanRatio = computeMeanRatio(groups)
const meanStdevRatio = Math.sqrt(meanRatio)
return { meanStdevRatio, groups }
const envDev = Math.sqrt(meanRatio)
return { envDev, groups }
}

const returnTrue = function () {
Expand Down Expand Up @@ -250,7 +250,7 @@ const computeMeanRatio = function (groups) {
varianceRatios,
maxIndex,
)
return Math.max(varianceRatioMean, MIN_VARIANCE_RATIO)
return Math.max(varianceRatioMean, MIN_ENV_DEV)
}

const getGroupVarianceRatio = function ({ varianceRatio }) {
Expand Down Expand Up @@ -326,7 +326,7 @@ const isValidGroup = function (
// - When the distribution measures are fully independent from each other
// - In some rare cases with odd distributions
// In those cases, we default to returning 1
const MIN_VARIANCE_RATIO = 1
const MIN_ENV_DEV = 1

// Significance level when computing the confidence interval of each group's
// variance.
Expand Down
35 changes: 16 additions & 19 deletions src/stats/env_dev/try.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const samplesCount = 1e3

const realPeriods = new Set([])
const maxRealPeriodBase = Math.log(realLength) / Math.log(CLUSTER_FACTOR)
const meanRatiosAccuracies = []
const meanRatiosRstdevs = []
const envDevsAccuracies = []
const envDevsRstdevs = []

// eslint-disable-next-line fp/no-loops
for (
Expand Down Expand Up @@ -50,7 +50,7 @@ for (

realPeriods.add(realPeriod)

const meanRatiosProps = Array.from({ length: samplesCount }, () => {
const envDevsProps = Array.from({ length: samplesCount }, () => {
const samples = getSamples(
realLength,
realPeriod,
Expand All @@ -61,10 +61,8 @@ for (
)
return getEnvDev(samples)
})
const meanRatios = meanRatiosProps.map(
({ meanStdevRatio }) => meanStdevRatio,
)
const allGroups = meanRatiosProps.map(({ groups }) =>
const envDevs = envDevsProps.map(({ envDev }) => envDev)
const allGroups = envDevsProps.map(({ groups }) =>
// eslint-disable-next-line max-nested-callbacks
groups.map(({ varianceRatio }) => Math.sqrt(varianceRatio)),
)
Expand All @@ -83,23 +81,22 @@ for (
return groupMedian
},
)
const realMeanRatio = Math.max(...groupMedians)
const meanRatiosMean = getMean(meanRatios)
const meanRatiosMedian = getQuantile(
const realEnvDev = Math.max(...groupMedians)
const envDevsMean = getMean(envDevs)
const envDevsMedian = getQuantile(
// eslint-disable-next-line fp/no-mutating-methods
[...meanRatios].sort(sortNumbers),
[...envDevs].sort(sortNumbers),
// eslint-disable-next-line no-magic-numbers
0.5,
{},
)
const meanRatiosRstdev =
Math.sqrt(getVariance(meanRatios, { mean: meanRatiosMean })) /
meanRatiosMedian
const meanRatiosAccuracy = meanRatiosMedian / realMeanRatio
const envDevsRstdev =
Math.sqrt(getVariance(envDevs, { mean: envDevsMean })) / envDevsMedian
const envDevsAccuracy = envDevsMedian / realEnvDev
// eslint-disable-next-line fp/no-mutating-methods
meanRatiosAccuracies.push(meanRatiosAccuracy)
envDevsAccuracies.push(envDevsAccuracy)
// eslint-disable-next-line fp/no-mutating-methods
meanRatiosRstdevs.push(meanRatiosRstdev)
envDevsRstdevs.push(envDevsRstdev)
}
}

Expand All @@ -110,9 +107,9 @@ console.log(`${[...realPeriods]
.join(' ')}
${
// eslint-disable-next-line no-magic-numbers
meanRatiosAccuracies.map((float) => float.toFixed(2).padStart(5)).join(' ')
envDevsAccuracies.map((float) => float.toFixed(2).padStart(5)).join(' ')
}
${
// eslint-disable-next-line no-magic-numbers
meanRatiosRstdevs.map((float) => float.toFixed(2).padStart(5)).join(' ')
envDevsRstdevs.map((float) => float.toFixed(2).padStart(5)).join(' ')
}`)

0 comments on commit 94e2e64

Please sign in to comment.