Moved render types to DistPlusRenderer

This commit is contained in:
Ozzie Gooen 2020-07-30 18:09:36 +01:00
parent 2316820db1
commit 8fdb54f0df
10 changed files with 118 additions and 115 deletions

View File

@ -6,18 +6,18 @@
// uniform(0,1) > 0.3 ? lognormal(6.652, -0.41): 0 // uniform(0,1) > 0.3 ? lognormal(6.652, -0.41): 0
let timeDist ={ let timeDist ={
let ingredients = RenderTypes.DistPlusRenderer.Ingredients.make( let ingredients = DistPlusRenderer.Inputs.Ingredients.make(
~guesstimatorString="(floor(10 to 15))", ~guesstimatorString="(floor(10 to 15))",
~domain=RightLimited({xPoint: 50.0, excludingProbabilityMass: 0.3}), ~domain=RightLimited({xPoint: 50.0, excludingProbabilityMass: 0.3}),
~unit= ~unit=
DistTypes.TimeDistribution({zero: MomentRe.momentNow(), unit: `years}), DistTypes.TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
()); ());
let inputs = RenderTypes.DistPlusRenderer.make(~distPlusIngredients=ingredients,()) let inputs = DistPlusRenderer.Inputs.make(~distPlusIngredients=ingredients,())
inputs |> DistPlusRenderer.run inputs |> DistPlusRenderer.run
} }
let setup = dist => let setup = dist =>
RenderTypes.DistPlusRenderer.make(~distPlusIngredients=dist,()) DistPlusRenderer.Inputs.make(~distPlusIngredients=dist,())
|> DistPlusRenderer.run |> DistPlusRenderer.run
|> E.R.fmap(distPlus => <DistPlusPlot distPlus />) |> E.R.fmap(distPlus => <DistPlusPlot distPlus />)
|> E.R.toOption |> E.R.toOption
@ -28,7 +28,7 @@ let simpleExample = (name, guesstimatorString) =>
<h3 className="text-gray-600 text-lg font-bold"> <h3 className="text-gray-600 text-lg font-bold">
{name |> ReasonReact.string} {name |> ReasonReact.string}
</h3> </h3>
{setup(RenderTypes.DistPlusRenderer.Ingredients.make(~guesstimatorString, ()))} {setup(DistPlusRenderer.Inputs.Ingredients.make(~guesstimatorString, ()))}
</>; </>;
let timeExample = (name, guesstimatorString) => let timeExample = (name, guesstimatorString) =>
@ -37,7 +37,7 @@ let timeExample = (name, guesstimatorString) =>
{name |> ReasonReact.string} {name |> ReasonReact.string}
</h3> </h3>
{setup( {setup(
RenderTypes.DistPlusRenderer.Ingredients.make( DistPlusRenderer.Inputs.Ingredients.make(
~guesstimatorString, ~guesstimatorString,
~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}), ~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
(), (),

View File

@ -1,5 +1,5 @@
let setup = dist => let setup = dist =>
RenderTypes.DistPlusRenderer.make(~distPlusIngredients=dist, ()) DistPlusRenderer.Inputs.make(~distPlusIngredients=dist, ())
|> DistPlusRenderer.run |> DistPlusRenderer.run
|> E.R.fmap(distPlus => <DistPlusPlot distPlus />) |> E.R.fmap(distPlus => <DistPlusPlot distPlus />)
|> E.R.toOption |> E.R.toOption
@ -10,7 +10,7 @@ let simpleExample = (guesstimatorString, ~problem="", ()) =>
<p> {guesstimatorString |> ReasonReact.string} </p> <p> {guesstimatorString |> ReasonReact.string} </p>
<p> {problem |> (e => "problem: " ++ e) |> ReasonReact.string} </p> <p> {problem |> (e => "problem: " ++ e) |> ReasonReact.string} </p>
{setup( {setup(
RenderTypes.DistPlusRenderer.Ingredients.make(~guesstimatorString, ()), DistPlusRenderer.Inputs.Ingredients.make(~guesstimatorString, ()),
)} )}
</>; </>;

View File

@ -128,13 +128,6 @@ module Styles = {
]); ]);
}; };
type inputs = {
samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs,
guesstimatorString: string,
length: int,
shouldDownsampleSampledDistribution: int,
};
module DemoDist = { module DemoDist = {
[@react.component] [@react.component]
let make = (~guesstimatorString, ~domain, ~unit, ~options) => { let make = (~guesstimatorString, ~domain, ~unit, ~options) => {
@ -144,14 +137,14 @@ module DemoDist = {
{switch (domain, unit, options) { {switch (domain, unit, options) {
| (Some(domain), Some(unit), Some(options)) => | (Some(domain), Some(unit), Some(options)) =>
let distPlusIngredients = let distPlusIngredients =
RenderTypes.DistPlusRenderer.Ingredients.make( DistPlusRenderer.Inputs.Ingredients.make(
~guesstimatorString, ~guesstimatorString,
~domain, ~domain,
~unit, ~unit,
(), (),
); );
let inputs1 = let inputs1 =
RenderTypes.DistPlusRenderer.make( DistPlusRenderer.Inputs.make(
~samplingInputs={ ~samplingInputs={
sampleCount: Some(options.sampleCount), sampleCount: Some(options.sampleCount),
outputXYPoints: Some(options.outputXYPoints), outputXYPoints: Some(options.outputXYPoints),

View File

@ -1,52 +1,110 @@
type inputs = { // TODO: This setup is more confusing than it should be, there's more work to do in cleanup here.
samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs,
symbolicInputs: RenderTypes.ShapeRenderer.Symbolic.inputs,
guesstimatorString: string,
inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node),
};
type outputs = {
graph: ExpressionTypes.ExpressionTree.node,
shape: DistTypes.shape,
};
let makeOutputs = (graph, shape): outputs => {graph, shape};
let inputsToShape = (inputs: inputs) => { module Inputs = {
MathJsParser.fromString(inputs.guesstimatorString, inputs.inputVariables) let defaultRecommendedLength = 10000;
|> E.R.bind(_, g => let defaultShouldDownsample = true;
ExpressionTree.toShape( type ingredients = {
inputs.symbolicInputs.length, guesstimatorString: string,
{ domain: DistTypes.domain,
sampleCount: unit: DistTypes.distributionUnit,
inputs.samplingInputs.sampleCount |> E.O.default(10000), };
outputXYPoints: module Ingredients = {
inputs.samplingInputs.outputXYPoints |> E.O.default(10000), type t = ingredients;
kernelWidth: inputs.samplingInputs.kernelWidth, let make =
}, (
g, ~guesstimatorString,
) ~domain=DistTypes.Complete,
|> E.R.fmap(makeOutputs(g)) ~unit=DistTypes.UnspecifiedDistribution,
); (),
)
: t => {
guesstimatorString,
domain,
unit,
};
};
type inputs = {
distPlusIngredients: ingredients,
samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs,
recommendedLength: int,
shouldDownsample: bool,
inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node),
};
let make =
(
~samplingInputs=RenderTypes.ShapeRenderer.Sampling.Inputs.empty,
~recommendedLength=defaultRecommendedLength,
~shouldDownsample=defaultShouldDownsample,
~distPlusIngredients,
~inputVariables=[||]->Belt.Map.String.fromArray,
(),
)
: inputs => {
distPlusIngredients,
samplingInputs,
recommendedLength,
shouldDownsample,
inputVariables,
};
}; };
let run = (inputs: RenderTypes.DistPlusRenderer.inputs) => { module Internals = {
let output = type inputs = {
inputsToShape({ samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs,
symbolicInputs: RenderTypes.ShapeRenderer.Symbolic.inputs,
guesstimatorString: string,
inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node),
};
let distPlusRenderInputsToInputs = (inputs: Inputs.inputs): inputs => {
{
samplingInputs: inputs.samplingInputs, samplingInputs: inputs.samplingInputs,
guesstimatorString: inputs.distPlusIngredients.guesstimatorString, guesstimatorString: inputs.distPlusIngredients.guesstimatorString,
inputVariables: inputs.inputVariables, inputVariables: inputs.inputVariables,
symbolicInputs: { symbolicInputs: {
length: inputs.recommendedLength, length: inputs.recommendedLength,
}, },
}); };
output };
|> E.R.fmap((o: outputs) =>
DistPlus.make( type outputs = {
~shape=o.shape, graph: ExpressionTypes.ExpressionTree.node,
~domain=inputs.distPlusIngredients.domain, shape: DistTypes.shape,
~unit=inputs.distPlusIngredients.unit, };
~guesstimatorString= let makeOutputs = (graph, shape): outputs => {graph, shape};
Some(inputs.distPlusIngredients.guesstimatorString),
(), let inputsToShape = (inputs: inputs) => {
) MathJsParser.fromString(inputs.guesstimatorString, inputs.inputVariables)
); |> E.R.bind(_, g =>
ExpressionTree.toShape(
inputs.symbolicInputs.length,
{
sampleCount:
inputs.samplingInputs.sampleCount |> E.O.default(10000),
outputXYPoints:
inputs.samplingInputs.outputXYPoints |> E.O.default(10000),
kernelWidth: inputs.samplingInputs.kernelWidth,
},
g,
)
|> E.R.fmap(makeOutputs(g))
);
};
let outputToDistPlus = (inputs: Inputs.inputs, outputs: outputs) => {
DistPlus.make(
~shape=outputs.shape,
~domain=inputs.distPlusIngredients.domain,
~unit=inputs.distPlusIngredients.unit,
~guesstimatorString=Some(inputs.distPlusIngredients.guesstimatorString),
(),
);
};
};
let run = (inputs: Inputs.inputs) => {
inputs
|> Internals.distPlusRenderInputsToInputs
|> Internals.inputsToShape
|> E.R.fmap(Internals.outputToDistPlus(inputs));
}; };

View File

@ -34,51 +34,3 @@ module ShapeRenderer = {
type inputs = {length: int}; type inputs = {length: int};
}; };
}; };
module DistPlusRenderer = {
let defaultRecommendedLength = 10000;
let defaultShouldDownsample = true;
type ingredients = {
guesstimatorString: string,
domain: DistTypes.domain,
unit: DistTypes.distributionUnit,
};
module Ingredients = {
type t = ingredients;
let make =
(
~guesstimatorString,
~domain=DistTypes.Complete,
~unit=DistTypes.UnspecifiedDistribution,
(),
)
: t => {
guesstimatorString,
domain,
unit,
};
};
type inputs = {
distPlusIngredients: ingredients,
samplingInputs: ShapeRenderer.Sampling.inputs,
recommendedLength: int,
shouldDownsample: bool,
inputVariables: MS.t(ExpressionTypes.ExpressionTree.node),
};
let make =
(
~samplingInputs=ShapeRenderer.Sampling.Inputs.empty,
~recommendedLength=defaultRecommendedLength,
~shouldDownsample=defaultShouldDownsample,
~distPlusIngredients,
~inputVariables=[||]->Belt.Map.String.fromArray,
(),
)
: inputs => {
distPlusIngredients,
samplingInputs,
recommendedLength,
shouldDownsample,
inputVariables,
};
};

View File

@ -17,9 +17,9 @@ let propValue = (t: Prop.Value.t) => {
switch (t) { switch (t) {
| SelectSingle(r) => r |> ReasonReact.string | SelectSingle(r) => r |> ReasonReact.string
| ConditionalArray(r) => "Array" |> ReasonReact.string | ConditionalArray(r) => "Array" |> ReasonReact.string
| DistPlusIngredients((r: RenderTypes.DistPlusRenderer.ingredients)) => | DistPlusIngredients((r: DistPlusRenderer.Inputs.ingredients)) =>
let newDistribution = let newDistribution =
RenderTypes.DistPlusRenderer.make( DistPlusRenderer.Inputs.make(
~distPlusIngredients=r, ~distPlusIngredients=r,
~recommendedLength=10000, ~recommendedLength=10000,
~shouldDownsample=true, ~shouldDownsample=true,

View File

@ -9,7 +9,7 @@ module Value = {
| DateTime(MomentRe.Moment.t) | DateTime(MomentRe.Moment.t)
| FloatPoint(float) | FloatPoint(float)
| Probability(float) | Probability(float)
| DistPlusIngredients(RenderTypes.DistPlusRenderer.ingredients) | DistPlusIngredients(DistPlusRenderer.Inputs.ingredients)
| ConditionalArray(array(conditional)) | ConditionalArray(array(conditional))
| FloatCdf(string); | FloatCdf(string);
@ -85,7 +85,7 @@ module ValueCluster = {
[ | `combination(range(MomentRe.Moment.t)) | `item(string)], [ | `combination(range(MomentRe.Moment.t)) | `item(string)],
) )
| Probability([ | `item(string)]) | Probability([ | `item(string)])
| DistPlusIngredients([ | `item(RenderTypes.DistPlusRenderer.ingredients)]) | DistPlusIngredients([ | `item(DistPlusRenderer.Inputs.ingredients)])
| ConditionalArray([ | `item(array(conditional))]) | ConditionalArray([ | `item(array(conditional))])
| FloatCdf([ | `item(string)]); | FloatCdf([ | `item(string)]);
}; };

View File

@ -110,7 +110,7 @@ module Model = {
// TODO: Fixe number that integral is calculated for // TODO: Fixe number that integral is calculated for
let getGlobalCatastropheChance = dateTime => { let getGlobalCatastropheChance = dateTime => {
GlobalCatastrophe.makeI(MomentRe.momentNow()) GlobalCatastrophe.makeI(MomentRe.momentNow())
|> RenderTypes.DistPlusRenderer.make(~distPlusIngredients=_, ()) |> DistPlusRenderer.Inputs.make(~distPlusIngredients=_, ())
|> DistPlusRenderer.run |> DistPlusRenderer.run
|> E.R.bind(_, r => |> E.R.bind(_, r =>
r r
@ -157,7 +157,7 @@ module Model = {
}; };
let distPlusIngredients = let distPlusIngredients =
RenderTypes.DistPlusRenderer.Ingredients.make( DistPlusRenderer.Inputs.Ingredients.make(
~guesstimatorString=str, ~guesstimatorString=str,
~domain=Complete, ~domain=Complete,
~unit=UnspecifiedDistribution, ~unit=UnspecifiedDistribution,
@ -167,7 +167,7 @@ module Model = {
| CHANCE_OF_EXISTENCE => | CHANCE_OF_EXISTENCE =>
Prop.Value.DistPlusIngredients( Prop.Value.DistPlusIngredients(
RenderTypes.DistPlusRenderer.Ingredients.make( DistPlusRenderer.Inputs.Ingredients.make(
~guesstimatorString= ~guesstimatorString=
GuesstimatorDist.min( GuesstimatorDist.min(
GlobalCatastrophe.guesstimatorString, GlobalCatastrophe.guesstimatorString,

View File

@ -1,7 +1,7 @@
let guesstimatorString = "uniform(1, 100)"; let guesstimatorString = "uniform(1, 100)";
let makeI = (currentDateTime: MomentRe.Moment.t) => { let makeI = (currentDateTime: MomentRe.Moment.t) => {
RenderTypes.DistPlusRenderer.Ingredients.make( DistPlusRenderer.Inputs.Ingredients.make(
~guesstimatorString, ~guesstimatorString,
~unit=TimeDistribution({zero: currentDateTime, unit: `years}), ~unit=TimeDistribution({zero: currentDateTime, unit: `years}),
~domain=RightLimited({xPoint: 300.0, excludingProbabilityMass: 0.3}), ~domain=RightLimited({xPoint: 300.0, excludingProbabilityMass: 0.3}),

View File

@ -2,7 +2,7 @@ let guesstimatorString = age =>
GuesstimatorDist.normal(72.0 -. age, 5.0 -. age *. 0.01); GuesstimatorDist.normal(72.0 -. age, 5.0 -. age *. 0.01);
let makeI = (age: float) => { let makeI = (age: float) => {
RenderTypes.DistPlusRenderer.Ingredients.make( DistPlusRenderer.Inputs.Ingredients.make(
~guesstimatorString=guesstimatorString(age), ~guesstimatorString=guesstimatorString(age),
~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}), ~unit=TimeDistribution({zero: MomentRe.momentNow(), unit: `years}),
~domain=RightLimited({xPoint: 300.0, excludingProbabilityMass: 0.3}), ~domain=RightLimited({xPoint: 300.0, excludingProbabilityMass: 0.3}),