fixed \-1\ I had forgotten; added basic mean tests

This commit is contained in:
Quinn Dougherty 2022-06-30 12:20:50 -04:00
parent 54cd636524
commit 9dcac8dd48
2 changed files with 18 additions and 1 deletions

View File

@ -77,6 +77,23 @@ describe("(Symbolic) mean", () => {
meanValue->unpackFloat->expect->ExpectJs.toBeFalsy
})
testAll(
"of beta distributions from mean and standard dev",
list{(0.39, 0.1), (0.08, 0.1), (0.8, 0.3)},
tup => {
let (mean, stdev) = tup
let betaDistribution = SymbolicDist.Beta.fromMeanAndStdev(mean, stdev)
let meanValue =
betaDistribution->E.R2.fmap(d =>
run(FromDist(ToFloat(#Mean), d->DistributionTypes.Symbolic))
)
switch meanValue {
| Ok(value) => value->unpackFloat->expect->toBeCloseTo(mean)
| Error(err) => err->expect->toBe("shouldn't happen")
}
},
)
testAll(
"of lognormal distributions",
list{(2.0, 4.0), (1e-7, 1e-2), (-1e6, 10.0), (1e3, -1e2), (-1e8, -1e4), (1e2, 1e-5)},

View File

@ -135,7 +135,7 @@ module Beta = {
let fromMeanAndStdev = (mean, stdev) => {
// https://en.wikipedia.org/wiki/Beta_distribution#Mean_and_variance
let var = stdev *. stdev
let sampleSize = mean *. (1.0 -. mean) /. var
let sampleSize = mean *. (1.0 -. mean) /. var -. 1.0
mean->fromMeanAndSampleSize(sampleSize)
}
}