flat-mcmc

Painless, efficient, general-purpose sampling from continuous distributions.
Log | Files | Refs | README | LICENSE

commit 9622e0ae714ed09ef5e3352010104999c1799fc8
parent 1b35e1cc34c41d93b11a887e37279622aade0e05
Author: Jared Tobin <jared@jtobin.ca>
Date:   Mon,  5 Nov 2012 13:27:38 +1300

Serialize to float rather than double.

Diffstat:
MExamples/code/SPDE_Flat.hs | 6++++--
MNumeric/MCMC/Flat.hs | 3++-
2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/Examples/code/SPDE_Flat.hs b/Examples/code/SPDE_Flat.hs @@ -1,3 +1,5 @@ +{-# LANGUAGE BangPatterns #-} + import System.IO import System.Exit import System.Environment @@ -8,8 +10,8 @@ import qualified Data.Vector as V target :: [Double] -> Double target xs = go 0 0 xs - where go t0 t1 [] = (- t0 / (2*h)) - (0.5 * h * t1) - go t0 t1 (u:us:uss) = go (t0 + (us - u)^2) (t1 + v (us + u)) uss + where go !t0 !t1 [] = (-t0 / (2*h)) - (0.5*h*t1) + go !t0 !t1 (u:us:uss) = go (t0 + (us - u)^2) (t1 + v (us + u)) uss h = 1 / fromIntegral (length xs) v x = (1 - x^2)^2 {-# INLINE target #-} diff --git a/Numeric/MCMC/Flat.hs b/Numeric/MCMC/Flat.hs @@ -16,6 +16,7 @@ import qualified Data.Vector.Unboxed as U import Control.Monad.Par (NFData) import Control.Monad.Par.Scheds.Direct import Control.Monad.Par.Combinator +import GHC.Float import System.IO -- | Parallel map with a specified granularity. @@ -34,7 +35,7 @@ data MarkovChain = MarkovChain { ensemble :: Ensemble -- | Display the current state. This will be very slow and should be replaced. instance Show MarkovChain where - show config = filter (`notElem` "[]") $ unlines $ map show (V.toList (ensemble config)) + show config = filter (`notElem` "[]") $ unlines $ map (show . map double2Float) (V.toList (ensemble config)) -- | Options for the chain. The target (expected to be a log density), as -- well as the size of the ensemble. The size should be an even number. Also