Learn R Programming

gmatrix (version 0.3)

gBasicHMC: Performing Hamiltonian MCMC

Description

This function performs Hamiltonian MCMC for continuous distributions.

Usage

gBasicHMC(lpgrf, initial, nsims, nsteps, step, burnin = 1, nstepsburnin = nsteps, stepburnin = step, Tstart = 1, r = 1, keep=keep, thin = 1, report = 100)

Arguments

lpgrf
This lpgrf input must be a function which takes as its input a list of parameters and gives as its output the log probability (lp) excluding the normalization constant and a first derivative of the log probability (gr). Both the lp and gr information must be returned as slots in an object of class lpgr. See details.
initial
Starting values as a list. Again each element of the starting value must be a matrix on the CPU or GPU. The number columns of each matrix is the number of parrallel runs.
nsims
Total number of simulations includeing burnin.
nsteps
Tuning parameter for HMC representing the number of leepfrog steps for each iteration.
step
Tuning parameter for HMC controls the length of each leepfrog steps for each iteration.
nstepsburnin
Tuning parameter for HMC representing the number of leepfrog steps for each iteration. This parameter is used only during burnin.
stepburnin
Tuning parameter for HMC controls the length of each leepfrog steps for each iteration. This parameter is used only during burnin.
Tstart
During the burnin phase only tempering is used to get the simulation moving. Tstart is the starting temperature.
r
The temperature during the burning phase is exponentially decreased at a rate r. The temperature is set to 1 if it drops below 1. Also, the temperature is set to 1 once the burnin phas is done.
burnin
The number of iterations used for burnin. All burnin samples are discarded.
keep
Function to extract samples to keep. If defualt keep function is defined as keep = function(q) lapply(q, function(x) if(any(class(x) %in% c("gmatrix","gvector"))) g(x) else x).
thin
Selects the number of samples to keep. thin=1 keeps all the samples. thin=5 keeps only ever fifth sample.
report
Controls how often an update of the progress is printed out.

Value

Output is a list:
sims
A list with the simulation results from each iteration as elements.
lp
A matrix with the simulation log probabilities for all simulations.
AcceptanceRate
Acceptence rate for each parallel chain.
BurninAcceptanceRate
Acceptence rate during the burnin phase for each parallel chain.

Details

The most important input of gBasicHMC() is the lpgrf parameter. This lpgrf input must be a function which takes as its input a list of parameters and gives as its output the log probability (lp) excluding the normalization constant and a first derivative of the log probability (gr). Both the lp and gr information must be returned as slots in an object of class lpgrf. The lp slot must be a numberic CPU vector while gr slot must be a list with elements either on the CPU or GPU.The function gBasicHMC() is designed to run multiple chains simultaneously. Thus each element in the input is expected to be a matrix where the number of columns is the number of parallel chains and the number of rows is the dimension of the random variable being simulated. The input is assumed to be a list of parameters because in many cases there are different types of parameters such as hyper-parameters. Tracking the current stated of the chain using a list is therefore often quite natural. As a result of this convention, the gr slot for lpgr object returned by the lpgrf function must also be a list.

References

Neal, Radford M. "MCMC using Hamiltonian dynamics." Handbook of Markov Chain Monte Carlo 2 (2011).

Beam, Andrew L., Sujit K. Ghosh, and Jon Doyle. "Fast hamiltonian monte carlo using gpu computing." Journal of Computational and Graphical Statistics just-accepted (2015): 00-00.

See Also

lpgr-class