Beale.hs (577B)
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] 8 | and [x0 >= -4.5, x0 <= 4.5, x1 >= -4.5, x1 <= 4.5] 9 = negate $ (1.5 - x0 + x0 * x1) ^ 2 10 + (2.25 - x0 + x0 * x1 ^ 2) ^ 2 11 + (2.625 - x0 + x0 * x1 ^ 3) ^ 2 12 | otherwise = - (1 / 0) 13 14 gTarget :: [Double] -> [Double] 15 gTarget = grad target 16 17 beale :: Target [Double] 18 beale = Target target (Just gTarget) 19 20 main :: IO () 21 main = withSystemRandom . asGenIO $ mcmc 10000 0.05 20 [0, 0] beale 22 23