diff options
| author | Justin Bedo <cu@cua0.org> | 2026-02-20 14:09:42 +1100 |
|---|---|---|
| committer | Justin Bedo <cu@cua0.org> | 2026-02-20 14:09:42 +1100 |
| commit | 0e87d9352381c865ba91cffda353e394d0cf418f (patch) | |
| tree | 1f9074962d9748d584397942befbc8f8b6d13142 | |
| parent | 339dc051c0b37952ab9aa55a0983ec35ba03033f (diff) | |
prevent overflows on bounded
| -rw-r--r-- | src/PPL/Distr.hs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/PPL/Distr.hs b/src/PPL/Distr.hs index e1fd5aa..8ffbd0f 100644 --- a/src/PPL/Distr.hs +++ b/src/PPL/Distr.hs @@ -95,7 +95,9 @@ geom p = first 0 <$> iid (bern p) first _ _ = undefined bounded :: Double -> Double -> Prob Double -bounded lower upper = (+ lower) . (* (upper - lower)) <$> uniform +bounded lower upper = do + z <- uniform + pure $ 2 * (lower / 2 + (upper / 2 - lower / 2) * z) bounded' :: Integral a => a -> a -> Prob a bounded' lower upper = round <$> bounded (fromIntegral lower) (fromIntegral upper) |
