From 7f0ab442ad5bf51221da243f2cb82a4b63e67711 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Sun, 23 Feb 2020 12:49:33 +0000 Subject: [PATCH] Renames to use distPlus and distPlusIngredients --- showcase/entries/Continuous.re | 12 ++---- ...{ComplexPowerChart.re => DistPlusChart.re} | 43 ++++++++----------- src/core/DistFunctor.re | 10 ++--- src/core/DistPlusIngredients.re | 29 +++++++++++++ src/core/DistributionTypes.re | 14 +++--- src/core/GenericDistribution.re | 29 ------------- src/interface/FormBuilder.re | 6 +-- src/interface/Prop.re | 4 +- src/models/EAFunds.re | 32 ++++++-------- src/models/GlobalCatastrophe.re | 8 ++-- 10 files changed, 87 insertions(+), 100 deletions(-) rename src/components/charts/{ComplexPowerChart.re => DistPlusChart.re} (55%) create mode 100644 src/core/DistPlusIngredients.re delete mode 100644 src/core/GenericDistribution.re diff --git a/showcase/entries/Continuous.re b/showcase/entries/Continuous.re index 6ec0ba41..8448d044 100644 --- a/showcase/entries/Continuous.re +++ b/showcase/entries/Continuous.re @@ -1,22 +1,18 @@ // "mm(floor(uniform(30,35)), normal(50,20), [.25,.5])", let timeDist = - GenericDistribution.make( - ~generationSource= - GuesstimatorString("mm(floor(normal(30,2)), normal(39,1), [.5,.5])"), + DistPlusIngredients.make( + ~guesstimatorString="mm(floor(normal(30,2)), normal(39,1), [.5,.5])", ~domain=Complete, ~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `days}), (), ) - |> GenericDistribution.toComplexPower(~sampleCount=1000); + |> DistPlusIngredients.toDistPlus(~sampleCount=1000); let distributions = () =>

{"Basic Mixed Distribution" |> ReasonReact.string}

- {timeDist - |> E.O.React.fmapOrNull(complexPower => - - )} + {timeDist |> E.O.React.fmapOrNull(distPlus => )}

{"Simple Continuous" |> ReasonReact.string}

