fixed \-1\
I had forgotten; added basic mean tests
This commit is contained in:
parent
54cd636524
commit
9dcac8dd48
|
@ -77,6 +77,23 @@ describe("(Symbolic) mean", () => {
|
||||||
meanValue->unpackFloat->expect->ExpectJs.toBeFalsy
|
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(
|
testAll(
|
||||||
"of lognormal distributions",
|
"of lognormal distributions",
|
||||||
list{(2.0, 4.0), (1e-7, 1e-2), (-1e6, 10.0), (1e3, -1e2), (-1e8, -1e4), (1e2, 1e-5)},
|
list{(2.0, 4.0), (1e-7, 1e-2), (-1e6, 10.0), (1e3, -1e2), (-1e8, -1e4), (1e2, 1e-5)},
|
||||||
|
|
|
@ -135,7 +135,7 @@ module Beta = {
|
||||||
let fromMeanAndStdev = (mean, stdev) => {
|
let fromMeanAndStdev = (mean, stdev) => {
|
||||||
// https://en.wikipedia.org/wiki/Beta_distribution#Mean_and_variance
|
// https://en.wikipedia.org/wiki/Beta_distribution#Mean_and_variance
|
||||||
let var = stdev *. stdev
|
let var = stdev *. stdev
|
||||||
let sampleSize = mean *. (1.0 -. mean) /. var
|
let sampleSize = mean *. (1.0 -. mean) /. var -. 1.0
|
||||||
mean->fromMeanAndSampleSize(sampleSize)
|
mean->fromMeanAndSampleSize(sampleSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user