ModifiedMetropolisHastings
The ModifiedMetropolisHastings
class is imported using the following command:
>>> from UQpy.sampling.mcmc.ModifiedMetropolisHastings import ModifiedMetropolisHastings
- class ModifiedMetropolisHastings(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, proposal=None, proposal_is_symmetric=False, random_state=None, n_chains=None, nsamples=None, nsamples_per_chain=None)[source]
Component-wise Modified Metropolis-Hastings algorithm. [13]
In this algorithm, candidate samples are drawn separately in each dimension, thus the proposal consists of a list of 1D distributions. The target pdf can be given as a joint pdf or a list of marginal pdfs in all dimensions. This will trigger two different algorithms. If a list of marginals is provided, the acceptance ratio is computed for every dimension independently using the marginal densities. If a joint pdf is provided, the acceptance ratio for each component is computed in a loop using this joint pdf.
- 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 toMCMC
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 anumpy.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_targetburn_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. Settingjump=n
corresponds to skippingn-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 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 annumpy.ndarray
of shape(nsamples * n_chains, dimension)
ifTrue
,(nsamples, n_chains, dimension)
ifFalse
. Default: Truen_chains (
Optional
[int
]) – The number of Markov chains to generate. Either dimension and n_chains or seed must be provided.proposal (
Union
[Distribution
,list
[Distribution
],None
]) – Proposal distribution, must have a log_pdf/pdf and rvs method. Default: standard multivariate normalproposal_is_symmetric (
Union
[bool
,list
[bool
]]) – Indicates whether the proposal distribution is symmetric, affects computation of acceptance probability alpha Default:False
, set toTrue
if default proposal is usedrandom_state (
Union
[None
,int
,RandomState
]) – Random seed used to initialize the pseudo-random number generator. Default isNone
.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.
-
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, thensamples
attribute equals the user-specified value for inputnsamples
given to the child class.