bayesbay.samplers.ParallelTempering
- class bayesbay.samplers.ParallelTempering(temperature_max=5, chains_with_unit_temperature=0.4, swap_every=500)
High-level class to be used to sample the posterior by means of reversible-jump Markov chain Monte Carlo accelerated with parallel tempering.
See references below for details on parallel tempering [1], [2].
- Parameters:
temperature_max (Number) – the maximum temperature attributed to the chains
chains_with_unit_temperature (float) – the fraction of chains having unit temperature, 0.4 by default (i.e. 40% of the chains)
swap_every (int) – the frequency with which the chain temperatures are randomly chosen and possibly swapped during the sampling, by default 500 iterations
References
Reference Details
- chains
the
MarkovChain
instances of the current Bayesian inference
- parallel_config
customized parallel configuration dictionary that will be passed to
joblib.Parallel
- add_on_begin_iteration(func)
adds a custom function that will be called at the beginning of each Markov chain iteration (see
on_begin_iteration()
)
- add_on_end_advance_chain(func)
adds a custom function that will be called at the end of the batch of Markov chain iterations taking place after calling
advance_chain()
- add_on_end_iteration(func)
adds a custom function that will be called at the end of each Markov chain iteration (see
on_end_iteration()
)
- add_on_initialize(func)
adds a custom function that will be called at the end of the chains initialization (see
initialize()
)- Parameters:
func (Callable) – Function that takes as arguments a Sampler and a list of MarkovChains
- advance_chain(n_iterations, burnin_iterations=0, save_every=100, verbose=True, print_every=100)
advances the Markov chains for a given number of iterations
- Parameters:
n_iterations (int) – the number of iterations to advance
burnin_iterations (int, optional) – the iteration number from which we start to save samples, by default 0
save_every (int, optional) – the frequency in which we save the samples, by default 100
verbose (bool, optional) – whether to print the progress during sampling or not, by default True
print_every (int, optional) – the frequency with which we print the progress and information during the sampling, by default 100 iterations
parallel_config (dict, optional) – keyword arguments passed to
joblib.Parallel
. Ignored whenlen(self.chains)
is 1
- Returns:
the Markov chains
- Return type:
List[BaseMarkovChain]
- begin_iteration(chain)
calls
on_begin_iteration()
before beginning the current Markov chain iteration- Parameters:
chain (bayesbay.BaseMarkovChain) – Markov chain used to sample the posterior
- end_advance_chain()
calls
on_end_advance_chain()
before concluding the batch of Markov chain iterations taking place after callingadvance_chain()
- end_iteration(chain)
calls
on_end_iteration()
before passing to the next Markov chain iteration.- Parameters:
chain (bayesbay.BaseMarkovChain) – Markov chain used to sample the posterior
- initialize(chains)
initializes the given Markov Chains by calling
on_initialize()
- Parameters:
chains (List[BaseMarkovChain]) – List of Markov chains used to sample the posterior
- on_begin_iteration(chain)
defines the behaviour of the sampler at the beginning of each Markov chain iteration
- Parameters:
chain (BaseMarkovChain) – Markov chain used to sample the posterior
- on_end_advance_chain()
defines the behaviour of the sampler at the end of the batch of Markov chain iterations taking place after calling
advance_chain()
- Parameters:
chain (BaseMarkovChain) – Markov chain used to sample the posterior
- on_end_iteration(chain)
defines the behaviour of the sampler at the end of each Markov chain iteration
- Parameters:
chain (BaseMarkovChain) – Markov chain used to sample the posterior
- on_initialize(chains)
defines the behaviour of the sampler at the initialization of the Markov chains
- Parameters:
chains (List[BaseMarkovChain]) – List of Markov chains used to sample the posterior
- run(n_iterations, burnin_iterations=0, save_every=100, verbose=True, print_every=100)
function that allows for running the Bayesian inference by calling
advance_chain()
.Important
To work properly, a custom Sampler has to call within this function the method
advance_chain()
.