Stretch

The Stretch class is imported using the following command:

>>> from UQpy.sampling.mcmc.Stretch import Stretch
class Stretch(pdf_target=None, log_pdf_target=None, args_target=None, burn_length=0, jump=1, dimension=None, seed=None, save_log_pdf=False, concatenate_chains=True, scale=2.0, random_state=None, n_chains=None, nsamples=None, nsamples_per_chain=None)[source]

Affine-invariant sampler with Stretch moves, parallel implementation. [31] [32]

Parameters:
  • pdf_target (Union[Callable, list[Callable], None]) –

    Target density function from which to draw random samples. Either pdf_target or log_pdf_target must be provided (the latter should be preferred for better numerical stability).

    If pdf_target is a callable, it refers to the joint pdf to sample from, it must take at least one input x, which are the point(s) at which to evaluate the pdf. Within MCMC the pdf_target is evaluated as: p(x) = pdf_target(x, *args_target)

    where x is a numpy.ndarray of shape (nsamples, dimension) and args_target are additional positional arguments that are provided to MCMC via its args_target input.

    If pdf_target is a list of callables, it refers to independent marginals to sample from. The marginal in dimension j is evaluated as: p_j(xj) = pdf_target[j](xj, *args_target[j]) where x is a numpy.ndarray of shape (nsamples, dimension)

  • log_pdf_target (Union[Callable, list[Callable], None]) –

    Logarithm of the target density function from which to draw random samples. Either pdf_target or log_pdf_target must be provided (the latter should be preferred for better numerical stability).

    Same comments as for input pdf_target.

  • args_target (Optional[tuple]) – Positional arguments of the pdf / log-pdf target function. See pdf_target

  • burn_length (int) – Length of burn-in - i.e., number of samples at the beginning of the chain to discard (note: no thinning during burn-in). Default is \(0\), no burn-in.

  • jump (int) – Thinning parameter, used to reduce correlation between samples. Setting jump=n corresponds to skipping n-1 states between accepted states of the chain. Default is \(1\) (no thinning).

  • dimension (Optional[int]) – A scalar value defining the dimension of target density function. Either dimension and n_chains or seed must be provided.

  • seed (Optional[list]) –

    Seed of the Markov chain(s), shape (n_chains, dimension). Default: zeros(n_chains x dimension).

    If seed is not provided, both n_chains and dimension must be provided.

  • save_log_pdf (bool) – Boolean that indicates whether to save log-pdf values along with the samples. Default: False

  • concatenate_chains (bool) – Boolean that indicates whether to concatenate the chains after a run, i.e., samples are stored as an numpy.ndarray of shape (nsamples * n_chains, dimension) if True, (nsamples, n_chains, dimension) if False. Default: True

  • n_chains (Optional[int]) – The number of Markov chains to generate. Either dimension and n_chains or seed must be provided.

  • scale (float) – Scale parameter. Default: \(2\).

  • random_state (Union[None, int, RandomState]) – Random seed used to initialize the pseudo-random number generator. Default is None.

  • nsamples (Optional[int]) – Number of samples to generate.

  • nsamples_per_chain (Optional[int]) – Number of samples to generate per chain.

nsamples_per_chain: int

Total number of samples per chain; Similar to the attribute nsamples, it is updated during iterations as new samples are saved.

run_one_iteration(current_state, current_log_pdf)[source]

Run one iteration of the mcmc chain for Stretch algorithm, starting at current state - see MCMC class.

evaluate_log_target: Callable

It is a callable that evaluates the log-pdf of the target distribution at a given point x

evaluate_log_target_marginals: Callable

It is a callable that evaluates the log-pdf of the target marginal distributions at a given point x

samples: ndarray

Set of MCMC samples following the target distribution, numpy.ndarray of shape (nsamples * n_chains, dimension) or (nsamples, n_chains, dimension) (see input concatenate_chains).

log_pdf_values: ndarray

Values of the log pdf for the accepted samples, numpy.ndarray of shape (n_chains * nsamples,) or (nsamples, n_chains)

samples_counter: int

Total number of samples; The nsamples attribute tallies the total number of generated samples. After each iteration, it is updated by \(1\). At the end of the simulation, the nsamples attribute equals the user-specified value for input nsamples given to the child class.

iterations_number: int

Total number of iterations, updated on-the-fly as the algorithm proceeds. It is related to number of samples as iterations_number=burn_length+jump*nsamples_per_chain.