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) – If set this function will be called after every sample. The signature of the callback function is callback(sample, sample_index), where sample is the current sample and sample_index is the index of the sample. An example is shown in demos/demo31_callback.py.

  • 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.

get_history()

Return the history of the sampler.

get_samples()

Return the samples.

get_state()

Return the state of the sampler.

initialize()

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.

reinitialize()

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_proposal()

Validate the proposal distribution.

validate_target()

Validate the target is compatible with the sampler.

warmup(Nb[, tune_freq])

Warmup the sampler by drawing Nb samples.

Attributes

dim

Dimension of the target density.

geometry

Geometry of the target density.

proposal

The proposal distribution.

scale

Get the scale parameter.

target

Return the target density.