Implementation of Haario et al. (2001)'s Adaptive Metropolis.

kernel_adapt(
  mu = 0,
  bw = 0L,
  lb = -.Machine$double.xmax,
  ub = .Machine$double.xmax,
  freq = 1L,
  warmup = 500L,
  Sigma = NULL,
  Sd = NULL,
  eps = 1e-04,
  fixed = FALSE,
  until = Inf
)

kernel_am(
  mu = 0,
  bw = 0L,
  lb = -.Machine$double.xmax,
  ub = .Machine$double.xmax,
  freq = 1L,
  warmup = 500L,
  Sigma = NULL,
  Sd = NULL,
  eps = 1e-04,
  fixed = FALSE,
  until = Inf
)

Arguments

mu

Either a numeric vector or a scalar. Proposal mean. If scalar, values are recycled to match the number of parameters in the objective function.

bw

Integer scalar. The bandwidth, is the number of observations to include in the computation of the variance-covariance matrix.

lb, ub

Either a numeric vector or a scalar. Lower and upper bounds for bounded kernels. When of length 1, the values are recycled to match the number of parameters in the objective function.

freq

Integer scalar. Frequency of updates. How often the variance-covariance matrix is updated. The implementation is different from that described in the original paper (see details).

warmup

Integer scalar. The number of iterations that the algorithm has to wait before starting to do the updates.

Sigma

The variance-covariance matrix. By default this will be an identity matrix during the warmup period.

Sd

Overall scale for the algorithm. By default, the variance-covariance is scaled to \(2.4^2/d\), with \(d\) the number of dimensions.

eps

Double scalar. Default size of the initial step (see details).

fixed

Logical scalar or vector of length k. Indicates which parameters will be treated as fixed or not. Single values are recycled.

until

Integer scalar. Last step at which adaptation takes place (see details).

Value

An object of class fmcmc_kernel. fmcmc_kernel objects are intended to be used with the MCMC() function.

Details

While it has been shown that under regular conditions this transition kernel generates ergodic chains even when the adaptation does not stop, some practitioners may want to stop adaptation at some point.

kernel_adapt Implements the adaptive Metropolis (AM) algorithm of Haario et al. (2001). If the value of bw is greater than zero, then the algorithm folds back AP, a previous version which is known to have ergodicity problems.

The parameter eps has two functions. The first one is to set the initial scale for the multivariate normal kernel, which is replaced after warmup steps with the actual variance-covariance computed by the main algorithm. The second usage is in the equation that ensures that the variance-covariance is greater than zero, this is, the \(\varepsilon\) parameter in the original paper.

The update of the covariance matrix is done using cov_recursive() function, which makes the updates faster. The freq parameter, besides of indicating the frequency with which the updates are done, it specifies what are the samples included in each update, in other words, like a thinning parameter, only every freq samples will be used to compute the covariance matrix. Since this implementation uses the recursive formula for updating the covariance, there is no practical need to set freq != 1.

kernel_am is just an alias for kernel_adapt.

References

Haario, H., Saksman, E., & Tamminen, J. (2001). An adaptive Metropolis algorithm. Bernoulli, 7(2), 223–242. https://projecteuclid.org/euclid.bj/1080222083

See also

Examples

# Update every-step and wait 1,000 steps before starting to adapt
kern <- kernel_adapt(freq = 1, warmup = 1000)

# Two parameters model, the second parameter with a restricted range, i.e.
# a lower bound of 1
kern <- kernel_adapt(lb = c(-.Machine$double.xmax, 0))