From 9cdcc85d6c0605883a08a0abf4bcb102e2015013 Mon Sep 17 00:00:00 2001 From: Sebastian Kosch Date: Thu, 16 Jul 2020 20:50:12 -0700 Subject: [PATCH] Fix broken filter in Discrete.truncate; switch to epsilon_float in Continuous.truncate --- src/distPlus/distribution/Continuous.re | 6 ++---- src/distPlus/distribution/Discrete.re | 2 +- src/distPlus/expressionTree/ExpressionTreeEvaluator.re | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/distPlus/distribution/Continuous.re b/src/distPlus/distribution/Continuous.re index 288360f0..223f1693 100644 --- a/src/distPlus/distribution/Continuous.re +++ b/src/distPlus/distribution/Continuous.re @@ -167,12 +167,10 @@ module T = |> XYShape.T.zip |> XYShape.Zipped.filterByX(x => x >= lc && x <= rc); - let eps = (t |> getShape |> XYShape.T.xTotalRange) *. 0.0001; - let leftNewPoint = - leftCutoff |> E.O.dimap(lc => [|(lc -. eps, 0.)|], _ => [||]); + leftCutoff |> E.O.dimap(lc => [|(lc -. epsilon_float, 0.)|], _ => [||]); let rightNewPoint = - rightCutoff |> E.O.dimap(rc => [|(rc +. eps, 0.)|], _ => [||]); + rightCutoff |> E.O.dimap(rc => [|(rc +. epsilon_float, 0.)|], _ => [||]); let truncatedZippedPairsWithNewPoints = E.A.concatMany([|leftNewPoint, truncatedZippedPairs, rightNewPoint|]); diff --git a/src/distPlus/distribution/Discrete.re b/src/distPlus/distribution/Discrete.re index 02c8b45a..cf0a7b55 100644 --- a/src/distPlus/distribution/Discrete.re +++ b/src/distPlus/distribution/Discrete.re @@ -203,7 +203,7 @@ module T = |> XYShape.T.zip |> XYShape.Zipped.filterByX(x => x >= E.O.default(neg_infinity, leftCutoff) - || x <= E.O.default(infinity, rightCutoff) + && x <= E.O.default(infinity, rightCutoff) ) |> XYShape.T.fromZippedArray; diff --git a/src/distPlus/expressionTree/ExpressionTreeEvaluator.re b/src/distPlus/expressionTree/ExpressionTreeEvaluator.re index 77f415d2..76775759 100644 --- a/src/distPlus/expressionTree/ExpressionTreeEvaluator.re +++ b/src/distPlus/expressionTree/ExpressionTreeEvaluator.re @@ -177,7 +177,7 @@ module Truncate = { let truncateAsShape = (evaluationParams: evaluationParams, leftCutoff, rightCutoff, t) => { - // TODO: use named args in renderToShape; if we're lucky we can at least get the tail + // TODO: use named args for xMin/xMax in renderToShape; if we're lucky we can at least get the tail // of a distribution we otherwise wouldn't get at all switch (render(evaluationParams, t)) { | Ok(`RenderedDist(rs)) =>