hasty-hamiltonian

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

README.md (1491B)


      1 # hasty-hamiltonian
      2 
      3 [![Build Status](https://secure.travis-ci.org/jtobin/hasty-hamiltonian.png)](http://travis-ci.org/jtobin/hasty-hamiltonian)
      4 [![Hackage Version](https://img.shields.io/hackage/v/hasty-hamiltonian.svg)](http://hackage.haskell.org/package/hasty-hamiltonian)
      5 [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jtobin/hasty-hamiltonian/blob/master/LICENSE)
      6 
      7 
      8 Speedy, gradient-based traversal through parameter space.
      9 
     10 Exports a `mcmc` function that prints a trace to stdout, a `chain` function for
     11 collecting results in memory, and a `hamiltonian` transition operator that can
     12 be used more generally.
     13 
     14 If you don't want to calculate your gradients by hand you can use the handy
     15 [ad](https://hackage.haskell.org/package/ad) library for automatic
     16 differentiation.
     17 
     18     import Numeric.AD (grad)
     19     import Numeric.MCMC.Hamiltonian
     20 
     21     target :: RealFloat a => [a] -> a
     22     target [x0, x1] = negate ((x0 + 2 * x1 - 7) ^ 2 + (2 * x0 + x1 - 5) ^ 2)
     23 
     24     gTarget :: [Double] -> [Double]
     25     gTarget = grad target
     26 
     27     booth :: Target [Double]
     28     booth = Target target (Just gTarget)
     29 
     30     main :: IO ()
     31     main = withSystemRandom . asGenIO $ mcmc 10000 0.05 20 [0, 0] booth
     32 
     33 ![trace](https://dl.dropboxusercontent.com/spa/u0s6617yxinm2ca/h6ty39dl.png)
     34 
     35 *hasty-hamiltonian* is a member of the [declarative][decl] suite of libraries,
     36 containing a bunch of MCMC algorithms that play nicely together.
     37 
     38 [decl]: https://github.com/jtobin/declarative