Booth.hs (469B)
1 {-# OPTIONS_GHC -fno-warn-type-defaults #-} 2 3 import Numeric.AD (grad) 4 import Numeric.MCMC.Hamiltonian 5 6 target :: RealFloat a => [a] -> a 7 target [x0, x1] = negate ((x0 + 2 * x1 - 7) ^ 2 + (2 * x0 + x1 - 5) ^ 2) 8 9 gTarget :: [Double] -> [Double] 10 gTarget = grad target 11 12 booth :: Target [Double] 13 booth = Target target (Just gTarget) 14 15 main :: IO () 16 main = withSystemRandom . asGenIO $ \gen -> do 17 _ <- chain 100 0.05 20 [0, 0] booth gen 18 mcmc 100 0.05 20 [0, 0] booth gen 19