Moved render types to DistPlusRenderer
This commit is contained in:
parent
2316820db1
commit
8fdb54f0df
|
@ -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}),
|
||||
(),
|
||||
|
|
|
@ -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, ()),
|
||||
)}
|
||||
</>;
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -1,16 +1,79 @@
|
|||
type inputs = {
|
||||
// TODO: This setup is more confusing than it should be, there's more work to do in cleanup here.
|
||||
|
||||
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,
|
||||
};
|
||||
};
|
||||
|
||||
module Internals = {
|
||||
type inputs = {
|
||||
samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs,
|
||||
symbolicInputs: RenderTypes.ShapeRenderer.Symbolic.inputs,
|
||||
guesstimatorString: string,
|
||||
inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node),
|
||||
};
|
||||
type outputs = {
|
||||
};
|
||||
|
||||
let distPlusRenderInputsToInputs = (inputs: Inputs.inputs): inputs => {
|
||||
{
|
||||
samplingInputs: inputs.samplingInputs,
|
||||
guesstimatorString: inputs.distPlusIngredients.guesstimatorString,
|
||||
inputVariables: inputs.inputVariables,
|
||||
symbolicInputs: {
|
||||
length: inputs.recommendedLength,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
type outputs = {
|
||||
graph: ExpressionTypes.ExpressionTree.node,
|
||||
shape: DistTypes.shape,
|
||||
};
|
||||
let makeOutputs = (graph, shape): outputs => {graph, shape};
|
||||
};
|
||||
let makeOutputs = (graph, shape): outputs => {graph, shape};
|
||||
|
||||
let inputsToShape = (inputs: inputs) => {
|
||||
let inputsToShape = (inputs: inputs) => {
|
||||
MathJsParser.fromString(inputs.guesstimatorString, inputs.inputVariables)
|
||||
|> E.R.bind(_, g =>
|
||||
ExpressionTree.toShape(
|
||||
|
@ -26,27 +89,22 @@ let inputsToShape = (inputs: inputs) => {
|
|||
)
|
||||
|> E.R.fmap(makeOutputs(g))
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
let run = (inputs: RenderTypes.DistPlusRenderer.inputs) => {
|
||||
let output =
|
||||
inputsToShape({
|
||||
samplingInputs: inputs.samplingInputs,
|
||||
guesstimatorString: inputs.distPlusIngredients.guesstimatorString,
|
||||
inputVariables: inputs.inputVariables,
|
||||
symbolicInputs: {
|
||||
length: inputs.recommendedLength,
|
||||
},
|
||||
});
|
||||
output
|
||||
|> E.R.fmap((o: outputs) =>
|
||||
let outputToDistPlus = (inputs: Inputs.inputs, outputs: outputs) => {
|
||||
DistPlus.make(
|
||||
~shape=o.shape,
|
||||
~shape=outputs.shape,
|
||||
~domain=inputs.distPlusIngredients.domain,
|
||||
~unit=inputs.distPlusIngredients.unit,
|
||||
~guesstimatorString=
|
||||
Some(inputs.distPlusIngredients.guesstimatorString),
|
||||
~guesstimatorString=Some(inputs.distPlusIngredients.guesstimatorString),
|
||||
(),
|
||||
)
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
let run = (inputs: Inputs.inputs) => {
|
||||
inputs
|
||||
|> Internals.distPlusRenderInputsToInputs
|
||||
|> Internals.inputsToShape
|
||||
|> E.R.fmap(Internals.outputToDistPlus(inputs));
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)]);
|
||||
};
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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}),
|
||||
|
|
|
@ -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}),
|
||||
|
|
Loading…
Reference in New Issue
Block a user