README.md (2108B)
1 # flat-mcmc 2 3 [![Build Status](https://secure.travis-ci.org/jtobin/flat-mcmc.png)](http://travis-ci.org/jtobin/flat-mcmc) 4 [![Hackage Version](https://img.shields.io/hackage/v/flat-mcmc.svg)](http://hackage.haskell.org/package/flat-mcmc) 5 [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/jtobin/flat-mcmc/blob/master/LICENSE) 6 7 *flat-mcmc* is a Haskell library for painless, efficient, general-purpose 8 sampling from continuous distributions. 9 10 *flat-mcmc* uses an ensemble sampler that is invariant to affine 11 transformations of space. It wanders a target probability distribution's 12 parameter space as if it had been "flattened" or "unstretched" in some sense, 13 allowing many particles to explore it locally and in parallel. 14 15 In general this sampler is useful when you want decent performance without 16 dealing with any tuning parameters or local proposal distributions. Check out 17 the paper describing the algorithm 18 [here](http://msp.org/camcos/2010/5-1/camcos-v5-n1-p04-p.pdf), and a paper on 19 some potential limitations [here](http://arxiv.org/abs/1509.02230), authored 20 by my friends David Huijser and [Brendon 21 Brewer](https://www.stat.auckland.ac.nz/~brewer/). There is also also a robust 22 Python implementation [here](http://dan.iel.fm/emcee/current/) authored by [Dan 23 Foreman-Mackey](http://dan.iel.fm), a very nice dude who I once moved some 24 furniture with. 25 26 *flat-mcmc* exports an 'mcmc' function that prints a trace to stdout, as well 27 as a 'flat' transition operator that can be used more generally. 28 29 ``` haskell 30 import Numeric.MCMC.Flat 31 import qualified Data.Vector.Unboxed as U (unsafeIndex) 32 33 rosenbrock :: Particle -> Double 34 rosenbrock xs = negate (5 * (x1 - x0 ^ 2) ^ 2 + 0.05 * (1 - x0) ^ 2) where 35 x0 = U.unsafeIndex xs 0 36 x1 = U.unsafeIndex xs 1 37 38 origin :: Ensemble 39 origin = ensemble [ 40 particle [negate 1.0, negate 1.0] 41 , particle [negate 1.0, 1.0] 42 , particle [1.0, negate 1.0] 43 , particle [1.0, 1.0] 44 ] 45 46 main :: IO () 47 main = withSystemRandom . asGenIO $ mcmc 12500 origin rosenbrock 48 ``` 49 50 ![trace](http://jtobin.ca/flat-mcmc/img/Rosenbrock_AIE.png) 51