diff --git a/src/Experimental/LimitedDomainCdf.re b/src/Experimental/LimitedDomainCdf.re new file mode 100644 index 00000000..126cf5d1 --- /dev/null +++ b/src/Experimental/LimitedDomainCdf.re @@ -0,0 +1,33 @@ +// type t = { + // distribution: Types.ContinuousDistribution.t, + // domainMaxX: float, + // }; + // let make = (~distribution, ~domainMaxX): t => {distribution, domainMaxX}; + // let fromCdf = + // ( + // cdf: Types.ContinuousDistribution.t, + // domainMaxX: float, + // probabilityAtMaxX: float, + // ) => { + // let distribution: Types.ContinuousDistribution.t = { + // xs: cdf.xs, + // ys: cdf.ys |> E.A.fmap(r => r *. probabilityAtMaxX), + // }; + // {distribution, domainMaxX}; + // }; + // let _lastElement = (a: array('a)) => + // switch (Belt.Array.size(a)) { + // | 0 => None + // | n => Belt.Array.get(a, n) + // }; + // let probabilityBeforeDomainMax = (t: t) => _lastElement(t.distribution.ys); + // let domainMaxX = (t: t) => t.domainMaxX /* CdfLibrary.Distribution.findX(yPoint, t.distribution)*/; + // let probabilityDistribution = (t: t) => + // t.distribution |> CdfLibrary.Distribution.toPdf; + // let probability = (t: t, xPoint: float) => + // CdfLibrary.Distribution.findY(xPoint, probabilityDistribution(t)); + // let probabilityInverse = (t: t, yPoint: float) => + // CdfLibrary.Distribution.findX(yPoint, probabilityDistribution(t)); + // let cumulativeProbability = (t: t, xPoint: float) => + // CdfLibrary.Distribution.findY(xPoint, t.distribution); + /* let cumulativeProbabilityInverse = (t: t, yPoint: float) =*/ \ No newline at end of file diff --git a/src/Experimental/TimeLimitedDomainCdf.re b/src/Experimental/TimeLimitedDomainCdf.re new file mode 100644 index 00000000..9c4c3b67 --- /dev/null +++ b/src/Experimental/TimeLimitedDomainCdf.re @@ -0,0 +1,38 @@ +// open TimeTypes; + // type t = { + // timeVector, + // limitedDomainCdf: LimitedDomainCdf.t, + // }; + // let make = + // ( + // ~timeVector: timeVector, + // ~distribution: Types.ContinuousDistribution.t, + // ~probabilityAtMaxX: float, + // ~maxX: [ | `time(MomentRe.Moment.t) | `x(float)], + // ) + // : t => { + // let domainMaxX = + // switch (maxX) { + // | `time(m) => TimePoint.fromMoment(timeVector, m) + // | `x(r) => r + // }; + // let limitedDomainCdf = + // LimitedDomainCdf.fromCdf(distribution, domainMaxX, probabilityAtMaxX); + // {timeVector, limitedDomainCdf}; + // }; + // let probabilityBeforeDomainMax = (t: t) => + // LimitedDomainCdf.probabilityBeforeDomainMax(t.limitedDomainCdf); + // let domainMaxX = (t: t) => + // LimitedDomainCdf.probabilityBeforeDomainMax(t.limitedDomainCdf) /* |> (r => RelativeTimePoint.toTime(t.timeVector, XValue(r)))*/; + // let probability = (t: t, m: MomentRe.Moment.t) => { + // RelativeTimePoint.toXValue(t.timeVector, Time(m)) + // |> LimitedDomainCdf.probability(t.limitedDomainCdf); + // }; + // let probabilityInverse = (t: t, y: float) => + // LimitedDomainCdf.probabilityInverse(t.limitedDomainCdf, y) + // |> (r => RelativeTimePoint.toTime(t.timeVector, XValue(r))); + // let cumulativeProbability = (t: t, m: MomentRe.Moment.t) => + // RelativeTimePoint.toXValue(t.timeVector, Time(m)) + // |> LimitedDomainCdf.cumulativeProbability(t.limitedDomainCdf); + // let cumulativeProbabilityInverse = (t: t, y: float) => + /* LimitedDomainCdf.cumulativeProbabilityInverse(t.limitedDomainCdf, y*/ \ No newline at end of file diff --git a/src/LimitedDomainCdf.re b/src/LimitedDomainCdf.re deleted file mode 100644 index 3eeeda59..00000000 --- a/src/LimitedDomainCdf.re +++ /dev/null @@ -1,43 +0,0 @@ -type t = { - distribution: Types.ContinuousDistribution.t, - domainMaxX: float, -}; - -let make = (~distribution, ~domainMaxX): t => {distribution, domainMaxX}; - -let fromCdf = - ( - cdf: Types.ContinuousDistribution.t, - domainMaxX: float, - probabilityAtMaxX: float, - ) => { - let distribution: Types.ContinuousDistribution.t = { - xs: cdf.xs, - ys: cdf.ys |> E.A.fmap(r => r *. probabilityAtMaxX), - }; - {distribution, domainMaxX}; -}; - -let _lastElement = (a: array('a)) => - switch (Belt.Array.size(a)) { - | 0 => None - | n => Belt.Array.get(a, n) - }; - -let probabilityBeforeDomainMax = (t: t) => _lastElement(t.distribution.ys); - -let domainMaxX = (t: t) => t.domainMaxX /* CdfLibrary.Distribution.findX(yPoint, t.distribution)*/; - -// let probabilityDistribution = (t: t) => -// t.distribution |> CdfLibrary.Distribution.toPdf; - -// let probability = (t: t, xPoint: float) => -// CdfLibrary.Distribution.findY(xPoint, probabilityDistribution(t)); - -// let probabilityInverse = (t: t, yPoint: float) => -// CdfLibrary.Distribution.findX(yPoint, probabilityDistribution(t)); - -// let cumulativeProbability = (t: t, xPoint: float) => -// CdfLibrary.Distribution.findY(xPoint, t.distribution); - -// let cumulativeProbabilityInverse = (t: t, yPoint: float) => \ No newline at end of file diff --git a/src/TimeLimitedDomainCdf.re b/src/TimeLimitedDomainCdf.re deleted file mode 100644 index aa8e08c9..00000000 --- a/src/TimeLimitedDomainCdf.re +++ /dev/null @@ -1,46 +0,0 @@ -open TimeTypes; - -type t = { - timeVector, - limitedDomainCdf: LimitedDomainCdf.t, -}; - -let make = - ( - ~timeVector: timeVector, - ~distribution: Types.ContinuousDistribution.t, - ~probabilityAtMaxX: float, - ~maxX: [ | `time(MomentRe.Moment.t) | `x(float)], - ) - : t => { - let domainMaxX = - switch (maxX) { - | `time(m) => TimePoint.fromMoment(timeVector, m) - | `x(r) => r - }; - let limitedDomainCdf = - LimitedDomainCdf.fromCdf(distribution, domainMaxX, probabilityAtMaxX); - {timeVector, limitedDomainCdf}; -}; - -let probabilityBeforeDomainMax = (t: t) => - LimitedDomainCdf.probabilityBeforeDomainMax(t.limitedDomainCdf); - -let domainMaxX = (t: t) => - LimitedDomainCdf.probabilityBeforeDomainMax(t.limitedDomainCdf) /* |> (r => RelativeTimePoint.toTime(t.timeVector, XValue(r)))*/; - -// let probability = (t: t, m: MomentRe.Moment.t) => { -// RelativeTimePoint.toXValue(t.timeVector, Time(m)) -// |> LimitedDomainCdf.probability(t.limitedDomainCdf); -// }; - -// let probabilityInverse = (t: t, y: float) => -// LimitedDomainCdf.probabilityInverse(t.limitedDomainCdf, y) -// |> (r => RelativeTimePoint.toTime(t.timeVector, XValue(r))); - -// let cumulativeProbability = (t: t, m: MomentRe.Moment.t) => -// RelativeTimePoint.toXValue(t.timeVector, Time(m)) -// |> LimitedDomainCdf.cumulativeProbability(t.limitedDomainCdf); - -// let cumulativeProbabilityInverse = (t: t, y: float) => -// LimitedDomainCdf.cumulativeProbabilityInverse(t.limitedDomainCdf, y) \ No newline at end of file diff --git a/src/lib/DistributionTypes.re b/src/lib/DistributionTypes.re index 498c33de..c8b4db27 100644 --- a/src/lib/DistributionTypes.re +++ b/src/lib/DistributionTypes.re @@ -9,15 +9,13 @@ type domain = | RightLimited(domainLimit) | LeftAndRightLimited(domainLimit, domainLimit); -type continuousShape = { +type xyShape = { xs: array(float), ys: array(float), }; +type continuousShape = xyShape; -type discreteShape = { - xs: array(float), - ys: array(float), -}; +type discreteShape = xyShape; type mixedShape = { continuous: continuousShape, diff --git a/src/lib/MixedShapeBuilder.re b/src/lib/MixedShapeBuilder.re new file mode 100644 index 00000000..9ed0ca0a --- /dev/null +++ b/src/lib/MixedShapeBuilder.re @@ -0,0 +1,63 @@ +type assumption = + | ADDS_TO_1 + | ADDS_TO_CORRECT_PROBABILITY; +type assumptions = { + continuous: assumption, + discrete: assumption, + discreteProbabilityMass: option(float), +}; +let build = (~continuous, ~discrete, ~assumptions) => + switch (assumptions) { + | { + continuous: ADDS_TO_CORRECT_PROBABILITY, + discrete: ADDS_TO_CORRECT_PROBABILITY, + discreteProbabilityMass: Some(r), + } => + // TODO: Fix this, it's wrong :( + Some( + Shape.Mixed.make( + ~continuous, + ~discrete, + ~discreteProbabilityMassFraction=r, + ), + ) + | { + continuous: ADDS_TO_1, + discrete: ADDS_TO_1, + discreteProbabilityMass: Some(r), + } => + Some( + Shape.Mixed.make( + ~continuous, + ~discrete, + ~discreteProbabilityMassFraction=r, + ), + ) + | { + continuous: ADDS_TO_1, + discrete: ADDS_TO_1, + discreteProbabilityMass: None, + } => + None + | { + continuous: ADDS_TO_CORRECT_PROBABILITY, + discrete: ADDS_TO_1, + discreteProbabilityMass: None, + } => + None + | { + continuous: ADDS_TO_1, + discrete: ADDS_TO_CORRECT_PROBABILITY, + discreteProbabilityMass: None, + } => + let discreteProbabilityMassFraction = Shape.Discrete.ySum(discrete); + let discrete = Shape.Discrete.scaleYToTotal(1.0, discrete); + Some( + Shape.Mixed.make( + ~continuous, + ~discrete, + ~discreteProbabilityMassFraction, + ), + ); + | _ => None + }; \ No newline at end of file diff --git a/src/lib/Prop.re b/src/lib/Prop.re index eac149ff..92827695 100644 --- a/src/lib/Prop.re +++ b/src/lib/Prop.re @@ -16,10 +16,6 @@ module Value = { | Probability(float) | Conditional(conditional) | GenericDistribution(DistributionTypes.genericDistribution) - | TimeLimitedDomainCdf(TimeLimitedDomainCdf.t) - | TimeLimitedDomainCdfLazy( - (string => Types.ContinuousDistribution.t) => TimeLimitedDomainCdf.t, - ) | ConditionalArray(array(conditional)) | FloatCdf(string); @@ -33,8 +29,6 @@ module Value = { | SelectSingle(r) => r | FloatCdf(r) => r | GenericDistribution(_) => "" - | TimeLimitedDomainCdf(_) => "" - | TimeLimitedDomainCdfLazy(_) => "" | Probability(r) => (r *. 100. |> Js.Float.toFixed) ++ "%" | DateTime(r) => r |> MomentRe.Moment.defaultFormat | FloatPoint(r) => r |> Js.Float.toFixed @@ -78,13 +72,6 @@ module Value = { | None => "Something went wrong" |> ReasonReact.string | _ =>
}; - | TimeLimitedDomainCdfLazy(_) => - | TimeLimitedDomainCdf(r) => - let cdf: Types.ContinuousDistribution.t = - r.limitedDomainCdf.distribution; - <> -