From 32a881d06a7785537c577d3dea92c8759050b48b Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Thu, 5 May 2022 10:38:33 -0400 Subject: [PATCH] Call Jstat for mean instead of calculate it Value: [1e-8 to 1e-4] --- .../__tests__/Distributions/Dotwise_test.res | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Distributions/Dotwise_test.res b/packages/squiggle-lang/__tests__/Distributions/Dotwise_test.res index 9a77d3e5..7725aa54 100644 --- a/packages/squiggle-lang/__tests__/Distributions/Dotwise_test.res +++ b/packages/squiggle-lang/__tests__/Distributions/Dotwise_test.res @@ -16,12 +16,20 @@ describe("dotSubtract", () => { mkExponential(rate), ) let meanResult = E.R2.bind(DistributionOperation.Constructors.mean(~env), dotDifference) - let meanAnalytical = mean -. 1.0 /. rate + let meanAnalytical = + mean -. + SymbolicDist.Exponential.mean({rate: rate})->E.R2.toExn( + "On trusted input this should never happen", + ) switch meanResult { | Ok(meanValue) => meanValue->expect->toBeCloseTo(meanAnalytical) | Error(_) => raise(MeanFailed) } }) + /* + It seems like this test should work, and it's plausible that + there's some bug in `pointwiseSubtract` + */ Skip.test("mean of normal minus exponential (property)", () => { assert_( property2(float_(), floatRange(1e-5, 1e5), (mean, rate) => { @@ -33,12 +41,11 @@ describe("dotSubtract", () => { ) let meanResult = E.R2.bind(DistributionOperation.Constructors.mean(~env), dotDifference) // according to algebra or random variables, - let meanAnalytical = mean -. 1.0 /. rate - Js.Console.log3( - mean, - rate, - E.R.fmap(x => abs_float(x -. meanAnalytical) /. abs_float(meanAnalytical), meanResult), - ) + let meanAnalytical = + mean -. + SymbolicDist.Exponential.mean({rate: rate})->E.R2.toExn( + "On trusted input this should never happen", + ) switch meanResult { | Ok(meanValue) => abs_float(meanValue -. meanAnalytical) /. abs_float(meanValue) < 1e-2 // 1% relative error | Error(err) => err === DistributionTypes.OperationError(DivisionByZeroError)