gwin.sampler.kombine module¶
This modules provides classes and functions for using the kombine sampler packages for parameter estimation.
-
class
gwin.sampler.kombine.
KombineSampler
(model, nwalkers, transd=False, pool=None, model_call=None, update_interval=None)[source]¶ Bases:
gwin.sampler.base.BaseMCMCSampler
This class is used to construct the MCMC sampler from the kombine package.
Parameters: - model (model) – A model from
gwin.models
. - nwalkers (int) – Number of walkers to use in sampler.
- transd (bool) – If True, the sampler will operate across parameter spaces using a kombine.clustered_kde.TransdimensionalKDE proposal distribution. In this mode a masked array with samples in each of the possible sets of dimensions must be given for the initial ensemble distribution.
- processes ({None, int}) – Number of processes to use with multiprocessing. If None, all available cores are used.
- update_interval ({None, int}) – Make the sampler update the proposal densities every
update_interval
iterations.
-
acceptance_fraction
¶ Get the fraction of steps accepted by each walker as an array.
-
burn_in
()[source]¶ Use kombine’s
burnin
routine to advance the sampler.If a minimum number of burn-in iterations was specified, this will run the burn-in until it has advanced at least as many steps as desired. The initial positions (p0) must be set prior to running.
For more details, see
kombine.sampler.burnin
.Returns: - p (numpy.array) – An array of current walker positions with shape (nwalkers, ndim).
- lnpost (numpy.array) – The list of log posterior probabilities for the walkers at positions p, with shape (nwalkers, ndim).
- lnprop (numpy.array) – The list of log proposal densities for the walkers at positions p, with shape (nwalkers, ndim).
-
chain
¶ Get all past samples as an nwalker x niterations x ndim array.
-
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) – The model to use with the sampler.
Returns: A kombine sampler initialized based on the given arguments.
Return type:
-
lnpost
¶ Get the natural logarithm of the likelihood as an nwalkers x niterations array.
-
name
= 'kombine'¶
-
run
(niterations, **kwargs)[source]¶ Advance the sampler for a number of samples.
Parameters: niterations (int) – Number of samples to get from sampler. Returns: - p (numpy.array) – An array of current walker positions with shape (nwalkers, ndim).
- lnpost (numpy.array) – The list of log posterior probabilities for the walkers at positions p, with shape (nwalkers, ndim).
- lnprop (numpy.array) – The list of log proposal densities for the walkers at positions p, with shape (nwalkers, ndim).
-
set_state_from_file
(fp)[source]¶ Sets the state of the sampler back to the instance saved in a file.
In addition to the numpy random state, the current KDE used for the jump proposals is loaded.
Parameters: fp (InferenceFile) – File with sampler state stored.
-
write_state
(fp)[source]¶ Saves the state of the sampler in a file.
In addition to the numpy random state, the current KDE used for the jump proposals is saved.
Parameters: fp (InferenceFile) – File to store sampler state.
- model (model) – A model from