pint.sampler.MCMCSampler

class pint.sampler.MCMCSampler[source]

Bases: object

Base class for samplers used in MCMC fitting.

The sampling method should be implemented in the run_mcmc() method.

This was created initially to work with the emcee package but can be extended for other samplers.

The use of this class can be somewhat tricky, since MCMCFitter must own some subclass of the abstract class MCMCSampler. However, the MCMCSampler requires access to functions inside MCMCFitter. So the specific MCMCSampler must be instantiated first and passed into the Fitter, but the Sampler cannot be initialized until after the Fitter has been created.

The general flow of using the MCMCSampler class with MCMCFitter is::

#Create the sampler object but don’t initialize the internals sampler = MCMCSampler()

#Create the fitter using the new sampler fitter = MCMCFitter(…stuff…, sampler=sampler)

#Initialize the sampler at some point before use using sampler.initialize_sampler(fitter.lnposterior)

Methods

get_initial_pos(fitkeys, fitvals, fiterrs, ...)

Give the initial position(s) for the fitter based on given values.

initialize_sampler(lnpostfn, ndim)

Initialize the internals of the sampler using the posterior probability function

run_mcmc(pos, nsteps)

Run the MCMC process from the given initial position

initialize_sampler(lnpostfn, ndim)[source]

Initialize the internals of the sampler using the posterior probability function

This function must be called before run_mcmc()

get_initial_pos(fitkeys, fitvals, fiterrs, errfact, **kwargs)[source]

Give the initial position(s) for the fitter based on given values.

run_mcmc(pos, nsteps)[source]

Run the MCMC process from the given initial position

Parameters:
  • pos – The initial sampling point

  • nstesps (int) – The number of iterations to run for