Moved truncateString work to separate section
This commit is contained in:
parent
4663700f67
commit
99c0803953
|
@ -279,7 +279,7 @@ module T = {
|
||||||
| `Error(string)
|
| `Error(string)
|
||||||
| `NoSolution
|
| `NoSolution
|
||||||
];
|
];
|
||||||
let attemptAlgebraicOperation =
|
let attemptAnalyticalOperation =
|
||||||
(
|
(
|
||||||
d1: symbolicDist,
|
d1: symbolicDist,
|
||||||
d2: symbolicDist,
|
d2: symbolicDist,
|
||||||
|
|
|
@ -110,6 +110,13 @@ module Scale = {
|
||||||
| `Exponentiate => ( ** )
|
| `Exponentiate => ( ** )
|
||||||
| `Log => ((a, b) => log(a) /. log(b));
|
| `Log => ((a, b) => log(a) /. log(b));
|
||||||
|
|
||||||
|
let format = (operation:t, value, scaleBy) =>
|
||||||
|
switch (operation) {
|
||||||
|
| `Multiply => {j|scaleMultiply($value, $scaleBy) |j}
|
||||||
|
| `Exponentiate => {j|ScaleExponentiate($value, $scaleBy) |j}
|
||||||
|
| `Log => {j|ScaleLog($value, $scaleBy) |j}
|
||||||
|
};
|
||||||
|
|
||||||
let toKnownIntegralSumFn =
|
let toKnownIntegralSumFn =
|
||||||
fun
|
fun
|
||||||
| `Multiply => ((a, b) => Some(a *. b))
|
| `Multiply => ((a, b) => Some(a *. b))
|
||||||
|
|
|
@ -5,6 +5,7 @@ type leaf = [
|
||||||
| `SymbolicDist(SymbolicTypes.symbolicDist)
|
| `SymbolicDist(SymbolicTypes.symbolicDist)
|
||||||
| `RenderedDist(DistTypes.shape)
|
| `RenderedDist(DistTypes.shape)
|
||||||
];
|
];
|
||||||
|
|
||||||
/* TreeNodes are either Data (i.e. symbolic or rendered distributions) or Operations. Operations always refer to two child nodes.*/
|
/* TreeNodes are either Data (i.e. symbolic or rendered distributions) or Operations. Operations always refer to two child nodes.*/
|
||||||
type treeNode = [ | `Leaf(leaf) | `Operation(operation)]
|
type treeNode = [ | `Leaf(leaf) | `Operation(operation)]
|
||||||
and operation = [
|
and operation = [
|
||||||
|
@ -19,25 +20,29 @@ and operation = [
|
||||||
|
|
||||||
module Operation = {
|
module Operation = {
|
||||||
type t = operation;
|
type t = operation;
|
||||||
|
let truncateToString =
|
||||||
|
(left: option(float), right: option(float), nodeToString) => {
|
||||||
|
let left = left |> E.O.dimap(Js.Float.toString, () => "-inf");
|
||||||
|
let right = right |> E.O.dimap(Js.Float.toString, () => "inf");
|
||||||
|
{j|truncate($nodeToString, $left, $right)|j};
|
||||||
|
};
|
||||||
|
|
||||||
let toString = nodeToString =>
|
let toString = nodeToString =>
|
||||||
fun
|
fun
|
||||||
| `AlgebraicCombination(op, t1, t2) =>
|
| `AlgebraicCombination(op, t1, t2) =>
|
||||||
SymbolicTypes.Algebraic.format(op, nodeToString(t1), nodeToString(t2))
|
SymbolicTypes.Algebraic.format(op, nodeToString(t1), nodeToString(t2))
|
||||||
| `PointwiseCombination(op, t1, t2) =>
|
| `PointwiseCombination(op, t1, t2) =>
|
||||||
SymbolicTypes.Pointwise.format(op, nodeToString(t1), nodeToString(t2))
|
SymbolicTypes.Pointwise.format(op, nodeToString(t1), nodeToString(t2))
|
||||||
| `VerticalScaling(_scaleOp, t, scaleBy) =>
|
| `VerticalScaling(scaleOp, t, scaleBy) =>
|
||||||
nodeToString(t) ++ " @ " ++ nodeToString(scaleBy)
|
SymbolicTypes.Scale.format(
|
||||||
|
scaleOp,
|
||||||
|
nodeToString(t),
|
||||||
|
nodeToString(scaleBy),
|
||||||
|
)
|
||||||
| `Normalize(t) => "normalize(" ++ nodeToString(t) ++ ")"
|
| `Normalize(t) => "normalize(" ++ nodeToString(t) ++ ")"
|
||||||
| `FloatFromDist(floatFromDistOp, t) =>
|
| `FloatFromDist(floatFromDistOp, t) =>
|
||||||
SymbolicTypes.DistToFloat.format(floatFromDistOp, nodeToString(t))
|
SymbolicTypes.DistToFloat.format(floatFromDistOp, nodeToString(t))
|
||||||
| `Truncate(lc, rc, t) =>
|
| `Truncate(lc, rc, t) => truncateToString(lc, rc, nodeToString(t))
|
||||||
"truncate("
|
|
||||||
++ nodeToString(t)
|
|
||||||
++ ", "
|
|
||||||
++ E.O.dimap(Js.Float.toString, () => "-inf", lc)
|
|
||||||
++ ", "
|
|
||||||
++ E.O.dimap(Js.Float.toString, () => "inf", rc)
|
|
||||||
++ ")"
|
|
||||||
| `Render(t) => nodeToString(t);
|
| `Render(t) => nodeToString(t);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -70,7 +75,7 @@ module TreeNode = {
|
||||||
`Leaf(`SymbolicDist(d2)),
|
`Leaf(`SymbolicDist(d2)),
|
||||||
),
|
),
|
||||||
) as t =>
|
) as t =>
|
||||||
switch (SymbolicDist.T.attemptAlgebraicOperation(d1, d2, operation)) {
|
switch (SymbolicDist.T.attemptAnalyticalOperation(d1, d2, operation)) {
|
||||||
| `AnalyticalSolution(symbolicDist) =>
|
| `AnalyticalSolution(symbolicDist) =>
|
||||||
Ok(`Leaf(`SymbolicDist(symbolicDist)))
|
Ok(`Leaf(`SymbolicDist(symbolicDist)))
|
||||||
| `Error(er) => Error(er)
|
| `Error(er) => Error(er)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user