gwin.sampler.mcmc module

This modules provides classes and functions for using a MCMC sampler for parameter estimation.

class gwin.sampler.mcmc.MCMCSampler(model)[source]

Bases: gwin.sampler.base.BaseMCMCSampler

This class is used to construct the MCMC sampler.

Parameters:model (Model) – A model from gwin.models.
blobs

This function should return the blobs with a shape nwalkers x niteration as requested by the BaseMCMCSampler class.

chain

This function should return the past samples as a [additional dimensions x] niterations x ndim array, where ndim are the number of sampling params, niterations the number of iterations, and additional dimensions are any additional dimensions used by the sampler (e.g, walkers, temperatures).

clear_chain()[source]

This function should clear the current chain of samples from memory.

classmethod from_cli(opts, model, pool=None, model_call=None)[source]

Create an instance of this sampler from the given command-line options.

Parameters:
  • opts (ArgumentParser options) – The options to parse.
  • model (Model) – A model from gwin.models.
Returns:

A MCMC sampler initialized based on the given arguments.

Return type:

MCMCSampler

lnpost

This function should return the natural logarithm of the likelihood function used by the sampler as an [additional dimensions] x niterations array.

name = 'mcmc'
niterations

Get the current number of iterations.

p0

Since this is just a single chain, forces p0 to have shape (nparams,).

run(niterations)[source]

This function should run the sampler.

write_acceptance_fraction(fp, start_iteration=None, max_iterations=None)[source]

Write acceptance_fraction data to file. Results are written to fp[acceptance_fraction].

Parameters:fp (InferenceFile) – A file handler to an open inference file.