hasty-hamiltonian

Speedy traversal through parameter space.

http://jtobin.github.com/hasty-hamiltonian

Version on this page:1.1.2
LTS Haskell 22.14:1.3.4
Stackage Nightly 2024-03-28:1.3.4
Latest on Hackage:1.3.4

See all snapshots hasty-hamiltonian appears in

MIT licensed by Jared Tobin
Maintained by [email protected]
This version can be pinned in stack with:hasty-hamiltonian-1.1.2@sha256:f1c17eac571113bf1d2c929546eb20d9c026a5d3443b1ce708e124bb0895066a,2188

Module documentation for 1.1.2

Used by 1 package in nightly-2015-12-08(full list with versions):

Gradient-based traversal through parameter space.

This implementation of HMC algorithm uses lens as a means to operate over generic indexed traversable functors, so you can expect it to work if your target function takes a list, vector, map, sequence, etc. as its argument.

If you don't want to calculate your gradients by hand you can use the handy ad library for automatic differentiation.

Exports a mcmc function that prints a trace to stdout, as well as a hamiltonian transition operator that can be used more generally.

import Numeric.AD (grad)
import Numeric.MCMC.Hamiltonian

target :: RealFloat a => [a] -> a
target [x0, x1] = negate ((x0 + 2 * x1 - 7) ^ 2 + (2 * x0 + x1 - 5) ^ 2)

gTarget :: [Double] -> [Double]
gTarget = grad target

booth :: Target [Double]
booth = Target target (Just gTarget)

main :: IO ()
main = withSystemRandom . asGenIO $ mcmc 10000 0.05 20 [0, 0] booth