diff --git a/src/distPlus/expressionTree/ExpressionTree.re b/src/distPlus/expressionTree/ExpressionTree.re index 66ccf3a6..c6bcbc74 100644 --- a/src/distPlus/expressionTree/ExpressionTree.re +++ b/src/distPlus/expressionTree/ExpressionTree.re @@ -1,13 +1,18 @@ open ExpressionTypes.ExpressionTree; +let toLeaf = (intendedShapeLength: int, samplingInputs, node: node) => { + node + |> ExpressionTreeEvaluator.toLeaf({ + samplingInputs, + intendedShapeLength, + evaluateNode: ExpressionTreeEvaluator.toLeaf, + }); +}; + let toShape = (intendedShapeLength: int, samplingInputs, node: node) => { let renderResult = `Render(`Normalize(node)) - |> ExpressionTreeEvaluator.toLeaf({ - samplingInputs, - intendedShapeLength, - evaluateNode: ExpressionTreeEvaluator.toLeaf, - }); + |> toLeaf(intendedShapeLength, samplingInputs); switch (renderResult) { | Ok(`RenderedDist(shape)) => Ok(shape) diff --git a/src/distPlus/expressionTree/ExpressionTypes.re b/src/distPlus/expressionTree/ExpressionTypes.re index e7dbabcf..d94cebb9 100644 --- a/src/distPlus/expressionTree/ExpressionTypes.re +++ b/src/distPlus/expressionTree/ExpressionTypes.re @@ -74,12 +74,18 @@ module ExpressionTree = { | _ => None }; - let _toFloat = (t:DistTypes.shape) => switch(t){ - | Discrete({xyShape: {xs: [|x|], ys: [|1.0|]}}) => Some(`SymbolicDist(`Float(x))) - | _ => None - } + let _toFloat = (t: DistTypes.shape) => + switch (t) { + | Discrete({xyShape: {xs: [|x|], ys: [|1.0|]}}) => + Some(`SymbolicDist(`Float(x))) + | _ => None + }; - let toFloat = (item:node):result(node, string) => item |> getShape |> E.O.bind(_,_toFloat) |> E.O.toResult("Not valid shape") + let toFloat = (item: node): result(node, string) => + item + |> getShape + |> E.O.bind(_, _toFloat) + |> E.O.toResult("Not valid shape"); }; }; @@ -88,3 +94,8 @@ type simplificationResult = [ | `Error(string) | `NoSolution ]; + +module Program = { + type statement = [ | `Assignment(string, ExpressionTree.node) | `Expression(ExpressionTree.node)]; + type program = array(statement); +} \ No newline at end of file diff --git a/src/distPlus/expressionTree/Program.re b/src/distPlus/expressionTree/Program.re new file mode 100644 index 00000000..217fabd8 --- /dev/null +++ b/src/distPlus/expressionTree/Program.re @@ -0,0 +1,4 @@ +type t = ExpressionTypes.Program.program; + +// let run = (p:program) => p |> E.A.last |> E.O.fmap(r => +// ) \ No newline at end of file diff --git a/src/distPlus/renderers/DistPlusRenderer.re b/src/distPlus/renderers/DistPlusRenderer.re index a43a7822..dd23513b 100644 --- a/src/distPlus/renderers/DistPlusRenderer.re +++ b/src/distPlus/renderers/DistPlusRenderer.re @@ -1,3 +1,21 @@ +let inputsToShape = (inputs: RenderTypes.ShapeRenderer.Combined.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(RenderTypes.ShapeRenderer.Symbolic.make(g)) + ); +}; + let run = (inputs: RenderTypes.DistPlusRenderer.inputs) => { let toDist = shape => DistPlus.make( @@ -8,10 +26,8 @@ let run = (inputs: RenderTypes.DistPlusRenderer.inputs) => { (), ) |> DistPlus.T.normalize; - // let symbolicDist: ExpressionTypes.ExpressionTree.node = `SymbolicDist(`Float(30.0)); - // inputVariables: [|("p", symbolicDist)|] -> Belt.Map.String.fromArray, let output = - ShapeRenderer.run({ + inputsToShape({ samplingInputs: inputs.samplingInputs, guesstimatorString: inputs.distPlusIngredients.guesstimatorString, inputVariables: inputs.inputVariables, diff --git a/src/distPlus/renderers/ShapeRenderer.re b/src/distPlus/renderers/ShapeRenderer.re deleted file mode 100644 index f9822409..00000000 --- a/src/distPlus/renderers/ShapeRenderer.re +++ /dev/null @@ -1,35 +0,0 @@ -// This transforms an array intersperced with spaces or newlines with a normally formatted one. -// "3 4 5 3 2 1 " -> "[3,4,5,3,2,1]"" -let formatMessyArray = str => { - let split = Js.String.splitByRe([%re "/\\n|\\r|\\s/"], str); - if (E.A.length(split) > 20) { - let inner = split |> Js.Array.joinWith(","); - {j|[$inner]|j}; - } else { - str; - }; -}; - -let formatString = str => { - str |> formatMessyArray; -}; - -let run = (inputs: RenderTypes.ShapeRenderer.Combined.inputs) => { - let str = formatString(inputs.guesstimatorString); - let graph = MathJsParser.fromString(str, inputs.inputVariables); - graph - |> 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(RenderTypes.ShapeRenderer.Symbolic.make(g)) - ); -};