Copyright | (c) 2015 Jared Tobin |
---|---|

License | MIT |

Maintainer | Jared Tobin <jared@jtobin.ca> |

Stability | unstable |

Portability | ghc |

Safe Haskell | None |

Language | Haskell2010 |

This implementation performs slice sampling by first finding a bracket about a mode (using a simple doubling heuristic), and then doing rejection sampling along it. The result is a reliable and computationally inexpensive sampling routine.

The `mcmc`

function streams a trace to stdout to be processed elsewhere,
while the `slice`

transition can be used for more flexible purposes, such as
working with samples in memory.

See Neal, 2003 for the definitive reference of the algorithm.

- mcmc :: (Show (t a), FoldableWithIndex (Index (t a)) t, Ixed (t a), Num (IxValue (t a)), Variate (IxValue (t a))) => Int -> IxValue (t a) -> t a -> (t a -> Double) -> Gen RealWorld -> IO ()
- slice :: (PrimMonad m, FoldableWithIndex (Index (t a)) t, Ixed (t a), Num (IxValue (t a)), Variate (IxValue (t a))) => IxValue (t a) -> Transition m (Chain (t a) b)
- create :: PrimMonad m => m (Gen (PrimState m))
- createSystemRandom :: IO GenIO
- withSystemRandom :: PrimBase m => (Gen (PrimState m) -> m a) -> IO a
- asGenIO :: (GenIO -> IO a) -> GenIO -> IO a

# Documentation

mcmc :: (Show (t a), FoldableWithIndex (Index (t a)) t, Ixed (t a), Num (IxValue (t a)), Variate (IxValue (t a))) => Int -> IxValue (t a) -> t a -> (t a -> Double) -> Gen RealWorld -> IO () Source #

Trace `n`

iterations of a Markov chain and stream them to stdout.

`>>>`

`let rosenbrock [x0, x1] = negate (5 *(x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2)`

`>>>`

-3.854097694213343e-2,0.16688601288358407 -9.310661272172682e-2,0.2562387977415508 -0.48500122500661846,0.46245400501919076`withSystemRandom . asGenIO $ mcmc 3 1 [0, 0] rosenbrock`

slice :: (PrimMonad m, FoldableWithIndex (Index (t a)) t, Ixed (t a), Num (IxValue (t a)), Variate (IxValue (t a))) => IxValue (t a) -> Transition m (Chain (t a) b) Source #

A slice sampling transition operator.

# Re-exported

createSystemRandom :: IO GenIO #

Seed a PRNG with data from the system's fast source of pseudo-random
numbers. All the caveats of `withSystemRandom`

apply here as well.

withSystemRandom :: PrimBase m => (Gen (PrimState m) -> m a) -> IO a #

Seed a PRNG with data from the system's fast source of
pseudo-random numbers ("`/dev/urandom`

" on Unix-like systems or
`RtlGenRandom`

on Windows), then run the given action.

This is a somewhat expensive function, and is intended to be called
only occasionally (e.g. once per thread). You should use the `Gen`

it creates to generate many random numbers.