Minor cleanup of RenderTypes

This commit is contained in:
Ozzie Gooen 2020-07-30 17:52:28 +01:00
parent d17299a5b1
commit 2316820db1
3 changed files with 36 additions and 97 deletions

View File

@ -167,30 +167,12 @@ module DemoDist = {
);
let response1 = DistPlusRenderer.run(inputs1);
let inputs2 =
RenderTypes.DistPlusRenderer.make(
~samplingInputs={
sampleCount: Some(options.sampleCount),
outputXYPoints: Some(options.outputXYPoints),
kernelWidth: options.kernelWidth,
},
~distPlusIngredients,
~shouldDownsample=options.downsampleTo |> E.O.isSome,
~recommendedLength=options.downsampleTo |> E.O.default(1000),
~inputVariables=
[|("p", `SymbolicDist(`Float(2.0)))|]
->Belt.Map.String.fromArray,
(),
);
let response2 = DistPlusRenderer.run(inputs2);
switch (response1, response2) {
| (Ok(distPlus1), Ok(distPlus2)) =>
switch (response1) {
| (Ok(distPlus1)) =>
<>
<DistPlusPlot distPlus={DistPlus.T.normalize(distPlus1)} />
<DistPlusPlot distPlus={DistPlus.T.normalize(distPlus2)} />
</>
| (Error(r), _) => r |> R.ste
| (_, Error(r)) => r |> R.ste
| (Error(r)) => r |> R.ste
};
| _ =>
"Nothing to show. Try to change the distribution description."

View File

@ -1,4 +1,16 @@
let inputsToShape = (inputs: RenderTypes.ShapeRenderer.Combined.inputs) => {
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};
let inputsToShape = (inputs: inputs) => {
MathJsParser.fromString(inputs.guesstimatorString, inputs.inputVariables)
|> E.R.bind(_, g =>
ExpressionTree.toShape(
@ -12,20 +24,11 @@ let inputsToShape = (inputs: RenderTypes.ShapeRenderer.Combined.inputs) => {
},
g,
)
|> E.R.fmap(RenderTypes.ShapeRenderer.Symbolic.make(g))
|> E.R.fmap(makeOutputs(g))
);
};
let run = (inputs: RenderTypes.DistPlusRenderer.inputs) => {
let toDist = shape =>
DistPlus.make(
~shape,
~domain=inputs.distPlusIngredients.domain,
~unit=inputs.distPlusIngredients.unit,
~guesstimatorString=Some(inputs.distPlusIngredients.guesstimatorString),
(),
)
|> DistPlus.T.normalize;
let output =
inputsToShape({
samplingInputs: inputs.samplingInputs,
@ -36,7 +39,14 @@ let run = (inputs: RenderTypes.DistPlusRenderer.inputs) => {
},
});
output
|> E.R.fmap((o: RenderTypes.ShapeRenderer.Symbolic.outputs) =>
toDist(o.shape)
|> E.R.fmap((o: outputs) =>
DistPlus.make(
~shape=o.shape,
~domain=inputs.distPlusIngredients.domain,
~unit=inputs.distPlusIngredients.unit,
~guesstimatorString=
Some(inputs.distPlusIngredients.guesstimatorString),
(),
)
);
};

View File

@ -7,20 +7,8 @@ module ShapeRenderer = {
outputXYPoints: option(int),
kernelWidth: option(float),
};
type samplingStats = {
sampleCount: int,
outputXYPoints: int,
bandwidthXSuggested: float,
bandwidthUnitSuggested: float,
bandwidthXImplemented: float,
bandwidthUnitImplemented: float,
};
type outputs = {
continuousParseParams: option(samplingStats),
shape: option(DistTypes.shape),
};
module Inputs = {
let defaultSampleCount = 5000;
let defaultSampleCount = 10000;
let defaultOutputXYPoints = 10000;
let empty = {
sampleCount: None,
@ -44,36 +32,6 @@ module ShapeRenderer = {
module Symbolic = {
type inputs = {length: int};
type outputs = {
graph: ExpressionTypes.ExpressionTree.node,
shape: DistTypes.shape,
};
let make = (graph, shape) => {graph, shape};
};
module Combined = {
type inputs = {
samplingInputs: Sampling.inputs,
symbolicInputs: Symbolic.inputs,
guesstimatorString: string,
inputVariables: MS.t(ExpressionTypes.ExpressionTree.node),
};
type outputs = {
symbolic: option(Belt.Result.t(Symbolic.outputs, string)),
sampling: option(Sampling.outputs),
};
let methodUsed = ({symbolic, sampling}: outputs) =>
switch (symbolic, sampling) {
| (Some(Ok(_)), _) => `Symbolic
| (_, Some({shape: Some(_)})) => `Sampling
| _ => `None
};
let getShape = (r: outputs) =>
switch (r.symbolic, r.sampling) {
| (Some(Ok({shape})), _) => Some(shape)
| (_, Some({shape})) => shape
| _ => None
};
};
};
@ -85,14 +43,8 @@ module DistPlusRenderer = {
domain: DistTypes.domain,
unit: DistTypes.distributionUnit,
};
type inputs = {
distPlusIngredients: ingredients,
samplingInputs: ShapeRenderer.Sampling.inputs,
recommendedLength: int,
shouldDownsample: bool,
inputVariables: MS.t(ExpressionTypes.ExpressionTree.node),
};
module Ingredients = {
type t = ingredients;
let make =
(
~guesstimatorString,
@ -100,12 +52,19 @@ module DistPlusRenderer = {
~unit=DistTypes.UnspecifiedDistribution,
(),
)
: ingredients => {
: 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,
@ -122,16 +81,4 @@ module DistPlusRenderer = {
shouldDownsample,
inputVariables,
};
type outputs = {
shapeRenderOutputs: ShapeRenderer.Combined.outputs,
distPlus: option(DistTypes.distPlus),
};
module Outputs = {
let distplus = (t: outputs) => t.distPlus;
let shapeRenderOutputs = (t: outputs) => t.shapeRenderOutputs;
let make = (shapeRenderOutputs, distPlus) => {
shapeRenderOutputs,
distPlus,
};
};
};