pastas.solver.mcmc.Emcee#
- class pastas.solver.mcmc.Emcee(name: str = 'solver', objfunction: pastas.solver.likelihood.GaussianLikelihood | pastas.solver.likelihood.GaussianLikelihoodAr1 | None = GaussianLikelihood(), nwalkers: int = 20, backend: Any | None = None, moves: Any | None = None, parallel: bool = False, progress_bar: bool = True, **kwargs: Any)#
Solver based on MCMC approach in emcee [Foreman-Mackey et al., 2013].
- Parameters:
objfunction (pastas.solver.likelihood function, optional) – An objective function to be minimized. See the pastas.likelihood 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 the Emcee documentation 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 SolverBase class.
optional – All other keyword arguments are passed on to the SolverBase 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.solver.Emcee(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.solver.Emcee(), thin_by=2)
Examples
Example usage:
ml.solve(solver=ps.solver.Emcee(), 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.solver.objective_function
Methods#
|
Get initial parameters for the solver. |
|
Solve the model using MCMC. |
|
Full log-probability called by Emcee. |
|
Log-likelihood function. |
|
Probability of parameter set given the priors. |
|
Report on the fit after a model is optimized. |
|
Not supported for this solver. |