mighty-metropolis

The classic Metropolis algorithm.
Log | Files | Refs | README | LICENSE

commit 7304eeaf6f3f44f8902e8e3b156402fa830f0897
parent cccf03d0cc41b2d20797af95ef02df5874d59dc0
Author: Jared Tobin <jared@jtobin.ca>
Date:   Tue, 20 Dec 2016 07:17:55 +1300

Generalize base monad.

Resolves #1.

This lets you use the sampler over any monad that's an instance of both
MonadIO and PrimMonad.

Diffstat:
MCHANGELOG | 6+++++-
MNumeric/MCMC/Metropolis.hs | 11++++++-----
Mmighty-metropolis.cabal | 2+-
3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,6 +1,10 @@ # Changelog +- 1.1.0 (2016-12-20) + * Generalize base monad requirement to something matching both MonadIO and + PrimState. + - 1.0.4 (2016-12-04) - * Add missing dependency bounds. + * Add missing dependency bounds. diff --git a/Numeric/MCMC/Metropolis.hs b/Numeric/MCMC/Metropolis.hs @@ -32,9 +32,10 @@ module Numeric.MCMC.Metropolis ( ) where import Control.Monad (when) -import Control.Monad.Primitive (PrimMonad, PrimState, RealWorld) +import Control.Monad.Primitive (PrimMonad, PrimState) import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.State.Strict (execStateT, get, put) +import Control.Monad.IO.Class (MonadIO, liftIO) import Data.Sampling.Types (Target(..), Chain(..), Transition) #if __GLASGOW_HASKELL__ < 710 import Data.Traversable (Traversable, traverse) @@ -89,17 +90,17 @@ chain radial = loop where -- 0.5000462419822702,0.5693944056267897 -- -0.7525995304580824,1.2240725505283248 mcmc - :: (Traversable f, Show (f Double)) + :: (MonadIO m, PrimMonad m, Traversable f, Show (f Double)) => Int -> Double -> f Double -> (f Double -> Double) - -> Gen RealWorld - -> IO () + -> Gen (PrimState m) + -> m () mcmc n radial chainPosition target gen = runEffect $ chain radial Chain {..} gen >-> Pipes.take n - >-> Pipes.mapM_ print + >-> Pipes.mapM_ (liftIO . print) where chainScore = lTarget chainTarget chainPosition chainTunables = Nothing diff --git a/mighty-metropolis.cabal b/mighty-metropolis.cabal @@ -1,5 +1,5 @@ name: mighty-metropolis -version: 1.0.4 +version: 1.1.0 synopsis: The Metropolis algorithm. homepage: http://github.com/jtobin/mighty-metropolis license: MIT