Rosenbrock.hs (565B)
1 {-# OPTIONS_GHC -fno-warn-type-defaults #-} 2 3 module Main where 4 5 import Numeric.MCMC 6 7 target :: [Double] -> Double 8 target [x0, x1] = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) 9 10 rosenbrock :: Target [Double] 11 rosenbrock = Target target Nothing 12 13 transition :: Transition IO (Chain [Double] b) 14 transition = 15 concatT 16 (sampleT (metropolis 0.5) (metropolis 1.0)) 17 (sampleT (slice 2.0) (slice 3.0)) 18 19 main :: IO () 20 main = withSystemRandom . asGenIO $ \gen -> do 21 _ <- chain 100 [0, 0] transition rosenbrock gen 22 mcmc 100 [0, 0] transition rosenbrock gen 23