From 350e42088437902e0702cd6564df3e8edccf8cd5 Mon Sep 17 00:00:00 2001 From: Sam Nolan Date: Tue, 26 Apr 2022 13:25:45 -0400 Subject: [PATCH] Add isNormalized to Continuous --- .../Distributions/SampleSetDist_ToPointSet_test.res | 4 +--- .../src/rescript/Distributions/PointSetDist/Continuous.res | 5 +++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/squiggle-lang/__tests__/Distributions/SampleSetDist_ToPointSet_test.res b/packages/squiggle-lang/__tests__/Distributions/SampleSetDist_ToPointSet_test.res index 2145220b..a2c7baa1 100644 --- a/packages/squiggle-lang/__tests__/Distributions/SampleSetDist_ToPointSet_test.res +++ b/packages/squiggle-lang/__tests__/Distributions/SampleSetDist_ToPointSet_test.res @@ -14,9 +14,7 @@ describe("Converting from a sample set distribution", () => { integralSumCache: None, integralCache: None, } - let fullShape = Continuous.updateIntegralCache(Some(Continuous.T.integral(c)), c) - let endY = Continuous.T.integralEndY(fullShape) - expect(endY)->toBeCloseTo(1.) + expect(Continuous.isNormalized(c))->toBe(true) }) }) diff --git a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/Continuous.res b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/Continuous.res index 5e44f900..905ffdb1 100644 --- a/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/Continuous.res +++ b/packages/squiggle-lang/src/rescript/Distributions/PointSetDist/Continuous.res @@ -269,6 +269,11 @@ module T = Dist({ XYShape.Analysis.getVarianceDangerously(t, mean, Analysis.getMeanOfSquares) }) +let isNormalized = (t: t): bool => { + let areaUnderIntegral = t |> updateIntegralCache(Some(T.integral(t))) |> T.integralEndY + areaUnderIntegral -. 1. < 1e-7 +} + let downsampleEquallyOverX = (length, t): t => t |> shapeMap(XYShape.XsConversion.proportionEquallyOverX(length))