hasty-hamiltonian

Speedy gradient-based traversal through parameter space.
git clone git://git.jtobin.io/hasty-hamiltonian.git
Log | Files | Refs | README | LICENSE

Rosenbrock.hs (412B)


      1 {-# OPTIONS_GHC -fno-warn-type-defaults #-}
      2 
      3 import Numeric.AD (grad)
      4 import Numeric.MCMC.Hamiltonian
      5 
      6 target :: Num a => [a] -> a
      7 target [x0, x1] = negate (100 * (x1 - x0 ^ 2) ^ 2 + (1 - x0) ^ 2)
      8 
      9 gTarget :: [Double] -> [Double]
     10 gTarget = grad target
     11 
     12 rosenbrock :: Target [Double]
     13 rosenbrock = Target target (Just gTarget)
     14 
     15 main :: IO ()
     16 main = withSystemRandom . asGenIO $ mcmc 100 0.05 20 [0, 0] rosenbrock
     17