Module mcmc
[frames] | no frames]

Module mcmc

source code

Adaptive Markov-Chain Monte-Carlo algorithm. This can be used to generate samples from a probability distribution, or also as a simulated annealing algorithm for maximization. This can be used as a script, from the command line, or (more likely) it can be imported and its functions and classes can be used.

The central interfaces are the BootStepper class, and within it, the step() method is used iteratively to take a Markov step.

To use it as a script, you create your own module that implements a few functions, and run mcmc.py. It will import your module and call your functions repeatedly.

The algorithm is described in Kochanski and Rosner 2010, and earlier versions have been used in ZZZ. It evolved originally from amoeba_anneal (in Numerical Recipes, Press et al.). The essential feature is that it keeps a large archive of previous positions (possibly many times more than N of them). It samples two positions from the archive and subtracts them to generate candidate steps. This has the nice property that when sampling from a multivariate Gaussian distribution, the candidate steps match the distribution nicely.

It can be operated in two modes (or set to automatically switch). One is optimization mode where it heads for the maximum of the probability distribution. The other mode is sampling mode, where it asymptotically follows a Markov sampling procedure and has the proper statistical properties.

As a script, it takes the following arguments:

It uses the following functions and variables:

Classes
  def_logger
Functions
 
logp_from_resid(x, c, resid_fcn) source code
 
go(argv, theStepper)
Run the optimization, controlled by command line flags.
source code
Variables
  Debug = 0
  MEMORYS_WORTH_OF_PARAMETERS = 100000000.0
  __package__ = None
hash(x)

Imports: sys, numpy, die, mcmc, gpkmisc, g_implements, MVN