Simple debugging changes
This commit is contained in:
parent
27611ee7bf
commit
800eb41e3f
|
@ -1,31 +1,6 @@
|
||||||
open ExpressionTypes.ExpressionTree;
|
open ExpressionTypes.ExpressionTree;
|
||||||
|
|
||||||
let rec toString: node => string =
|
let toString = ExpressionTreeBasic.toString;
|
||||||
fun
|
|
||||||
| `SymbolicDist(d) => SymbolicDist.T.toString(d)
|
|
||||||
| `RenderedDist(_) => "[renderedShape]"
|
|
||||||
| `AlgebraicCombination(op, t1, t2) =>
|
|
||||||
Operation.Algebraic.format(op, toString(t1), toString(t2))
|
|
||||||
| `PointwiseCombination(op, t1, t2) =>
|
|
||||||
Operation.Pointwise.format(op, toString(t1), toString(t2))
|
|
||||||
| `Normalize(t) => "normalize(k" ++ toString(t) ++ ")"
|
|
||||||
| `Truncate(lc, rc, t) =>
|
|
||||||
Operation.T.truncateToString(lc, rc, toString(t))
|
|
||||||
| `Render(t) => toString(t)
|
|
||||||
| `Symbol(t) => "Symbol: " ++ t
|
|
||||||
| `FunctionCall(name, args) =>
|
|
||||||
"[Function call: ("
|
|
||||||
++ name
|
|
||||||
++ (args |> E.A.fmap(toString) |> Js.String.concatMany(_, ","))
|
|
||||||
++ ")]"
|
|
||||||
| `Function(args, internal) =>
|
|
||||||
"[Function: ("
|
|
||||||
++ (args |> Js.String.concatMany(_, ","))
|
|
||||||
++ toString(internal)
|
|
||||||
++ ")]"
|
|
||||||
| `Array(_) => "Array"
|
|
||||||
| `Hash(_) => "Hash"
|
|
||||||
|
|
||||||
let envs = (samplingInputs, environment) => {
|
let envs = (samplingInputs, environment) => {
|
||||||
{samplingInputs, environment, evaluateNode: ExpressionTreeEvaluator.toLeaf};
|
{samplingInputs, environment, evaluateNode: ExpressionTreeEvaluator.toLeaf};
|
||||||
};
|
};
|
||||||
|
@ -42,5 +17,5 @@ let toShape = (samplingInputs, environment, node: node) => {
|
||||||
|
|
||||||
let runFunction = (samplingInputs, environment, inputs, fn: PTypes.Function.t) => {
|
let runFunction = (samplingInputs, environment, inputs, fn: PTypes.Function.t) => {
|
||||||
let params = envs(samplingInputs, environment);
|
let params = envs(samplingInputs, environment);
|
||||||
PTypes.Function.run(params, inputs, fn)
|
PTypes.Function.run(params, inputs, fn);
|
||||||
}
|
};
|
||||||
|
|
35
src/distPlus/expressionTree/ExpressionTreeBasic.re
Normal file
35
src/distPlus/expressionTree/ExpressionTreeBasic.re
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
open ExpressionTypes.ExpressionTree;
|
||||||
|
|
||||||
|
let rec toString: node => string =
|
||||||
|
fun
|
||||||
|
| `SymbolicDist(d) => SymbolicDist.T.toString(d)
|
||||||
|
| `RenderedDist(_) => "[renderedShape]"
|
||||||
|
| `AlgebraicCombination(op, t1, t2) =>
|
||||||
|
Operation.Algebraic.format(op, toString(t1), toString(t2))
|
||||||
|
| `PointwiseCombination(op, t1, t2) =>
|
||||||
|
Operation.Pointwise.format(op, toString(t1), toString(t2))
|
||||||
|
| `Normalize(t) => "normalize(k" ++ toString(t) ++ ")"
|
||||||
|
| `Truncate(lc, rc, t) =>
|
||||||
|
Operation.T.truncateToString(lc, rc, toString(t))
|
||||||
|
| `Render(t) => toString(t)
|
||||||
|
| `Symbol(t) => "Symbol: " ++ t
|
||||||
|
| `FunctionCall(name, args) =>
|
||||||
|
"[Function call: ("
|
||||||
|
++ name
|
||||||
|
++ (args |> E.A.fmap(toString) |> Js.String.concatMany(_, ","))
|
||||||
|
++ ")]"
|
||||||
|
| `Function(args, internal) =>
|
||||||
|
"[Function: ("
|
||||||
|
++ (args |> Js.String.concatMany(_, ","))
|
||||||
|
++ toString(internal)
|
||||||
|
++ ")]"
|
||||||
|
| `Array(a) =>
|
||||||
|
"[" ++ (a |> E.A.fmap(toString) |> Js.String.concatMany(_, ",")) ++ "]"
|
||||||
|
| `Hash(h) =>
|
||||||
|
"{"
|
||||||
|
++ (
|
||||||
|
h
|
||||||
|
|> E.A.fmap(((name, value)) => name ++ ":" ++ toString(value))
|
||||||
|
|> Js.String.concatMany(_, ",")
|
||||||
|
)
|
||||||
|
++ "}";
|
|
@ -1,7 +1,9 @@
|
||||||
open TypeSystem;
|
open TypeSystem;
|
||||||
|
|
||||||
let wrongInputsError = r => {
|
let wrongInputsError = (r: array(typedValue)) => {
|
||||||
Error("Wrong inputs");
|
let inputs = r |> E.A.fmap(TypedValue.toString) |>Js.String.concatMany(_, ",");
|
||||||
|
Js.log3("Inputs were", inputs, r);
|
||||||
|
Error("Wrong inputs. The inputs were:" ++ inputs);
|
||||||
};
|
};
|
||||||
|
|
||||||
let to_: (float, float) => result(node, string) =
|
let to_: (float, float) => result(node, string) =
|
||||||
|
@ -46,6 +48,7 @@ let makeDistFloat = (name, fn) =>
|
||||||
~run=
|
~run=
|
||||||
fun
|
fun
|
||||||
| [|`SamplingDist(a), `Float(b)|] => fn(a, b)
|
| [|`SamplingDist(a), `Float(b)|] => fn(a, b)
|
||||||
|
| [|`RenderedDist(a), `Float(b)|] => fn(`RenderedDist(a), b)
|
||||||
| e => wrongInputsError(e),
|
| e => wrongInputsError(e),
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
|
@ -55,6 +58,7 @@ let makeRenderedDistFloat = (name, fn) =>
|
||||||
~name,
|
~name,
|
||||||
~outputType=`RenderedDistribution,
|
~outputType=`RenderedDistribution,
|
||||||
~inputTypes=[|`RenderedDistribution, `Float|],
|
~inputTypes=[|`RenderedDistribution, `Float|],
|
||||||
|
~shouldCoerceTypes=true,
|
||||||
~run=
|
~run=
|
||||||
fun
|
fun
|
||||||
| [|`RenderedDist(a), `Float(b)|] => fn(a, b)
|
| [|`RenderedDist(a), `Float(b)|] => fn(a, b)
|
||||||
|
@ -70,6 +74,7 @@ let makeDist = (name, fn) =>
|
||||||
~run=
|
~run=
|
||||||
fun
|
fun
|
||||||
| [|`SamplingDist(a)|] => fn(a)
|
| [|`SamplingDist(a)|] => fn(a)
|
||||||
|
| [|`RenderedDist(a)|] => fn(`RenderedDist(a))
|
||||||
| e => wrongInputsError(e),
|
| e => wrongInputsError(e),
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
|
|
|
@ -36,6 +36,22 @@ type functions = array(_function);
|
||||||
type inputNodes = array(node);
|
type inputNodes = array(node);
|
||||||
|
|
||||||
module TypedValue = {
|
module TypedValue = {
|
||||||
|
let rec toString: typedValue => string =
|
||||||
|
fun
|
||||||
|
| `SamplingDist(_) => "[sampling dist]"
|
||||||
|
| `RenderedDist(_) => "[rendered Shape]"
|
||||||
|
| `Float(f) => "Float: " ++ Js.Float.toString(f)
|
||||||
|
| `Array(a) =>
|
||||||
|
"[" ++ (a |> E.A.fmap(toString) |> Js.String.concatMany(_, ",")) ++ "]"
|
||||||
|
| `Hash(v) =>
|
||||||
|
"{"
|
||||||
|
++ (
|
||||||
|
v
|
||||||
|
|> E.A.fmap(((name, value)) => name ++ ":" ++ toString(value))
|
||||||
|
|> Js.String.concatMany(_, ",")
|
||||||
|
)
|
||||||
|
++ "}";
|
||||||
|
|
||||||
let rec fromNode = (node: node): result(typedValue, string) =>
|
let rec fromNode = (node: node): result(typedValue, string) =>
|
||||||
switch (ExpressionTypes.ExpressionTree.toFloatIfNeeded(node)) {
|
switch (ExpressionTypes.ExpressionTree.toFloatIfNeeded(node)) {
|
||||||
| `SymbolicDist(`Float(r)) => Ok(`Float(r))
|
| `SymbolicDist(`Float(r)) => Ok(`Float(r))
|
||||||
|
@ -51,7 +67,7 @@ module TypedValue = {
|
||||||
|> E.A.fmap(((name, t)) => fromNode(t) |> E.R.fmap(r => (name, r)))
|
|> E.A.fmap(((name, t)) => fromNode(t) |> E.R.fmap(r => (name, r)))
|
||||||
|> E.A.R.firstErrorOrOpen
|
|> E.A.R.firstErrorOrOpen
|
||||||
|> E.R.fmap(r => `Hash(r))
|
|> E.R.fmap(r => `Hash(r))
|
||||||
| _ => Error("Wrong type")
|
| e => Error("Wrong type: " ++ ExpressionTreeBasic.toString(e))
|
||||||
};
|
};
|
||||||
|
|
||||||
// todo: Arrays and hashes
|
// todo: Arrays and hashes
|
||||||
|
@ -103,12 +119,12 @@ module TypedValue = {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
let toFloat: typedValue => result(float,string) =
|
let toFloat: typedValue => result(float, string) =
|
||||||
fun
|
fun
|
||||||
| `Float(x) => Ok(x)
|
| `Float(x) => Ok(x)
|
||||||
| _ => Error("Not a float");
|
| _ => Error("Not a float");
|
||||||
|
|
||||||
let toArray: typedValue => result(array('a),string) =
|
let toArray: typedValue => result(array('a), string) =
|
||||||
fun
|
fun
|
||||||
| `Array(x) => Ok(x)
|
| `Array(x) => Ok(x)
|
||||||
| _ => Error("Not an array");
|
| _ => Error("Not an array");
|
||||||
|
@ -118,12 +134,13 @@ module TypedValue = {
|
||||||
| `Hash(x) => Ok(x)
|
| `Hash(x) => Ok(x)
|
||||||
| _ => Error("Not a named item");
|
| _ => Error("Not a named item");
|
||||||
|
|
||||||
let toDist =
|
let toDist: typedValue => result(node,string) =
|
||||||
fun
|
fun
|
||||||
| `SamplingDist(`SymbolicDist(c)) => Ok(`SymbolicDist(c))
|
| `SamplingDist(`SymbolicDist(c)) => Ok(`SymbolicDist(c))
|
||||||
| `SamplingDist(`RenderedDist(c)) => Ok(`RenderedDist(c))
|
| `SamplingDist(`RenderedDist(c)) => Ok(`RenderedDist(c))
|
||||||
|
| `RenderedDist(c) => Ok(`RenderedDist(c))
|
||||||
| `Float(x) => Ok(`SymbolicDist(`Float(x)))
|
| `Float(x) => Ok(`SymbolicDist(`Float(x)))
|
||||||
| _ => Error("Cannot be converted into a distribution");
|
| x => Error("Cannot be converted into a distribution: " ++ toString(x));
|
||||||
};
|
};
|
||||||
|
|
||||||
module Function = {
|
module Function = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user