hasty-hamiltonian

Speedy gradient-based traversal through parameter space.
Log | Files | Refs | README | LICENSE

commit 343534c207cbdbb35609509d61954259c822b944
parent 49f111bb128bb4204af8d73dc6d6888a98bbfab9
Author: Jared Tobin <jared@jtobin.ca>
Date:   Mon, 12 Nov 2012 13:08:58 +1300

Various tweaks.

Diffstat:
M.gitignore | 1+
MExamples/code/SPDE_HMC.hs | 4++--
MNumeric/MCMC/Hamiltonian.hs | 8++++----
Mhasty-hamiltonian.cabal | 2+-
4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -7,3 +7,4 @@ Setup.hs *.o demos data +benchmarks diff --git a/Examples/code/SPDE_HMC.hs b/Examples/code/SPDE_HMC.hs @@ -10,8 +10,8 @@ import Numeric.AD target :: RealFloat a => [a] -> a 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/Hamiltonian.hs b/Numeric/MCMC/Hamiltonian.hs @@ -37,9 +37,9 @@ leapfrog t0 r0 = do Options _ gTarget ndisc e <- ask let go !t !r n | n == 0 = (t, r) - | otherwise = let rm = zipWith (+) r (map (* (0.5*e)) (gTarget t)) - tt = zipWith (+) t (map (*e) rm) - rt = zipWith (+) rm (map (* (0.5*e)) (gTarget tt)) + | otherwise = let rm = zipWith (+) r (map (* (0.5*e)) (gTarget t)) + tt = zipWith (+) t (map (*e) rm) + rt = zipWith (+) rm (map (* (0.5*e)) (gTarget tt)) in go tt rt (n - 1) return $! go t0 r0 ndisc {-# INLINE leapfrog #-} @@ -61,7 +61,7 @@ metropolisStep state g = do then (t, 1) else (t0, 0) - xs <.> ys = sum $ zipWith (*) xs ys + xs <.> ys = sum $ zipWith (*) xs ys arRatio = target t + 0.5*(r0 <.> r0) - target t0 - 0.5*(r <.> r) diff --git a/hasty-hamiltonian.cabal b/hasty-hamiltonian.cabal @@ -25,5 +25,5 @@ Source-repository head library exposed-modules: Numeric.MCMC.Hamiltonian -- other-modules: - build-depends: base ==4.*, mtl ==2.1.*, primitive ==0.4.*, mwc-random ==0.12.* + build-depends: base ==4.*, mtl ==2.1.*, primitive ==0.4.*, mwc-random ==0.12.*, parallel ==3.2.* ghc-options: -Wall