Conjugate#
- class cuqi.experimental.mcmc.Conjugate(target=None, initial_point=None, callback=None)#
Conjugate sampler
Sampler for sampling a posterior distribution which is a so-called “conjugate” distribution, i.e., where the likelihood and prior are conjugate to each other - denoted as a conjugate pair.
Currently supported conjugate pairs are: - (Gaussian, Gamma) where Gamma is defined on the precision parameter of the Gaussian - (GMRF, Gamma) where Gamma is defined on the precision parameter of the GMRF - (RegularizedGaussian, Gamma) with preset constraints only and Gamma is defined on the precision parameter of the RegularizedGaussian - (RegularizedGMRF, Gamma) with preset constraints only and Gamma is defined on the precision parameter of the RegularizedGMRF - (RegularizedGaussian, ModifiedHalfNormal) with preset constraints and regularization only - (RegularizedGMRF, ModifiedHalfNormal) with preset constraints and regularization only
Currently the Gamma and ModifiedHalfNormal distribution must be univariate.
A conjugate pair defines implicitly a so-called conjugate distribution which can be sampled from directly.
The conjugate parameter is the parameter that both the likelihood and prior PDF depend on.
For more information on conjugacy and conjugate distributions see https://en.wikipedia.org/wiki/Conjugate_prior.
For implicit regularized Gaussians and the corresponding conjugacy relations, see:
Section 3.3 from [1] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. “Bayesian inference with projected densities.” SIAM/ASA Journal on Uncertainty Quantification 11.3 (2023): 1025-1043. Section 4 from [2] Everink, Jasper M., Yiqiu Dong, and Martin S. Andersen. “Sparse Bayesian inference with regularized Gaussian distributions.” Inverse Problems 39.11 (2023): 115004.
- __init__(target=None, initial_point=None, callback=None)#
Initializer for abstract base class for all samplers.
Any subclassing samplers should simply store input parameters as part of the __init__ method.
The actual initialization of the sampler should be done in the _initialize method.
- Parameters:
target (cuqi.density.Density) – The target density.
initial_point (array-like, optional) – The initial point for the sampler. If not given, the sampler will choose an initial point.
callback (callable, optional) – A function that will be called after each sampling step. It can be useful for monitoring the sampler during sampling. The function should take three arguments: the sampler object, the index of the current sampling step, the total number of requested samples. The last two arguments are integers. An example of the callback function signature is: callback(sampler, sample_index, num_of_samples).
Methods
__init__
([target, initial_point, callback])Initializer for abstract base class for all samplers.
Return the history of the sampler.
Return the samples.
Return the state of the sampler.
Initialize the sampler by setting and allocating the state and history before sampling starts.
load_checkpoint
(path)Load the state of the sampler from a file.
Re-initialize the sampler.
sample
(Ns[, batch_size, sample_path])Sample Ns samples from the target density.
save_checkpoint
(path)Save the state of the sampler to a file.
set_history
(history)Set the history of the sampler.
set_state
(state)Set the state of the sampler.
step
()Perform one step of the sampler by transitioning the current point to a new point according to the sampler's transition kernel.
tune
(skip_len, update_count)Tune the parameters of the sampler.
Validate the target is compatible with the sampler.
warmup
(Nb[, tune_freq])Warmup the sampler by drawing Nb samples.
Attributes