Simple optional functions
This commit is contained in:
parent
04d606d9c6
commit
6887da59b3
|
@ -149,7 +149,8 @@ module DemoDist = {
|
|||
sampleCount: Some(options.sampleCount),
|
||||
outputXYPoints: Some(options.outputXYPoints),
|
||||
kernelWidth: options.kernelWidth,
|
||||
shapeLength: Some(options.downsampleTo |> E.O.default(1000))
|
||||
shapeLength:
|
||||
Some(options.downsampleTo |> E.O.default(1000)),
|
||||
},
|
||||
~distPlusIngredients,
|
||||
~environment=
|
||||
|
@ -160,12 +161,22 @@ module DemoDist = {
|
|||
|
||||
let response1 = DistPlusRenderer.run2(inputs1);
|
||||
switch (response1) {
|
||||
| (Ok(`DistPlus(distPlus1))) =>
|
||||
| Ok(`DistPlus(distPlus1)) =>
|
||||
<DistPlusPlot distPlus={DistPlus.T.normalize(distPlus1)} />
|
||||
| Ok(`Function(f, a)) =>
|
||||
let result1 = DistPlusRenderer.runFunction(inputs1, (f, a), [|`SymbolicDist(`Float(5.0))|],);
|
||||
let result2 = DistPlusRenderer.runFunction(inputs1, (f, a), [|`SymbolicDist(`Float(20.0))|],);
|
||||
let result3 = DistPlusRenderer.runFunction(inputs1, (f, a), [|`SymbolicDist(`Float(40.0))|],);
|
||||
switch (result1, result2, result3) {
|
||||
| (Ok(`DistPlus(distPlus1)),Ok(`DistPlus(distPlus2)),Ok(`DistPlus(distPlus3))) =>
|
||||
<>
|
||||
<DistPlusPlot distPlus={DistPlus.T.normalize(distPlus1)} />
|
||||
<DistPlusPlot distPlus={DistPlus.T.normalize(distPlus2)} />
|
||||
<DistPlusPlot distPlus={DistPlus.T.normalize(distPlus3)} />
|
||||
</>
|
||||
| (Ok(`Function(f,a))) => "Function!!!" |> R.ste
|
||||
| (Error(r)) => r |> R.ste
|
||||
| _ => "Failure " |> R.ste
|
||||
};
|
||||
| Error(r) => r |> R.ste
|
||||
};
|
||||
| _ =>
|
||||
"Nothing to show. Try to change the distribution description."
|
||||
|
@ -329,10 +340,7 @@ let make = () => {
|
|||
<Antd.Form onSubmit>
|
||||
<Row _type=`flex className=Styles.rows>
|
||||
<Col span=24>
|
||||
<FieldText
|
||||
field=FormConfig.GuesstimatorString
|
||||
label="Program"
|
||||
/>
|
||||
<FieldText field=FormConfig.GuesstimatorString label="Program" />
|
||||
</Col>
|
||||
</Row>
|
||||
<Row _type=`flex className=Styles.rows>
|
||||
|
|
|
@ -104,7 +104,7 @@ let reducer = (state: state, action: action) =>
|
|||
let init = {
|
||||
showStats: false,
|
||||
showParams: false,
|
||||
showPercentiles: true,
|
||||
showPercentiles: false,
|
||||
distributions: [
|
||||
{yLog: false, xLog: false, isCumulative: false, height: 1},
|
||||
],
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
open ExpressionTypes.ExpressionTree;
|
||||
|
||||
let toLeaf = (samplingInputs, environment, node: node) => {
|
||||
node
|
||||
|> ExpressionTreeEvaluator.toLeaf({
|
||||
samplingInputs,
|
||||
environment,
|
||||
evaluateNode: ExpressionTreeEvaluator.toLeaf,
|
||||
});
|
||||
let envs = (samplingInputs, environment) => {
|
||||
{samplingInputs, environment, evaluateNode: ExpressionTreeEvaluator.toLeaf};
|
||||
};
|
||||
let toLeaf = (samplingInputs, environment, node: node) =>
|
||||
ExpressionTreeEvaluator.toLeaf(envs(samplingInputs, environment), node);
|
||||
|
||||
let rec toString: node => string =
|
||||
fun
|
||||
|
@ -27,7 +24,7 @@ let rec toString: node => string =
|
|||
| `Render(t) => toString(t)
|
||||
| `Symbol(t) => "Symbol: " ++ t
|
||||
| `FunctionCall(name, args) =>
|
||||
"[Fuction call: ("
|
||||
"[Function call: ("
|
||||
++ name
|
||||
++ (args |> E.A.fmap(toString) |> Js.String.concatMany(_, ","))
|
||||
++ ")]"
|
||||
|
@ -37,16 +34,6 @@ let rec toString: node => string =
|
|||
++ toString(internal)
|
||||
++ ")]";
|
||||
|
||||
let toLeaf = (samplingInputs, environment, node: node) => {
|
||||
switch(toLeaf(samplingInputs, environment, node)){
|
||||
| Ok(`SymbolicDist(n)) => `Render(`SymbolicDist(n)) |> toLeaf(samplingInputs, environment);
|
||||
| Ok(`Function(n)) => Ok(`Function(n))
|
||||
| Ok(`RenderedDist(n)) => `Normalize(`RenderedDist(n))|> toLeaf(samplingInputs, environment)
|
||||
| Error(e) => Error(e)
|
||||
| _ => Error("Wrong type returned")
|
||||
}
|
||||
}
|
||||
|
||||
let toShape = (samplingInputs, environment, node: node) => {
|
||||
switch (toLeaf(samplingInputs, environment, node)) {
|
||||
| Ok(`RenderedDist(shape)) => Ok(shape)
|
||||
|
@ -54,3 +41,8 @@ let toShape = (samplingInputs, environment, node: node) => {
|
|||
| Error(e) => Error(e)
|
||||
};
|
||||
};
|
||||
|
||||
let runFunction = (samplingInputs, environment, inputs, fn: PTypes.Function.t) => {
|
||||
let params = envs(samplingInputs, environment);
|
||||
PTypes.Function.run(params, inputs, fn)
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ module Function = {
|
|||
};
|
||||
evaluationParams.evaluateNode(newEvaluationParams, internals(t));
|
||||
} else {
|
||||
Error("Failure");
|
||||
Error("Wrong number of variables");
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -123,10 +123,7 @@ module Internals = {
|
|||
let inputsToLeaf = (inputs: inputs) => {
|
||||
MathJsParser.fromString(inputs.guesstimatorString)
|
||||
|> E.R.bind(_, g => runProgram(inputs, g))
|
||||
|> E.R.bind(_, r =>
|
||||
E.A.last(r)
|
||||
|> E.O.toResult("No rendered lines")
|
||||
);
|
||||
|> E.R.bind(_, r => E.A.last(r) |> E.O.toResult("No rendered lines"));
|
||||
};
|
||||
|
||||
let outputToDistPlus = (inputs: Inputs.inputs, shape: DistTypes.shape) => {
|
||||
|
@ -144,21 +141,54 @@ let run = (inputs: Inputs.inputs) => {
|
|||
inputs
|
||||
|> Internals.distPlusRenderInputsToInputs
|
||||
|> Internals.inputsToLeaf
|
||||
|> E.R.bind(_,r => switch(r){
|
||||
| `RenderedDist(n) => Ok(n)
|
||||
| _ => Error("Didn't output renderedDist")
|
||||
})
|
||||
|> E.R.bind(_, r =>
|
||||
switch (r) {
|
||||
| `RenderedDist(n) => Ok(n)
|
||||
| _ => Error("Didn't output renderedDist")
|
||||
}
|
||||
)
|
||||
|> E.R.fmap(Internals.outputToDistPlus(inputs));
|
||||
};
|
||||
|
||||
|
||||
let run2 = (inputs: Inputs.inputs) => {
|
||||
inputs
|
||||
|> Internals.distPlusRenderInputsToInputs
|
||||
|> Internals.inputsToLeaf
|
||||
|> E.R.bind(_,r => switch(r){
|
||||
| `RenderedDist(n) => Ok(`DistPlus(Internals.outputToDistPlus(inputs,n)))
|
||||
| `Function(n) => Ok(`Function(n))
|
||||
| _ => Error("Didn't output renderedDist")
|
||||
})
|
||||
};
|
||||
|> E.R.bind(_, r =>
|
||||
switch (r) {
|
||||
| `RenderedDist(n) =>
|
||||
Ok(`DistPlus(Internals.outputToDistPlus(inputs, n)))
|
||||
| `Function(n) => Ok(`Function(n))
|
||||
| _ => Error("Didn't output renderedDist")
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
let runFunction =
|
||||
(
|
||||
ins: Inputs.inputs,
|
||||
fn: (array(string), ExpressionTypes.ExpressionTree.node),
|
||||
fnInputs,
|
||||
) => {
|
||||
let (_, fns) = fn;
|
||||
let inputs = ins |> Internals.distPlusRenderInputsToInputs;
|
||||
let output =
|
||||
ExpressionTree.runFunction(
|
||||
{
|
||||
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),
|
||||
},
|
||||
inputs.environment,
|
||||
fnInputs,
|
||||
fn,
|
||||
);
|
||||
Js.log2("GOt output", output);
|
||||
switch (output) {
|
||||
| Ok(`RenderedDist(n)) => Ok(`DistPlus(Internals.outputToDistPlus(ins, n)))
|
||||
| Ok(`Function(n)) => Ok(`Function(n))
|
||||
| _ => Error("Didn't output renderedDist")
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user