flat-mcmc

Painless, efficient, general-purpose sampling from continuous distributions.
git clone git://git.jtobin.io/flat-mcmc.git
Log | Files | Refs | README | LICENSE

Rosenbrock.hs (553B)


      1 {-# OPTIONS_GHC -fno-warn-type-defaults #-}
      2 
      3 module Main where
      4 
      5 import Numeric.MCMC.Flat
      6 import qualified Data.Vector.Unboxed as U (unsafeIndex)
      7 
      8 rosenbrock :: Particle -> Double
      9 rosenbrock xs = negate (5  *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) where
     10   x0 = U.unsafeIndex xs 0
     11   x1 = U.unsafeIndex xs 1
     12 
     13 origin :: Ensemble
     14 origin = ensemble [
     15     particle [negate 1.0, negate 1.0]
     16   , particle [negate 1.0, 1.0]
     17   , particle [1.0, negate 1.0]
     18   , particle [1.0, 1.0]
     19   ]
     20 
     21 main :: IO ()
     22 main = withSystemRandom . asGenIO $ mcmc 100 origin rosenbrock
     23