From 7a419742ad5f91afd07ff6a7deb828ad8c50632a Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Mon, 4 Jul 2022 09:57:00 -0400 Subject: [PATCH] moved error message sooner for invalid mean and stdev --- .../Distributions/SymbolicDist/SymbolicDist.res | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res index 0b192b5f..e7471ffa 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res +++ b/packages/squiggle-lang/src/rescript/Distributions/SymbolicDist/SymbolicDist.res @@ -129,14 +129,18 @@ module Beta = { // https://en.wikipedia.org/wiki/Beta_distribution#Mean_and_sample_size let alpha = mean *. sampleSize let beta = (1.0 -. mean) *. sampleSize - alpha->make(beta) + make(alpha, 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 -. 1.0 - mean->fromMeanAndSampleSize(sampleSize) + if !(0.0 < stdev && stdev <= 0.5) || !(0.0 <= mean && mean <= 1.0) { + "Beta mean must be in [0,1] and stdev must be in (1,0.5]"->Error + } else { + let var = stdev *. stdev + let sampleSize = mean *. (1.0 -. mean) /. var -. 1.0 + fromMeanAndSampleSize(mean, sampleSize) + } } }