jexplore.sampling.mh#
This module contains the definitions of classes and types for running a Metropolis-Hastings markov sampler.
Classes#
This class provides the definition of a markovc chain state for a |
|
Markov sampling defining parameters for Metropolis-Hastings |
|
Epoch definition class for Metropolis-Hastings. |
Module Contents#
- class StateMH[source]#
Bases:
jexplore.sampling.state.StateThis class provides the definition of a markovc chain state for a Metropolis-Hastings markov sampler. With respect to the parent
jexplore.sampling.state.Stateclass, it simply adds log likelihood and log prior values to the state attributes (operations on these parameters are handled by the parent class methods).- Parameters:
p – status point (nchains, dim)
ll – log likelihood values for each chain point (nchains, 1).
lp – log prior values for each chain point (nchains, 1).
- ll: jax.Array#
log likelihood values
- lp: jax.Array#
log prior values.
- class SamplingMH[Tspace: jexplore.sampling.space.Space](nwalker, temps, loglik, logprior, dim=None, space=None, inpars=None)[source]#
Bases:
jexplore.sampling.base.Sampling[Tspace]Markov sampling defining parameters for Metropolis-Hastings sampling. With respect to the parent
jexplore.sampling.base.Samplingclass the definition of the sampling includes the following parameters- Parameters:
nwalker (int) – number of walkers per temperature.
temps (jax.Array) – temperature ladder
loglik (jexplore.sampling.state.ArrayFn) – log likelihood function
logprior (jexplore.sampling.state.ArrayFn) – log prior function
dim (int | None)
space (Tspace | None)
inpars (list[str] | None)
The nchain parameter is computed from nwalker and temps.
- nwalker: int#
number of walkers
- temps: jax.Array#
temperature ladder
- loglik: jexplore.sampling.state.ArrayFn#
log likelihood function
- logprior: jexplore.sampling.state.ArrayFn#
log prior function
- inpars: list[str]#
list of input parameters of loglik and logprior
- class EpochMH[Tstate: StateMH, Tsampling: SamplingMH](epoch, force_covs=False)[source]#
Bases:
jexplore.sampling.epoch.Epoch[Tstate,Tsampling]Epoch definition class for Metropolis-Hastings.
With respect to the parent
jexplore.sampling.epoch.Epochclass, this class definejexplore.sampling.mh.StateMHas default state class and overrides the complete method to also compute the log likelihood and log prior of the epoch points.- Parameters:
epoch (Self | dict) – Epoch object from which the new instance can be derived by computing the covariance and getting the last sample. Alternatively this can be a dictionnary with the definition of the epoch samples.
force_covs (bool) – if true forces the recomputing of the covariance matrices.
- complete(sampling, compute=None)[source]#
Complete the definition and the parameters of the epoch.
- Parameters:
sampling (Tsampling) – sampling parameters.
compute (dict | None) – dictionnary defining how to compute the missing parameters. The keys are the names of the parameters to be computed. Values are (func, inpars) tuples, where func is a callable for the computation of the corresponding parameter and inpars is the list of the names if the input parameters.
- Return type:
Self
With respect to
jexplore.sampling.epoch.Epoch.complete, this implementation of the complete method provides a base for the compute parameter with the instructions to compute log likelihood and log prior epoch samples attributes.- Returns:
this object after update.
- Parameters:
sampling (Tsampling)
compute (dict | None)
- Return type:
Self