Fix truncation
This commit is contained in:
parent
4cf7a69d3e
commit
89e07dad86
|
@ -172,7 +172,7 @@ let make = () => {
|
||||||
~onSubmit=({state}) => {None},
|
~onSubmit=({state}) => {None},
|
||||||
~initialState={
|
~initialState={
|
||||||
//guesstimatorString: "mm(normal(-10, 2), uniform(18, 25), lognormal({mean: 10, stdev: 8}), triangular(31,40,50))",
|
//guesstimatorString: "mm(normal(-10, 2), uniform(18, 25), lognormal({mean: 10, stdev: 8}), triangular(31,40,50))",
|
||||||
guesstimatorString: "uniform(0, 1) * normal(1, 2) - 1",
|
guesstimatorString: "truncate(normal(100, 60), 50, 100)",
|
||||||
domainType: "Complete",
|
domainType: "Complete",
|
||||||
xPoint: "50.0",
|
xPoint: "50.0",
|
||||||
xPoint2: "60.0",
|
xPoint2: "60.0",
|
||||||
|
|
|
@ -118,16 +118,17 @@ module PointwiseCombination = {
|
||||||
};
|
};
|
||||||
|
|
||||||
module Truncate = {
|
module Truncate = {
|
||||||
let trySimplification = (leftCutoff, rightCutoff, t) => {
|
let trySimplification = (leftCutoff, rightCutoff, t): simplificationResult => {
|
||||||
switch (leftCutoff, rightCutoff, t) {
|
switch (leftCutoff, rightCutoff, t) {
|
||||||
| (None, None, t) => Ok(t)
|
| (None, None, t) => `Solution(t)
|
||||||
|
| (Some(lc), Some(rc), t) when lc > rc => `Error("Left truncation bound must be smaller than right bound.")
|
||||||
| (lc, rc, `SymbolicDist(`Uniform(u))) =>
|
| (lc, rc, `SymbolicDist(`Uniform(u))) =>
|
||||||
// just create a new Uniform distribution
|
// just create a new Uniform distribution
|
||||||
let nu: SymbolicTypes.uniform = u;
|
let nu: SymbolicTypes.uniform = u;
|
||||||
let newLow = max(E.O.default(neg_infinity, lc), nu.low);
|
let newLow = max(E.O.default(neg_infinity, lc), nu.low);
|
||||||
let newHigh = min(E.O.default(infinity, rc), nu.high);
|
let newHigh = min(E.O.default(infinity, rc), nu.high);
|
||||||
Ok(`SymbolicDist(`Uniform({low: newLow, high: newHigh})));
|
`Solution(`SymbolicDist(`Uniform({low: newLow, high: newHigh})));
|
||||||
| (_, _, t) => Ok(t)
|
| _ => `NoSolution
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -135,7 +136,6 @@ module Truncate = {
|
||||||
// TODO: use named args in renderToShape; if we're lucky we can at least get the tail
|
// TODO: use named args in renderToShape; if we're lucky we can at least get the tail
|
||||||
// of a distribution we otherwise wouldn't get at all
|
// of a distribution we otherwise wouldn't get at all
|
||||||
let renderedShape = toLeaf(renderParams, `Render(t));
|
let renderedShape = toLeaf(renderParams, `Render(t));
|
||||||
|
|
||||||
switch (renderedShape) {
|
switch (renderedShape) {
|
||||||
| Ok(`RenderedDist(rs)) =>
|
| Ok(`RenderedDist(rs)) =>
|
||||||
let truncatedShape =
|
let truncatedShape =
|
||||||
|
@ -157,13 +157,10 @@ module Truncate = {
|
||||||
: result(node, string) => {
|
: result(node, string) => {
|
||||||
t
|
t
|
||||||
|> trySimplification(leftCutoff, rightCutoff)
|
|> trySimplification(leftCutoff, rightCutoff)
|
||||||
|> E.R.bind(
|
|> fun
|
||||||
_,
|
| `Solution(t) => Ok(t)
|
||||||
fun
|
| `Error(e) => Error(e)
|
||||||
| `SymbolicDist(d) as t => Ok(t)
|
| `NoSolution => truncateAsShape(toLeaf, renderParams, leftCutoff, rightCutoff, t);
|
||||||
| _ =>
|
|
||||||
truncateAsShape(toLeaf, renderParams, leftCutoff, rightCutoff, t),
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,3 +18,9 @@ module ExpressionTree = {
|
||||||
| `FloatFromDist(distToFloatOperation, node)
|
| `FloatFromDist(distToFloatOperation, node)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type simplificationResult = [
|
||||||
|
| `Solution(ExpressionTree.node)
|
||||||
|
| `Error(string)
|
||||||
|
| `NoSolution
|
||||||
|
];
|
||||||
|
|
|
@ -274,11 +274,6 @@ module T = {
|
||||||
can still return an error if there is a serious problem,
|
can still return an error if there is a serious problem,
|
||||||
like in the case of a divide by 0.
|
like in the case of a divide by 0.
|
||||||
*/
|
*/
|
||||||
type analyticalSimplificationResult = [
|
|
||||||
| `AnalyticalSolution(SymbolicTypes.symbolicDist)
|
|
||||||
| `Error(string)
|
|
||||||
| `NoSolution
|
|
||||||
];
|
|
||||||
let tryAnalyticalSimplification =
|
let tryAnalyticalSimplification =
|
||||||
(
|
(
|
||||||
d1: symbolicDist,
|
d1: symbolicDist,
|
||||||
|
|
|
@ -47,3 +47,9 @@ type symbolicDist = [
|
||||||
| `ContinuousShape(continuousShape)
|
| `ContinuousShape(continuousShape)
|
||||||
| `Float(float) // Dirac delta at x. Practically useful only in the context of multimodals.
|
| `Float(float) // Dirac delta at x. Practically useful only in the context of multimodals.
|
||||||
];
|
];
|
||||||
|
|
||||||
|
type analyticalSimplificationResult = [
|
||||||
|
| `AnalyticalSolution(symbolicDist)
|
||||||
|
| `Error(string)
|
||||||
|
| `NoSolution
|
||||||
|
];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user