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

View File

@ -1,5 +1,5 @@
let setup = dist =>
RenderTypes.DistPlusRenderer.make(~distPlusIngredients=dist, ())
DistPlusRenderer.Inputs.make(~distPlusIngredients=dist, ())
|> DistPlusRenderer.run
|> E.R.fmap(distPlus => <DistPlusPlot distPlus />)
|> E.R.toOption
@ -10,7 +10,7 @@ let simpleExample = (guesstimatorString, ~problem="", ()) =>
<p> {guesstimatorString |> ReasonReact.string} </p>
<p> {problem |> (e => "problem: " ++ e) |> ReasonReact.string} </p>
{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 = {
[@react.component]
let make = (~guesstimatorString, ~domain, ~unit, ~options) => {
@ -144,14 +137,14 @@ module DemoDist = {
{switch (domain, unit, options) {
| (Some(domain), Some(unit), Some(options)) =>
let distPlusIngredients =
RenderTypes.DistPlusRenderer.Ingredients.make(
DistPlusRenderer.Inputs.Ingredients.make(
~guesstimatorString,
~domain,
~unit,
(),
);
let inputs1 =
RenderTypes.DistPlusRenderer.make(
DistPlusRenderer.Inputs.make(
~samplingInputs={
sampleCount: Some(options.sampleCount),
outputXYPoints: Some(options.outputXYPoints),

View File

@ -1,52 +1,110 @@
type inputs = {
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};
// TODO: This setup is more confusing than it should be, there's more work to do in cleanup here.
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))
);
module Inputs = {
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: 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) => {
let output =
inputsToShape({
module Internals = {
type inputs = {
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,
guesstimatorString: inputs.distPlusIngredients.guesstimatorString,
inputVariables: inputs.inputVariables,
symbolicInputs: {
length: inputs.recommendedLength,
},
});
output
|> E.R.fmap((o: outputs) =>
DistPlus.make(
~shape=o.shape,
~domain=inputs.distPlusIngredients.domain,
~unit=inputs.distPlusIngredients.unit,
~guesstimatorString=
Some(inputs.distPlusIngredients.guesstimatorString),
(),
)
);
};
};
type outputs = {
graph: ExpressionTypes.ExpressionTree.node,
shape: DistTypes.shape,
};
let makeOutputs = (graph, shape): outputs => {graph, shape};
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};
};
};
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) {
| SelectSingle(r) => r |> ReasonReact.string
| ConditionalArray(r) => "Array" |> ReasonReact.string
| DistPlusIngredients((r: RenderTypes.DistPlusRenderer.ingredients)) =>
| DistPlusIngredients((r: DistPlusRenderer.Inputs.ingredients)) =>
let newDistribution =
RenderTypes.DistPlusRenderer.make(
DistPlusRenderer.Inputs.make(
~distPlusIngredients=r,
~recommendedLength=10000,
~shouldDownsample=true,

View File

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

View File

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

View File

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