jexplore.sampling.mh#

This module contains the definitions of classes and types for running a Metropolis-Hastings markov sampler.

Classes#

StateMH

This class provides the definition of a markovc chain state for a

SamplingMH

Markov sampling defining parameters for Metropolis-Hastings

EpochMH

Epoch definition class for Metropolis-Hastings.

Module Contents#

class StateMH[source]#

Bases: jexplore.sampling.state.State

This class provides the definition of a markovc chain state for a Metropolis-Hastings markov sampler. With respect to the parent jexplore.sampling.state.State class, 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.Sampling class the definition of the sampling includes the following parameters

Parameters:

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

to_backend()[source]#

Save the attributes of the object in backend format.

Return type:

dict

get_sampler(steps=None, backend=None)[source]#

Return a sampler with default steps and backend.

Parameters:
  • steps – list of Step-like instances. If None, use strech and tswap (if more than 1 temp).

  • backend – a Backend instance. If None, use the default one.

Returns:

a JaxSampler instance.

get_epoch(p)[source]#

Return an Epoch object from starting sample, to be use by MH sampler as initial epoch.

Params p:

samples array of shape nwalker x ntemp, dim

Returns:

a EpochMH instance

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.Epoch class, this class define jexplore.sampling.mh.StateMH as 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.

statecls: type[Tstate] | type[StateMH]#

State class

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