; diff --git a/src/components/charts/ComplexPowerChart.re b/src/components/charts/DistPlusChart.re similarity index 55% rename from src/components/charts/ComplexPowerChart.re rename to src/components/charts/DistPlusChart.re index 8969aa34..5bb7ff23 100644 --- a/src/components/charts/ComplexPowerChart.re +++ b/src/components/charts/DistPlusChart.re @@ -1,16 +1,13 @@ -module ComplexPowerChart = { +module DistPlusChart = { [@react.component] - let make = (~complexPower: DistributionTypes.complexPower, ~onHover) => { - open DistFunctor.ComplexPower; - let discrete = complexPower |> T.toDiscrete; + let make = (~distPlus: DistributionTypes.distPlus, ~onHover) => { + open DistFunctor.DistPlus; + let discrete = distPlus |> T.toDiscrete; let continuous = - complexPower - |> T.toContinuous - |> E.O.fmap(DistFunctor.Continuous.getShape); - let minX = T.minX(complexPower); - let maxX = T.maxX(complexPower); - let timeScale = - complexPower.unit |> DistributionTypes.DistributionUnit.toJson; + distPlus |> T.toContinuous |> E.O.fmap(DistFunctor.Continuous.getShape); + let minX = T.minX(distPlus); + let maxX = T.maxX(distPlus); + let timeScale = distPlus.unit |> DistributionTypes.DistributionUnit.toJson; { - open DistFunctor.ComplexPower; - let integral = - DistFunctor.ComplexPower.T.Integral.get(~cache=None, complexPower); + let make = (~distPlus: DistributionTypes.distPlus, ~onHover) => { + open DistFunctor.DistPlus; + let integral = DistFunctor.DistPlus.T.Integral.get(~cache=None, distPlus); let continuous = integral |> T.toContinuous @@ -36,8 +32,7 @@ module IntegralChart = { |> E.O.fmap(DistFunctor.Continuous.getShape); let minX = T.minX(integral); let maxX = T.maxX(integral); - let timeScale = - complexPower.unit |> DistributionTypes.DistributionUnit.toJson; + let timeScale = distPlus.unit |> DistributionTypes.DistributionUnit.toJson; { +let make = (~distPlus: DistributionTypes.distPlus) => { let (x, setX) = React.useState(() => 0.); let chart = React.useMemo1( - () => { {setX(_ => r)}} />}, - [|complexPower|], + () => { {setX(_ => r)}} />}, + [|distPlus|], ); let chart2 = React.useMemo1( - () => { {setX(_ => r)}} />}, - [|complexPower|], + () => { {setX(_ => r)}} />}, + [|distPlus|], );
chart @@ -80,8 +75,8 @@ let make = (~complexPower: DistributionTypes.complexPower) => { {x |> E.Float.toString |> ReasonReact.string} - {complexPower - |> DistFunctor.ComplexPower.T.Integral.xToY(~cache=None, x) + {distPlus + |> DistFunctor.DistPlus.T.Integral.xToY(~cache=None, x) |> E.Float.with2DigitsPrecision |> ReasonReact.string} diff --git a/src/core/DistFunctor.re b/src/core/DistFunctor.re index 8cd0ddf8..56ec854e 100644 --- a/src/core/DistFunctor.re +++ b/src/core/DistFunctor.re @@ -388,7 +388,7 @@ module Shape = { }); }; -module ComplexPower = { +module DistPlus = { open DistributionTypes; let make = ( @@ -398,7 +398,7 @@ module ComplexPower = { ~unit=UnspecifiedDistribution, (), ) - : complexPower => { + : distPlus => { let integral = Shape.T.Integral.get(~cache=None, shape); {shape, domain, integralCache: integral, unit, guesstimatorString}; }; @@ -409,7 +409,7 @@ module ComplexPower = { ~domain=?, ~unit=?, ~guesstimatorString=?, - t: complexPower, + t: distPlus, ) => { shape: E.O.default(t.shape, shape), integralCache: E.O.default(t.integralCache, integralCache), @@ -420,8 +420,8 @@ module ComplexPower = { module T = Dist({ - type t = DistributionTypes.complexPower; - type integral = DistributionTypes.complexPower; + type t = DistributionTypes.distPlus; + type integral = DistributionTypes.distPlus; let toShape = ({shape, _}: t) => shape; let shapeFn = (fn, t: t) => t |> toShape |> fn; let toContinuous = shapeFn(Shape.T.toContinuous); diff --git a/src/core/DistPlusIngredients.re b/src/core/DistPlusIngredients.re new file mode 100644 index 00000000..d71c8ed2 --- /dev/null +++ b/src/core/DistPlusIngredients.re @@ -0,0 +1,29 @@ +open DistributionTypes; + +let make = + (~guesstimatorString, ~domain=Complete, ~unit=UnspecifiedDistribution, ()) + : distPlusIngredients => { + guesstimatorString, + domain, + unit, +}; + +let toDistPlus = (~sampleCount, t: distPlusIngredients) => { + let shape = + Guesstimator.stringToMixedShape( + ~string=t.guesstimatorString, + ~sampleCount, + (), + ) + |> E.O.bind(_, DistFunctor.Mixed.clean); + shape + |> E.O.fmap(shape => + DistFunctor.DistPlus.make( + ~shape, + ~domain=t.domain, + ~unit=t.unit, + ~guesstimatorString=None, + (), + ) + ); +}; \ No newline at end of file diff --git a/src/core/DistributionTypes.re b/src/core/DistributionTypes.re index 5b7b702a..35173501 100644 --- a/src/core/DistributionTypes.re +++ b/src/core/DistributionTypes.re @@ -52,13 +52,7 @@ type distributionUnit = | UnspecifiedDistribution | TimeDistribution(TimeTypes.timeVector); -type genericDistribution = { - generationSource, - domain, - unit: distributionUnit, -}; - -type complexPower = { +type distPlus = { shape, domain, integralCache: continuousShape, @@ -66,6 +60,12 @@ type complexPower = { guesstimatorString: option(string), }; +type distPlusIngredients = { + guesstimatorString: string, + domain, + unit: distributionUnit, +}; + module DistributionUnit = { let toJson = (distributionUnit: distributionUnit) => switch (distributionUnit) { diff --git a/src/core/GenericDistribution.re b/src/core/GenericDistribution.re deleted file mode 100644 index 7cde2e66..00000000 --- a/src/core/GenericDistribution.re +++ /dev/null @@ -1,29 +0,0 @@ -open DistributionTypes; - -let make = - (~generationSource, ~domain=Complete, ~unit=UnspecifiedDistribution, ()) - : genericDistribution => { - generationSource, - domain, - unit, -}; - -let toComplexPower = (~sampleCount, t: genericDistribution) => { - let shape = - switch (t.generationSource) { - | GuesstimatorString(s) => - Guesstimator.stringToMixedShape(~string=s, ~sampleCount, ()) - |> E.O.bind(_, DistFunctor.Mixed.clean) - | Shape(shape) => Some(shape) - }; - shape - |> E.O.fmap(shape => - DistFunctor.ComplexPower.make( - ~shape, - ~domain=t.domain, - ~unit=t.unit, - ~guesstimatorString=None, - (), - ) - ); -}; \ No newline at end of file diff --git a/src/interface/FormBuilder.re b/src/interface/FormBuilder.re index 5d387002..8849019a 100644 --- a/src/interface/FormBuilder.re +++ b/src/interface/FormBuilder.re @@ -17,12 +17,12 @@ let propValue = (t: Prop.Value.t) => { switch (t) { | SelectSingle(r) => r |> ReasonReact.string | ConditionalArray(r) => "Array" |> ReasonReact.string - | GenericDistribution(r) => + | DistPlusIngredients(r) => let newDistribution = - GenericDistribution.toComplexPower(~sampleCount=1000, r); + DistPlusIngredients.toDistPlus(~sampleCount=1000, r); switch (newDistribution) { | Some(distribution) => -
+
| None => "Something went wrong" |> ReasonReact.string }; | FloatCdf(_) =>
diff --git a/src/interface/Prop.re b/src/interface/Prop.re index c2a33e23..89971d8e 100644 --- a/src/interface/Prop.re +++ b/src/interface/Prop.re @@ -9,7 +9,7 @@ module Value = { | DateTime(MomentRe.Moment.t) | FloatPoint(float) | Probability(float) - | GenericDistribution(DistributionTypes.genericDistribution) + | DistPlusIngredients(DistributionTypes.distPlusIngredients) | ConditionalArray(array(conditional)) | FloatCdf(string); @@ -85,7 +85,7 @@ module ValueCluster = { [ | `combination(range(MomentRe.Moment.t)) | `item(string)], ) | Probability([ | `item(string)]) - | GenericDistribution([ | `item(DistributionTypes.genericDistribution)]) + | DistPlusIngredients([ | `item(DistributionTypes.distPlusIngredients)]) | ConditionalArray([ | `item(array(conditional))]) | FloatCdf([ | `item(string)]); }; diff --git a/src/models/EAFunds.re b/src/models/EAFunds.re index b549ee37..f5adca2a 100644 --- a/src/models/EAFunds.re +++ b/src/models/EAFunds.re @@ -111,12 +111,10 @@ module Model = { let getGlobalCatastropheChance = dateTime => { let model = GlobalCatastrophe.Model.make(dateTime); switch (model) { - | Prop.Value.GenericDistribution(genericDistribution) => - genericDistribution - |> GenericDistribution.toComplexPower(~sampleCount=1000) - |> E.O.fmap( - DistFunctor.ComplexPower.T.Integral.xToY(~cache=None, 18.0), - ) + | Prop.Value.DistPlusIngredients(distPlusIngredients) => + distPlusIngredients + |> DistPlusIngredients.toDistPlus(~sampleCount=1000) + |> E.O.fmap(DistFunctor.DistPlus.T.Integral.xToY(~cache=None, 18.0)) | _ => None }; }; @@ -155,24 +153,22 @@ module Model = { foo |> E.O.default(""); }; - let genericDistribution = - GenericDistribution.make( - ~generationSource=GuesstimatorString(str), + let distPlusIngredients = + DistPlusIngredients.make( + ~guesstimatorString=str, ~domain=Complete, ~unit=UnspecifiedDistribution, (), ); - Prop.Value.GenericDistribution(genericDistribution); + Prop.Value.DistPlusIngredients(distPlusIngredients); | CHANCE_OF_EXISTENCE => - Prop.Value.GenericDistribution( - GenericDistribution.make( - ~generationSource= - GuesstimatorString( - GuesstimatorDist.min( - GlobalCatastrophe.guesstimatorString, - GuesstimatorDist.logNormal(40., 4.), - ), + Prop.Value.DistPlusIngredients( + DistPlusIngredients.make( + ~guesstimatorString= + GuesstimatorDist.min( + GlobalCatastrophe.guesstimatorString, + GuesstimatorDist.logNormal(40., 4.), ), ~domain=RightLimited({xPoint: 100., excludingProbabilityMass: 0.3}), ~unit=TimeDistribution({zero: currentDateTime, unit: `years}), diff --git a/src/models/GlobalCatastrophe.re b/src/models/GlobalCatastrophe.re index 072a4944..d7002f73 100644 --- a/src/models/GlobalCatastrophe.re +++ b/src/models/GlobalCatastrophe.re @@ -2,13 +2,13 @@ let guesstimatorString = "20 to 80"; module Model = { let make = (currentDateTime: MomentRe.Moment.t) => { - let genericDistribution = - GenericDistribution.make( - ~generationSource=GuesstimatorString(guesstimatorString), + let distPlusIngredients = + DistPlusIngredients.make( + ~guesstimatorString, ~unit=TimeDistribution({zero: currentDateTime, unit: `years}), (), ); - Prop.Value.GenericDistribution(genericDistribution); + Prop.Value.DistPlusIngredients(distPlusIngredients); }; };