CWMH#
- class cuqi.experimental.mcmc.CWMH(target=None, proposal=None, scale=1, initial_point=None, **kwargs)#
Component-wise Metropolis Hastings sampler.
Allows sampling of a target distribution by a component-wise random-walk sampling of a proposal distribution along with an accept/reject step.
- Parameters:
target (cuqi.distribution.Distribution or lambda function) – The target distribution to sample. Custom logpdfs are supported by using a
cuqi.distribution.UserDefinedDistribution
.proposal (cuqi.distribution.Distribution or callable method) – The proposal to sample from. If a callable method it should provide a single independent sample from proposal distribution. Defaults to a Gaussian proposal. Optional.
scale (float or ndarray) – Scale parameter used to define correlation between previous and proposed sample in random-walk. Optional. If float, the same scale is used for all dimensions. If ndarray, a (possibly) different scale is used for each dimension.
initial_point (ndarray) – Initial parameters. Optional
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).
kwargs (dict) – Additional keyword arguments to be passed to the base class
ProposalBasedSampler
.
Example
- __init__(target=None, proposal=None, scale=1, initial_point=None, **kwargs)#
Initializer for abstract base class for samplers that use a proposal distribution.
Any subclassing samplers should simply store input parameters as part of the __init__ method.
Initialization of the sampler should be done in the _initialize method.
See
Sampler
for additional details.- Parameters:
target (cuqi.density.Density) – The target density.
proposal (cuqi.distribution.Distribution, optional) – The proposal distribution. If not specified, the default proposal is used.
scale (float, optional) – The scale parameter for the proposal distribution.
**kwargs (dict) – Additional keyword arguments passed to the
Sampler
initializer.
Methods
__init__
([target, proposal, scale, ...])Initializer for abstract base class for samplers that use a proposal distribution.
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 proposal distribution.
Validate the target is compatible with the sampler.
warmup
(Nb[, tune_freq])Warmup the sampler by drawing Nb samples.
Attributes