From 67828cf789c0f54aebd3cf4c10091c7bb9ef7592 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Thu, 30 Jul 2020 19:27:35 +0100 Subject: [PATCH] Merged recommendedLenght to samplingParams --- src/components/DistBuilder.re | 2 +- src/components/Drawer.re | 3 +-- src/distPlus/expressionTree/ExpressionTree.re | 7 +++--- .../expressionTree/ExpressionTreeEvaluator.re | 2 +- .../expressionTree/ExpressionTypes.re | 2 +- src/distPlus/renderers/DistPlusRenderer.re | 24 ++++++++++--------- src/distPlus/renderers/RenderTypes.re | 19 --------------- src/interface/FormBuilder.re | 1 - 8 files changed, 20 insertions(+), 40 deletions(-) delete mode 100644 src/distPlus/renderers/RenderTypes.re diff --git a/src/components/DistBuilder.re b/src/components/DistBuilder.re index 4899086f..330086b7 100644 --- a/src/components/DistBuilder.re +++ b/src/components/DistBuilder.re @@ -149,9 +149,9 @@ module DemoDist = { sampleCount: Some(options.sampleCount), outputXYPoints: Some(options.outputXYPoints), kernelWidth: options.kernelWidth, + shapeLength: Some(options.downsampleTo |> E.O.default(1000)) }, ~distPlusIngredients, - ~recommendedLength=options.downsampleTo |> E.O.default(1000), ~inputVariables= [|("p", `SymbolicDist(`Float(1.0)))|] ->Belt.Map.String.fromArray, diff --git a/src/components/Drawer.re b/src/components/Drawer.re index c8777b54..f7e042d8 100644 --- a/src/components/Drawer.re +++ b/src/components/Drawer.re @@ -392,8 +392,7 @@ module Draw = { let normal: SymbolicTypes.symbolicDist = `Normal({mean, stdev}); let normalShape = ExpressionTree.toShape( - numSamples, - {sampleCount: 10000, outputXYPoints: 10000, kernelWidth: None}, + {sampleCount: 10000, outputXYPoints: 10000, kernelWidth: None, shapeLength:numSamples}, `SymbolicDist(normal), ) |> E.R.toExn; let xyShape: Types.xyShape = diff --git a/src/distPlus/expressionTree/ExpressionTree.re b/src/distPlus/expressionTree/ExpressionTree.re index c6bcbc74..e3612420 100644 --- a/src/distPlus/expressionTree/ExpressionTree.re +++ b/src/distPlus/expressionTree/ExpressionTree.re @@ -1,18 +1,17 @@ open ExpressionTypes.ExpressionTree; -let toLeaf = (intendedShapeLength: int, samplingInputs, node: node) => { +let toLeaf = (samplingInputs, node: node) => { node |> ExpressionTreeEvaluator.toLeaf({ samplingInputs, - intendedShapeLength, evaluateNode: ExpressionTreeEvaluator.toLeaf, }); }; -let toShape = (intendedShapeLength: int, samplingInputs, node: node) => { +let toShape = (samplingInputs, node: node) => { let renderResult = `Render(`Normalize(node)) - |> toLeaf(intendedShapeLength, samplingInputs); + |> toLeaf(samplingInputs); switch (renderResult) { | Ok(`RenderedDist(shape)) => Ok(shape) diff --git a/src/distPlus/expressionTree/ExpressionTreeEvaluator.re b/src/distPlus/expressionTree/ExpressionTreeEvaluator.re index 91c1ec54..b5744456 100644 --- a/src/distPlus/expressionTree/ExpressionTreeEvaluator.re +++ b/src/distPlus/expressionTree/ExpressionTreeEvaluator.re @@ -279,7 +279,7 @@ module Render = { | `SymbolicDist(d) => Ok( `RenderedDist( - SymbolicDist.T.toShape(evaluationParams.intendedShapeLength, d), + SymbolicDist.T.toShape(1234, d), ), ) | `RenderedDist(_) as t => Ok(t) // already a rendered shape, we're done here diff --git a/src/distPlus/expressionTree/ExpressionTypes.re b/src/distPlus/expressionTree/ExpressionTypes.re index d94cebb9..5f8a40cf 100644 --- a/src/distPlus/expressionTree/ExpressionTypes.re +++ b/src/distPlus/expressionTree/ExpressionTypes.re @@ -28,11 +28,11 @@ module ExpressionTree = { sampleCount: int, outputXYPoints: int, kernelWidth: option(float), + shapeLength: int }; type evaluationParams = { samplingInputs, - intendedShapeLength: int, evaluateNode: (evaluationParams, node) => Belt.Result.t(node, string), }; diff --git a/src/distPlus/renderers/DistPlusRenderer.re b/src/distPlus/renderers/DistPlusRenderer.re index 44a3b51b..b005636b 100644 --- a/src/distPlus/renderers/DistPlusRenderer.re +++ b/src/distPlus/renderers/DistPlusRenderer.re @@ -1,5 +1,13 @@ // TODO: This setup is more confusing than it should be, there's more work to do in cleanup here. module Inputs = { + module SamplingInputs = { + type t = { + sampleCount: option(int), + outputXYPoints: option(int), + kernelWidth: option(float), + shapeLength: option(int), + }; + }; let defaultRecommendedLength = 10000; let defaultShouldDownsample = true; @@ -25,20 +33,19 @@ module Inputs = { }; type inputs = { distPlusIngredients: ingredients, - samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs, - recommendedLength: int, + samplingInputs: SamplingInputs.t, inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node), }; - let empty: RenderTypes.ShapeRenderer.Sampling.inputs = { + let empty: SamplingInputs.t = { sampleCount: None, outputXYPoints: None, kernelWidth: None, + shapeLength: None }; let make = ( ~samplingInputs=empty, - ~recommendedLength=defaultRecommendedLength, ~distPlusIngredients, ~inputVariables=[||]->Belt.Map.String.fromArray, (), @@ -46,15 +53,13 @@ module Inputs = { : inputs => { distPlusIngredients, samplingInputs, - recommendedLength, inputVariables, }; }; module Internals = { type inputs = { - samplingInputs: RenderTypes.ShapeRenderer.Sampling.inputs, - symbolicInputs: RenderTypes.ShapeRenderer.Symbolic.inputs, + samplingInputs: Inputs.SamplingInputs.t, guesstimatorString: string, inputVariables: Belt.Map.String.t(ExpressionTypes.ExpressionTree.node), }; @@ -64,9 +69,6 @@ module Internals = { samplingInputs: inputs.samplingInputs, guesstimatorString: inputs.distPlusIngredients.guesstimatorString, inputVariables: inputs.inputVariables, - symbolicInputs: { - length: inputs.recommendedLength, - }, }; }; @@ -80,13 +82,13 @@ module Internals = { 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, + shapeLength: inputs.samplingInputs.shapeLength |> E.O.default(10000) }, g, ) diff --git a/src/distPlus/renderers/RenderTypes.re b/src/distPlus/renderers/RenderTypes.re deleted file mode 100644 index 08201888..00000000 --- a/src/distPlus/renderers/RenderTypes.re +++ /dev/null @@ -1,19 +0,0 @@ -module ShapeRenderer = { - module Sampling = { - type inputs = { - sampleCount: option(int), - outputXYPoints: option(int), - kernelWidth: option(float), - }; - - let defaults = { - sampleCount: Some(10000), - outputXYPoints: Some(1000), - kernelWidth: None - } - }; - - module Symbolic = { - type inputs = {length: int}; - }; -}; diff --git a/src/interface/FormBuilder.re b/src/interface/FormBuilder.re index 030edb28..428d5556 100644 --- a/src/interface/FormBuilder.re +++ b/src/interface/FormBuilder.re @@ -21,7 +21,6 @@ let propValue = (t: Prop.Value.t) => { let newDistribution = DistPlusRenderer.Inputs.make( ~distPlusIngredients=r, - ~recommendedLength=10000, (), ) |> DistPlusRenderer.run;