LinearRTO#

class cuqi.experimental.mcmc.LinearRTO(target=None, initial_point=None, maxit=10, tol=1e-06, **kwargs)#

Linear RTO (Randomize-Then-Optimize) sampler.

Samples posterior related to the inverse problem with Gaussian likelihood and prior, and where the forward model is linear or more generally affine.

Parameters:
  • target (cuqi.distribution.Posterior, cuqi.distribution.MultipleLikelihoodPosterior or 5-dimensional tuple.) –

    If target is of type cuqi.distribution.Posterior or cuqi.distribution.MultipleLikelihoodPosterior, it represents the posterior distribution. If target is a 5-dimensional tuple, it assumes the following structure: (data, model, L_sqrtprec, P_mean, P_sqrtrec)

    Here: data: is a m-dimensional numpy array containing the measured data. model: is a m by n dimensional matrix, AffineModel or LinearModel representing the forward model. L_sqrtprec: is the squareroot of the precision matrix of the Gaussian likelihood. P_mean: is the prior mean. P_sqrtprec: is the squareroot of the precision matrix of the Gaussian mean.

  • initial_point (np.ndarray) – Initial point for the sampler. Optional.

  • maxit (int) – Maximum number of iterations of the inner CGLS solver. Optional.

  • tol (float) – Tolerance of the inner CGLS solver. 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.

__init__(target=None, initial_point=None, maxit=10, tol=1e-06, **kwargs)#

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 sample is drawn. The function should take two arguments: the sample and the index of the sample. The sample is a 1D numpy array and the index is an integer. The callback function is useful for monitoring the sampler during sampling.

Methods

__init__([target, initial_point, maxit, tol])

Initializer for abstract base class for all samplers.

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

likelihood

likelihoods

model

models

prior

target

Return the target density.