pastas.solver.EmceeSolve#

class pastas.solver.EmceeSolve(objective_function=None, nwalkers: int = 20, backend=None, moves=None, parallel: bool = False, progress_bar: bool = True, **kwargs)#

Solver based on MCMC approach in emcee [Foreman-Mackey et al., 2013].

Parameters:
  • objective_function (func, optional) – An objective function to be minimized. If not provided, the GaussianLikelihood is used. See the pastas.objective_functions module for more information.

  • nwalkers (int, optional) – Number of walkers to use. Default is 20.

  • backend (emcee.backend, optional) – One of the Backends from Emcee used to store MCMC results. See Emcee for more information.

  • moves (emcee.moves, optional) – The moves argument determines how the next step for a walker is chosen in the MCMC approach. One of the Moves classes from Emcee has to be provided. See Emcee documentation for more information.

  • parallel (bool, optional) – Run the sampler in parallel or not.

  • progress_bar (bool, optional) – Show the progress bar or not. Requires the tqdm package to be installed.

  • **kwargs – All other keyword arguments are passed on to the BaseSolver class.

  • optional – All other keyword arguments are passed on to the BaseSolver class.

Notes

The EmceeSolve solver uses the emcee package to perform a Markov Chain Monte Carlo (MCMC) approach to find the optimal parameter values. The solver can be used as follows:

solver = ps.EmceeSolve(
    nwalkers=20,
    progress_bar=True,
)
ml.solve(solver=solver)

The arguments provided are mostly passed on to the emcee.EnsembleSampler and determine how that instance is created. Arguments you want to pass on to run_mcmc (and indirectly the sample method), can be passed on to Model.solve, like:

ml.solve(solver=ps.EmceeSolve(), thin_by=2)

Examples

Example usage:

ml.solve(solver=ps.EmceeSolve(), steps=5000)

To obtain the MCMC chains, use:

ml.solver.sampler.get_chain(flat=True, discard=3000)

References

https://emcee.readthedocs.io/en/stable/

See also

emcee.EnsembleSampler, emcee.moves, emcee.backend, pastas.objective_functions

Methods#

log_probability(→ float)

Full log-probability called by Emcee.

log_likelihood(→ float)

Log-likelihood function.

log_prior(→ float)

Probability of parameter set given the priors.

set_parameter(→ None)

Method to change the parameter properties.

to_dict(→ dict)

This method is not supported for this solver.