Renames to use distPlus and distPlusIngredients
This commit is contained in:
parent
d947d43b56
commit
7f0ab442ad
|
@ -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 = () =>
|
||||
<div>
|
||||
<div>
|
||||
<h2> {"Basic Mixed Distribution" |> ReasonReact.string} </h2>
|
||||
{timeDist
|
||||
|> E.O.React.fmapOrNull(complexPower =>
|
||||
<ComplexPowerChart complexPower />
|
||||
)}
|
||||
{timeDist |> E.O.React.fmapOrNull(distPlus => <DistPlusChart distPlus />)}
|
||||
<h2> {"Simple Continuous" |> ReasonReact.string} </h2>
|
||||
</div>
|
||||
</div>;
|
||||
|
|
|
@ -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;
|
||||
<CdfChart__Plain
|
||||
minX
|
||||
maxX
|
||||
|
@ -25,10 +22,9 @@ module ComplexPowerChart = {
|
|||
|
||||
module IntegralChart = {
|
||||
[@react.component]
|
||||
let make = (~complexPower: DistributionTypes.complexPower, ~onHover) => {
|
||||
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;
|
||||
<CdfChart__Plain
|
||||
minX
|
||||
maxX
|
||||
|
@ -50,17 +45,17 @@ module IntegralChart = {
|
|||
};
|
||||
|
||||
[@react.component]
|
||||
let make = (~complexPower: DistributionTypes.complexPower) => {
|
||||
let make = (~distPlus: DistributionTypes.distPlus) => {
|
||||
let (x, setX) = React.useState(() => 0.);
|
||||
let chart =
|
||||
React.useMemo1(
|
||||
() => {<ComplexPowerChart complexPower onHover={r => {setX(_ => r)}} />},
|
||||
[|complexPower|],
|
||||
() => {<DistPlusChart distPlus onHover={r => {setX(_ => r)}} />},
|
||||
[|distPlus|],
|
||||
);
|
||||
let chart2 =
|
||||
React.useMemo1(
|
||||
() => {<IntegralChart complexPower onHover={r => {setX(_ => r)}} />},
|
||||
[|complexPower|],
|
||||
() => {<IntegralChart distPlus onHover={r => {setX(_ => r)}} />},
|
||||
[|distPlus|],
|
||||
);
|
||||
<div>
|
||||
chart
|
||||
|
@ -80,8 +75,8 @@ let make = (~complexPower: DistributionTypes.complexPower) => {
|
|||
{x |> E.Float.toString |> ReasonReact.string}
|
||||
</th>
|
||||
<th className="px-4 py-2 border ">
|
||||
{complexPower
|
||||
|> DistFunctor.ComplexPower.T.Integral.xToY(~cache=None, x)
|
||||
{distPlus
|
||||
|> DistFunctor.DistPlus.T.Integral.xToY(~cache=None, x)
|
||||
|> E.Float.with2DigitsPrecision
|
||||
|> ReasonReact.string}
|
||||
</th>
|
|
@ -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);
|
||||
|
|
29
src/core/DistPlusIngredients.re
Normal file
29
src/core/DistPlusIngredients.re
Normal file
|
@ -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,
|
||||
(),
|
||||
)
|
||||
);
|
||||
};
|
|
@ -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) {
|
||||
|
|
|
@ -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,
|
||||
(),
|
||||
)
|
||||
);
|
||||
};
|
|
@ -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) =>
|
||||
<div> <ComplexPowerChart complexPower=distribution /> </div>
|
||||
<div> <DistPlusChart distPlus=distribution /> </div>
|
||||
| None => "Something went wrong" |> ReasonReact.string
|
||||
};
|
||||
| FloatCdf(_) => <div />
|
||||
|
|
|
@ -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)]);
|
||||
};
|
||||
|
|
|
@ -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}),
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user