diff --git a/src/components/DistBuilder.re b/src/components/DistBuilder.re
index 97048130..7b942773 100644
--- a/src/components/DistBuilder.re
+++ b/src/components/DistBuilder.re
@@ -164,64 +164,24 @@ module DemoDist = {
| Ok(`DistPlus(distPlus1)) =>
| Ok(`Function(f, a)) =>
- let result1 =
- DistPlusRenderer.runFunction(
- inputs1,
- (f, a),
- [|`SymbolicDist(`Float(0.0))|],
- );
- let result2 =
- DistPlusRenderer.runFunction(
- inputs1,
- (f, a),
- [|`SymbolicDist(`Float(2.0))|],
- );
- let result3 =
- DistPlusRenderer.runFunction(
- inputs1,
- (f, a),
- [|`SymbolicDist(`Float(4.0))|],
- );
- let result4 =
- DistPlusRenderer.runFunction(
- inputs1,
- (f, a),
- [|`SymbolicDist(`Float(6.0))|],
- );
- let result5 =
- DistPlusRenderer.runFunction(
- inputs1,
- (f, a),
- [|`SymbolicDist(`Float(8.0))|],
- );
- let result6 =
- DistPlusRenderer.runFunction(
- inputs1,
- (f, a),
- [|`SymbolicDist(`Float(10.0))|],
- );
- switch (result1, result2, result3, result4, result5, result6) {
- | (
- Ok(`DistPlus(distPlus1)),
- Ok(`DistPlus(distPlus2)),
- Ok(`DistPlus(distPlus3)),
- Ok(`DistPlus(distPlus4)),
- Ok(`DistPlus(distPlus5)),
- Ok(`DistPlus(distPlus6)),
- ) =>
- <>
-
- >
- | _ => "Failure " |> R.ste
+ let results = E.A.Floats.range(0.0, 10.0, 100)
+ |> E.A.fmap(r =>
+ DistPlusRenderer.runFunction(
+ inputs1,
+ (f, a),
+ [|`SymbolicDist(`Float(r))|],
+ )
+ |> E.R.bind(_, a =>
+ switch (a) {
+ | `DistPlus(d) => Ok((r, d))
+ | _ => Error("")
+ }
+ )
+ )
+ |> E.A.R.firstErrorOrOpen;
+ switch (results) {
+ | Ok(dists) => <> >
+ | Error(r) => r |> R.ste
};
| Error(r) => r |> R.ste
};
@@ -236,7 +196,7 @@ module DemoDist = {
[@react.component]
let make = () => {
- let (reloader, setRealoader) = React.useState(() => 1);
+ let (reloader, setReloader) = React.useState(() => 1);
let reform =
Form.use(
~validationStrategy=OnDemand,
@@ -366,8 +326,8 @@ let make = () => {
|],
);
- let onRealod = _ => {
- setRealoader(_ => reloader + 1);
+ let onReload = _ => {
+ setReloader(_ => reloader + 1);
};
@@ -380,7 +340,7 @@ let make = () => {
}>
@@ -411,7 +371,7 @@ let make = () => {
+ _type=`primary icon=Antd.IconName.reload onClick=onReload>
{"Update Distribution" |> R.ste}
diff --git a/src/distPlus/expressionTree/ExpressionTreeEvaluator.re b/src/distPlus/expressionTree/ExpressionTreeEvaluator.re
index 99689911..6c4e39d6 100644
--- a/src/distPlus/expressionTree/ExpressionTreeEvaluator.re
+++ b/src/distPlus/expressionTree/ExpressionTreeEvaluator.re
@@ -151,7 +151,8 @@ module PointwiseCombination = {
};
};
- let pointwiseCombine = (fn, evaluationParams: evaluationParams, t1: t, t2: t) => {
+ let pointwiseCombine =
+ (fn, evaluationParams: evaluationParams, t1: t, t2: t) => {
// TODO: construct a function that we can easily sample from, to construct
// a RenderedDist. Use the xMin and xMax of the rendered shapes to tell the sampling function where to look.
// TODO: This should work for symbolic distributions too!
@@ -176,8 +177,8 @@ module PointwiseCombination = {
) => {
switch (pointwiseOp) {
| `Add => pointwiseAdd(evaluationParams, t1, t2)
- | `Multiply => pointwiseCombine(( *. ),evaluationParams, t1, t2)
- | `Exponentiate => pointwiseCombine(( ** ),evaluationParams, t1, t2)
+ | `Multiply => pointwiseCombine(( *. ), evaluationParams, t1, t2)
+ | `Exponentiate => pointwiseCombine(( ** ), evaluationParams, t1, t2)
};
};
};
@@ -262,14 +263,12 @@ module FloatFromDist = {
// TODO: This forces things to be floats
let callableFunction = (evaluationParams, name, args) => {
- let b =
- args
- |> E.A.fmap(a =>
- Render.render(evaluationParams, a)
- |> E.R.bind(_, Render.toFloat)
- )
- |> E.A.R.firstErrorOrOpen;
- b |> E.R.bind(_, Functions.fnn(evaluationParams, name));
+ args
+ |> E.A.fmap(a =>
+ Render.render(evaluationParams, a) |> E.R.bind(_, Render.toFloat)
+ )
+ |> E.A.R.firstErrorOrOpen
+ |> E.R.bind(_, Functions.fnn(evaluationParams, name));
};
module Render = {
@@ -280,7 +279,10 @@ module Render = {
| `SymbolicDist(d) =>
Ok(
`RenderedDist(
- SymbolicDist.T.toShape(evaluationParams.samplingInputs.shapeLength, d),
+ SymbolicDist.T.toShape(
+ evaluationParams.samplingInputs.shapeLength,
+ d,
+ ),
),
)
| `RenderedDist(_) as t => Ok(t) // already a rendered shape, we're done here
@@ -329,7 +331,12 @@ let toLeaf =
FloatFromDist.operationToLeaf(evaluationParams, distToFloatOp, t)
| `Normalize(t) => Normalize.operationToLeaf(evaluationParams, t)
| `Render(t) => Render.operationToLeaf(evaluationParams, t)
- | `Symbol(r) => ExpressionTypes.ExpressionTree.Environment.get(evaluationParams.environment, r) |> E.O.toResult("Undeclared variable " ++ r)
+ | `Symbol(r) =>
+ ExpressionTypes.ExpressionTree.Environment.get(
+ evaluationParams.environment,
+ r,
+ )
+ |> E.O.toResult("Undeclared variable " ++ r)
| `FunctionCall(name, args) =>
callableFunction(evaluationParams, name, args)
};
diff --git a/src/distPlus/expressionTree/Functions.re b/src/distPlus/expressionTree/Functions.re
index 80fa81ca..dd14a218 100644
--- a/src/distPlus/expressionTree/Functions.re
+++ b/src/distPlus/expressionTree/Functions.re
@@ -35,19 +35,18 @@ let apply3 = (fn, args: array(node)): result(node, string) =>
| _ => Error("Needs 3 args")
};
-let to_: array(node) => result(node, string) =
- fun
- | [|`SymbolicDist(`Float(low)), `SymbolicDist(`Float(high))|]
+let to_: (float, float) => result(node, string) = (low, high) => switch(low,high){
+ | (low,high)
when low <= 0.0 && low < high => {
Ok(`SymbolicDist(SymbolicDist.Normal.from90PercentCI(low, high)));
}
- | [|`SymbolicDist(`Float(low)), `SymbolicDist(`Float(high))|]
+ | (low,high)
when low < high => {
Ok(`SymbolicDist(SymbolicDist.Lognormal.from90PercentCI(low, high)));
}
- | [|`SymbolicDist(`Float(_)), `SymbolicDist(_)|] =>
+ | (low,high) =>
Error("Low value must be less than high value.")
- | _ => Error("Requires 2 variables");
+}
// Possible setup:
// let normal = {"inputs": [`float, `float], "outputs": [`float]};
@@ -97,6 +96,6 @@ let fnn =
|> E.R.fmap(r => `SymbolicDist(r))
| _ => Error("Needs 3 valid arguments")
}
- | ("to", _) => to_(args)
+ | ("to", _) => apply2(twoFloats(to_), args)
| _ => Error("Function " ++ name ++ " not found")
};
diff --git a/src/distPlus/renderers/DistPlusRenderer.re b/src/distPlus/renderers/DistPlusRenderer.re
index 9981db52..0f5993d0 100644
--- a/src/distPlus/renderers/DistPlusRenderer.re
+++ b/src/distPlus/renderers/DistPlusRenderer.re
@@ -135,23 +135,6 @@ module Internals = {
};
};
-let run = (inputs: Inputs.inputs) => {
- inputs
- |> Internals.distPlusRenderInputsToInputs
- |> Internals.inputsToLeaf
- |> E.R.bind(_, r =>
- switch (r) {
- | `RenderedDist(n) => Ok(n)
- | n =>
- Error(
- "Didn't output a rendered distribution. Format:"
- ++ ExpressionTree.toString(n),
- )
- }
- )
- |> E.R.fmap(Internals.outputToDistPlus(inputs));
-};
-
let renderIfNeeded =
(inputs, node: ExpressionTypes.ExpressionTree.node)
: result(ExpressionTypes.ExpressionTree.node, string) =>
@@ -171,6 +154,27 @@ let renderIfNeeded =
| n => Ok(n)
);
+let run = (inputs: Inputs.inputs) => {
+ inputs
+ |> Internals.distPlusRenderInputsToInputs
+ |> Internals.inputsToLeaf
+ |> E.R.bind(_, r =>
+ r
+ |> renderIfNeeded(inputs)
+ |> (
+ fun
+ | Ok(`RenderedDist(n)) => Ok(n)
+ | Ok(n) =>
+ Error(
+ "Didn't output a rendered distribution. Format:"
+ ++ ExpressionTree.toString(n),
+ )
+ | Error(r) => Error(r)
+ )
+ )
+ |> E.R.fmap(Internals.outputToDistPlus(inputs));
+};
+
let exportDistPlus = (inputs, node: ExpressionTypes.ExpressionTree.node) =>
node
|> renderIfNeeded(inputs)