aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2023-01-17 09:12:18 +1100
committerJustin Bedo <cu@cua0.org>2023-01-20 09:17:05 +1100
commit0718de4acc18df39152fc55d6bd279af56d7e2af (patch)
tree36e8f2eed93680a35d68c12667aa473b0a087911
parent3f2bd030b69a11a0f409c715740ec4bf8536f8b1 (diff)
add some strictness
-rw-r--r--src/PPL/Internal.hs4
-rw-r--r--src/PPL/Sampling.hs2
2 files changed, 3 insertions, 3 deletions
diff --git a/src/PPL/Internal.hs b/src/PPL/Internal.hs
index 201a3aa..d927508 100644
--- a/src/PPL/Internal.hs
+++ b/src/PPL/Internal.hs
@@ -18,7 +18,7 @@ import Control.Monad.IO.Class
-- Reimplementation of the LazyPPL monads to avoid some dependencies
-data Tree = Tree Double [Tree]
+data Tree = Tree !Double [Tree]
split :: Tree -> (Tree, Tree)
split (Tree r (t : ts)) = (t, Tree r ts)
@@ -61,7 +61,7 @@ newtype Meas a = Meas (WriterT (Product (Log Double)) Prob a)
score :: Double -> Meas ()
score = scoreLog . Exp . log . max eps
where
- eps = $(TH.lift (until ((== 1) . (1 +)) (/ 2) (1 :: Double))) -- machine epsilon, force compile time eval
+ eps = $(TH.lift (2 * until ((== 1) . (1 +)) (/ 2) (1 :: Double))) -- machine epsilon, force compile time eval
{-# INLINE scoreLog #-}
scoreLog :: Log Double -> Meas ()
diff --git a/src/PPL/Sampling.hs b/src/PPL/Sampling.hs
index a3f38db..1d20838 100644
--- a/src/PPL/Sampling.hs
+++ b/src/PPL/Sampling.hs
@@ -42,7 +42,7 @@ mh p m = do
ratio = w' / w
(Exp . log -> r, g3) = random g2
put g3
- pure $
+ pure $!
if r < ratio
then (t', x', w')
else (t, x, w)