From 51711512fb191f8c323d70edc07b58606b8c038d Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Mon, 4 Apr 2022 11:47:34 -0400 Subject: [PATCH] Removed Domain from DistPlus --- .../__tests__/DistTypes__Test.res | 89 ------------------- .../src/rescript/pointSetDist/DistPlus.res | 15 +--- .../rescript/pointSetDist/PointSetTypes.res | 39 -------- 3 files changed, 2 insertions(+), 141 deletions(-) delete mode 100644 packages/squiggle-lang/__tests__/DistTypes__Test.res diff --git a/packages/squiggle-lang/__tests__/DistTypes__Test.res b/packages/squiggle-lang/__tests__/DistTypes__Test.res deleted file mode 100644 index fb09d6d9..00000000 --- a/packages/squiggle-lang/__tests__/DistTypes__Test.res +++ /dev/null @@ -1,89 +0,0 @@ -open Jest -open Expect - -let makeTest = (~only=false, str, item1, item2) => - only - ? Only.test(str, () => expect(item1) -> toEqual(item2)) - : test(str, () => expect(item1) -> toEqual(item2)) - -describe("PointSetTypes", () => - describe("Domain", () => { - let makeComplete = (yPoint, expectation) => - makeTest( - "With input: " ++ Js.Float.toString(yPoint), - PointSetTypes.Domain.yPointToSubYPoint(Complete, yPoint), - expectation, - ) - let makeSingle = (direction: [#left | #right], excludingProbabilityMass, yPoint, expectation) => - makeTest( - "Excluding: " ++ - (Js.Float.toString(excludingProbabilityMass) ++ - (" and yPoint: " ++ Js.Float.toString(yPoint))), - PointSetTypes.Domain.yPointToSubYPoint( - direction == #left - ? LeftLimited({xPoint: 3.0, excludingProbabilityMass: excludingProbabilityMass}) - : RightLimited({xPoint: 3.0, excludingProbabilityMass: excludingProbabilityMass}), - yPoint, - ), - expectation, - ) - let makeDouble = (domain, yPoint, expectation) => - makeTest("Excluding: limits", PointSetTypes.Domain.yPointToSubYPoint(domain, yPoint), expectation) - - describe("With Complete Domain", () => { - makeComplete(0.0, Some(0.0)) - makeComplete(0.6, Some(0.6)) - makeComplete(1.0, Some(1.0)) - }) - describe("With Left Limit", () => { - makeSingle(#left, 0.5, 1.0, Some(1.0)) - makeSingle(#left, 0.5, 0.75, Some(0.5)) - makeSingle(#left, 0.8, 0.9, Some(0.5)) - makeSingle(#left, 0.5, 0.4, None) - makeSingle(#left, 0.5, 0.5, Some(0.0)) - }) - describe("With Right Limit", () => { - makeSingle(#right, 0.5, 1.0, None) - makeSingle(#right, 0.5, 0.25, Some(0.5)) - makeSingle(#right, 0.8, 0.5, None) - makeSingle(#right, 0.2, 0.2, Some(0.25)) - makeSingle(#right, 0.5, 0.5, Some(1.0)) - makeSingle(#right, 0.5, 0.0, Some(0.0)) - makeSingle(#right, 0.5, 0.5, Some(1.0)) - }) - describe("With Left and Right Limit", () => { - makeDouble( - LeftAndRightLimited( - {excludingProbabilityMass: 0.25, xPoint: 3.0}, - {excludingProbabilityMass: 0.25, xPoint: 10.0}, - ), - 0.5, - Some(0.5), - ) - makeDouble( - LeftAndRightLimited( - {excludingProbabilityMass: 0.1, xPoint: 3.0}, - {excludingProbabilityMass: 0.1, xPoint: 10.0}, - ), - 0.2, - Some(0.125), - ) - makeDouble( - LeftAndRightLimited( - {excludingProbabilityMass: 0.1, xPoint: 3.0}, - {excludingProbabilityMass: 0.1, xPoint: 10.0}, - ), - 0.1, - Some(0.0), - ) - makeDouble( - LeftAndRightLimited( - {excludingProbabilityMass: 0.1, xPoint: 3.0}, - {excludingProbabilityMass: 0.1, xPoint: 10.0}, - ), - 0.05, - None, - ) - }) - }) -) diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/DistPlus.res b/packages/squiggle-lang/src/rescript/pointSetDist/DistPlus.res index e1ece63d..2b1688b0 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/DistPlus.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/DistPlus.res @@ -8,25 +8,22 @@ let make = ( ~pointSetDist, ~squiggleString, - ~domain=Complete, (), ) : t => { let integral = pointSetDistIntegral(pointSetDist); - {pointSetDist, domain, integralCache: integral, squiggleString}; + {pointSetDist, integralCache: integral, squiggleString}; }; let update = ( ~pointSetDist=?, ~integralCache=?, - ~domain=?, ~squiggleString=?, t: t, ) => { pointSetDist: E.O.default(t.pointSetDist, pointSetDist), integralCache: E.O.default(t.integralCache, integralCache), - domain: E.O.default(t.domain, domain), squiggleString: E.O.default(t.squiggleString, squiggleString), }; @@ -35,12 +32,6 @@ let updateShape = (pointSetDist, t) => { update(~pointSetDist, ~integralCache, t); }; -let domainIncludedProbabilityMass = (t: t) => - Domain.includedProbabilityMass(t.domain); - -let domainIncludedProbabilityMassAdjustment = (t: t, f) => - f *. Domain.includedProbabilityMass(t.domain); - let toPointSetDist = ({pointSetDist, _}: t) => pointSetDist; let pointSetDistFn = (fn, {pointSetDist}: t) => fn(pointSetDist); @@ -70,8 +61,7 @@ module T = let xToY = (f, t: t) => t |> toPointSetDist - |> PointSetDist.T.xToY(f) - |> MixedPoint.fmap(domainIncludedProbabilityMassAdjustment(t)); + |> PointSetDist.T.xToY(f); let minX = pointSetDistFn(PointSetDist.T.minX); let maxX = pointSetDistFn(PointSetDist.T.maxX); @@ -112,7 +102,6 @@ module T = f, toPointSetDist(t), ) - |> domainIncludedProbabilityMassAdjustment(t); }; // TODO: This part is broken when there is a limit, if this is supposed to be taken into account. diff --git a/packages/squiggle-lang/src/rescript/pointSetDist/PointSetTypes.res b/packages/squiggle-lang/src/rescript/pointSetDist/PointSetTypes.res index e2e17a94..15fbd4c3 100644 --- a/packages/squiggle-lang/src/rescript/pointSetDist/PointSetTypes.res +++ b/packages/squiggle-lang/src/rescript/pointSetDist/PointSetTypes.res @@ -74,49 +74,10 @@ type generationSource = @genType type distPlus = { pointSetDist: pointSetDist, - domain: domain, integralCache: continuousShape, squiggleString: option, } -module Domain = { - let excludedProbabilityMass = (t: domain) => - switch t { - | Complete => 0.0 - | LeftLimited({excludingProbabilityMass}) => excludingProbabilityMass - | RightLimited({excludingProbabilityMass}) => excludingProbabilityMass - | LeftAndRightLimited({excludingProbabilityMass: l}, {excludingProbabilityMass: r}) => l +. r - } - - let includedProbabilityMass = (t: domain) => 1.0 -. excludedProbabilityMass(t) - - let initialProbabilityMass = (t: domain) => - switch t { - | Complete - | RightLimited(_) => 0.0 - | LeftLimited({excludingProbabilityMass}) => excludingProbabilityMass - | LeftAndRightLimited({excludingProbabilityMass}, _) => excludingProbabilityMass - } - - let normalizeProbabilityMass = (t: domain) => 1. /. excludedProbabilityMass(t) - - let yPointToSubYPoint = (t: domain, yPoint) => - switch t { - | Complete => Some(yPoint) - | LeftLimited({excludingProbabilityMass}) if yPoint < excludingProbabilityMass => None - | LeftLimited({excludingProbabilityMass}) if yPoint >= excludingProbabilityMass => - Some((yPoint -. excludingProbabilityMass) /. includedProbabilityMass(t)) - | RightLimited({excludingProbabilityMass}) if yPoint > 1. -. excludingProbabilityMass => None - | RightLimited({excludingProbabilityMass}) if yPoint <= 1. -. excludingProbabilityMass => - Some(yPoint /. includedProbabilityMass(t)) - | LeftAndRightLimited({excludingProbabilityMass: l}, _) if yPoint < l => None - | LeftAndRightLimited(_, {excludingProbabilityMass: r}) if yPoint > 1.0 -. r => None - | LeftAndRightLimited({excludingProbabilityMass: l}, _) => - Some((yPoint -. l) /. includedProbabilityMass(t)) - | _ => None - } -} - type mixedPoint = { continuous: float, discrete: float,