speedy-slice

Speedy slice sampling.
git clone git://git.jtobin.io/speedy-slice.git
Log | Files | Refs | README | LICENSE

README.md (1629B)


      1 # speedy-slice
      2 
      3 [![Build Status](https://secure.travis-ci.org/jtobin/speedy-slice.png)](http://travis-ci.org/jtobin/speedy-slice)
      4 [![Hackage Version](https://img.shields.io/hackage/v/speedy-slice.svg)](http://hackage.haskell.org/package/speedy-slice)
      5 [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jtobin/speedy-slice/blob/master/LICENSE)
      6 
      7 Speedy slice sampling, as per [Neal, 2003](http://people.ee.duke.edu/~lcarin/slice.pdf).
      8 
      9 This implementation of the slice sampling algorithm uses `lens` as a means to
     10 operate over generic indexed traversable functors, so you can expect it to
     11 work if your target function takes a list, vector, map, sequence, etc. as its
     12 argument.
     13 
     14 Additionally you can sample over anything that's an instance of both `Num` and
     15 `Variate`, which is useful in the case of discrete parameters.
     16 
     17 Exports a `mcmc` function that prints a trace to stdout, a `chain` function for
     18 working with results in memory, and a `slice` transition operator that can be
     19 used more generally.
     20 
     21     import Numeric.MCMC.Slice
     22     import Data.Sequence (Seq, index, fromList)
     23 
     24     bnn :: Seq Double -> Double
     25     bnn xs = -0.5 * (x0 ^ 2 * x1 ^ 2 + x0 ^ 2 + x1 ^ 2 - 8 * x0 - 8 * x1) where
     26       x0 = index xs 0
     27       x1 = index xs 1
     28 
     29     main :: IO ()
     30     main = withSystemRandom . asGenIO $ mcmc 10000 1 (fromList [0, 0]) bnn
     31 
     32 ![trace](https://dl.dropboxusercontent.com/spa/u0s6617yxinm2ca/zp-9gl6z.png)
     33 
     34 *speedy-slice* is a member of the [declarative][decl] suite of libraries,
     35 containing a bunch of MCMC algorithms that play nicely together.
     36 
     37 [decl]: https://github.com/jtobin/declarative