Fix truncation
This commit is contained in:
parent
4cf7a69d3e
commit
89e07dad86
|
@ -172,7 +172,7 @@ let make = () => {
|
|||
~onSubmit=({state}) => {None},
|
||||
~initialState={
|
||||
//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",
|
||||
xPoint: "50.0",
|
||||
xPoint2: "60.0",
|
||||
|
|
|
@ -118,16 +118,17 @@ module PointwiseCombination = {
|
|||
};
|
||||
|
||||
module Truncate = {
|
||||
let trySimplification = (leftCutoff, rightCutoff, t) => {
|
||||
let trySimplification = (leftCutoff, rightCutoff, t): simplificationResult => {
|
||||
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))) =>
|
||||
// just create a new Uniform distribution
|
||||
let nu: SymbolicTypes.uniform = u;
|
||||
let newLow = max(E.O.default(neg_infinity, lc), nu.low);
|
||||
let newHigh = min(E.O.default(infinity, rc), nu.high);
|
||||
Ok(`SymbolicDist(`Uniform({low: newLow, high: newHigh})));
|
||||
| (_, _, t) => Ok(t)
|
||||
`Solution(`SymbolicDist(`Uniform({low: newLow, high: newHigh})));
|
||||
| _ => `NoSolution
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -135,7 +136,6 @@ module Truncate = {
|
|||
// 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
|
||||
let renderedShape = toLeaf(renderParams, `Render(t));
|
||||
|
||||
switch (renderedShape) {
|
||||
| Ok(`RenderedDist(rs)) =>
|
||||
let truncatedShape =
|
||||
|
@ -157,13 +157,10 @@ module Truncate = {
|
|||
: result(node, string) => {
|
||||
t
|
||||
|> trySimplification(leftCutoff, rightCutoff)
|
||||
|> E.R.bind(
|
||||
_,
|
||||
fun
|
||||
| `SymbolicDist(d) as t => Ok(t)
|
||||
| _ =>
|
||||
truncateAsShape(toLeaf, renderParams, leftCutoff, rightCutoff, t),
|
||||
);
|
||||
|> fun
|
||||
| `Solution(t) => Ok(t)
|
||||
| `Error(e) => Error(e)
|
||||
| `NoSolution => truncateAsShape(toLeaf, renderParams, leftCutoff, rightCutoff, t);
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -18,3 +18,9 @@ module ExpressionTree = {
|
|||
| `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,
|
||||
like in the case of a divide by 0.
|
||||
*/
|
||||
type analyticalSimplificationResult = [
|
||||
| `AnalyticalSolution(SymbolicTypes.symbolicDist)
|
||||
| `Error(string)
|
||||
| `NoSolution
|
||||
];
|
||||
let tryAnalyticalSimplification =
|
||||
(
|
||||
d1: symbolicDist,
|
||||
|
|
|
@ -46,4 +46,10 @@ type symbolicDist = [
|
|||
| `Triangular(triangular)
|
||||
| `ContinuousShape(continuousShape)
|
||||
| `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