samsam.sam#

samsam.sam(x0, logprob, nsamples=100000, mu0=None, cov0=None, cov_update_interval=100, cov_update_law=<function <lambda>>, scale0=None, accept_rate_target=0.234, force_use_empirical_cov=False, print_level=1, print_interval=1000, print_inplace=True, **kwargs)#

Adaptive Metropolis algorithm (Haario et al. 2001) with adaptive scaling (Andrieu & Thoms 2008).

Parameters:
x0(ndim,) ndarray

Initial guess of the parameters.

logprob(x, **kwargs)function

Log probability of the distribution to sample.

nsamples: int

Number of samples to draw.

mu0(ndim,) ndarray

Initial guess of the parameters’ mean.

cov0(ndim, ndim) ndarray

Initial guess of the parameters’ covariance matrix.

cov_update_intervalint

Interval at which to update the covariance matrix.

cov_update_law(t)function

Update coefficient (between 0 and 1) as a function of time (should vanish as t -> nsamples)

scale0float

Initial scaling factor for the proposal distribution (by default 2.4/sqrt(ndim)).

accept_rate_targetfloat

Acceptance rate to target when rescaling the proposal distribution, if None, the scale is left unchanged.

force_use_empirical_covbool

Whether to force the use of the empirical covariance from the beginning. If this is not forced, we wait for the acceptance rate to reach at least 0.1 before considering the empirical covariance to be correct.

print_levelint

0 (no printing) 1 (print acceptance rate)

print_intervalint

Interval at which to print infos.

print_inplacebool

Whether to print infos in place or one line after the other.

**kwargs

Additional parameters for the logprob function.

Returns:
samples(nsamples+1, ndim) ndarray

Array of parameters values for each sample.

diagnositicsdict

Dictionary of diagnostics, with the following keys:

logprob(nsamples+1,) ndarray

Array of log probability for each sample.

alpha(nsamples,) ndarray

Array of acceptance probability for each proposal.

accept(nsamples,) ndarray

Array of acceptance for each proposal.

mu(ndim,) ndarray

Final estimate of the mean.

cov(ndim, ndim) ndarray

Final estimate of the covariance matrix.

scalefloat

Final estimate of the proposal scale.