Starting to add Program file
This commit is contained in:
parent
0d5de854e3
commit
d17299a5b1
|
@ -1,13 +1,18 @@
|
|||
open ExpressionTypes.ExpressionTree;
|
||||
|
||||
let toShape = (intendedShapeLength: int, samplingInputs, node: node) => {
|
||||
let renderResult =
|
||||
`Render(`Normalize(node))
|
||||
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))
|
||||
|> toLeaf(intendedShapeLength, samplingInputs);
|
||||
|
||||
switch (renderResult) {
|
||||
| Ok(`RenderedDist(shape)) => Ok(shape)
|
||||
|
|
|
@ -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)))
|
||||
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);
|
||||
}
|
4
src/distPlus/expressionTree/Program.re
Normal file
4
src/distPlus/expressionTree/Program.re
Normal file
|
@ -0,0 +1,4 @@
|
|||
type t = ExpressionTypes.Program.program;
|
||||
|
||||
// let run = (p:program) => p |> E.A.last |> E.O.fmap(r =>
|
||||
// )
|
|
@ -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,
|
||||
|
|
|
@ -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))
|
||||
);
|
||||
};
|
Loading…
Reference in New Issue
Block a user