Chris Beaumont's IDL Library

Download source code

single page | use frames     summary     class     fields     routine details     file attributes

./

mcmc_multi__define.pro

mcmc_multi is a subclass of the mcmc class to create markov chain monte carlo simulations on multiple chains simultaneously.

One of IDL's principal weaknesses is that, since it is an interpreted scripting language, it is much slower than compiled languages for repetitive tasks like looping. The mcmc_multi class tries to mitigate this problem by vectorizing the mcmc code. In this class, multiple chains are run simultaneously and, assuming that the code which generates and evaluates trial links is vectorized well, this may be substantially faster than running one long mcmc chain.

To use this class, the user must supply ARRAYS for the seed and data variables when initializing the object. Each element in the array represents the seed/data for a particular chain. The final set of chains fetched from the getChain method will have nchain columns and nstep rows.

As with the mcmc class, the user must also override the logTargetDistribution and selectTrial methods in a subclass of mcmc_multi. These methods have the same signatures as in a normal mcmc object, but the inputs and outputs must now be arrays, not scalars. These objects should be written in a vectorized fashion, otherwise mcmc_multi will probably have no speed bost over mcmc.

Some quick testing showed that mcmc_multi was about a factor of 2 slower than mcmc when run using only 1 chain, but was 10x faster when comparing 100 chains to 1 chain with 100x as many steps.

Class description for mcmc_multi

Inheritance

Fields in mcmc

Author information

History

October 2009: Written by Chris Beaumont, adapted from the mcmc class. December 2009: Added tracking of maximum posterior

Routines

mcmc_multi::run

Run all of the chains

result = mcmc_multi::getPeak( [value=value])

Return the chain link which have the maximum target distribution value

result = mcmc_multi::getNSuccess( [nfail=nfail])

This function returns the numbers of accepted and, optionally, rejected trial links for each chain during the run

result = mcmc_multi::init(seed, nstep, data [, thin=thin])

Initialize the mcmc_multi object

mcmc_multi::cleanup

Free memory when we are finished

mcmc_multi__define

define the mcmc_multi data structure

Routine details

topmcmc_multi::run

statistics

mcmc_multi::run

Run all of the chains

mcmc_multi_common: Holds the seed variable for calls to randomu

topmcmc_multi::getPeak

result = mcmc_multi::getPeak( [value=value])

Return the chain link which have the maximum target distribution value

Keywords

value in optional

The value of the maximum target distribution

topmcmc_multi::getNSuccess

result = mcmc_multi::getNSuccess( [nfail=nfail])

This function returns the numbers of accepted and, optionally, rejected trial links for each chain during the run

Return value

The number of accepted links in each chain during the run. An array.

Keywords

nfail in optional

A named variable to hold the number of rejected links for each chain during the run. An array

topmcmc_multi::init

statistics INPTUS: seed: An array of starting seed links, one for each chain nstep: The number of desired links for each chain data: An array of any relevant data, one for each chain

result = mcmc_multi::init(seed, nstep, data [, thin=thin])

Initialize the mcmc_multi object

Parameters

seed
nstep
data

Keywords

thin in optional

If set to a non-negative integer, save only every THINth links in the chain. Helpful for saving space with long chains

topmcmc_multi::cleanup

statistics

mcmc_multi::cleanup

Free memory when we are finished

topmcmc_multi__define

statistics

mcmc_multi__define

define the mcmc_multi data structure

File attributes

Modifcation date: Tue Oct 12 15:38:51 2010
Lines: 223