C Function for Adaptive Rejection Sampling (ARS)

Longhai Li, Department of Mathematics and Statistics, University of Saskatchewan

Description

Adaptive Rejection Sampling (ARS) is an efficient method for sampling from a target distribution whose log PDF is concave.  The description of ARS by the original inventor (Wally Gilks) is as follows:

ARS works by constructing an envelope function of the log of the target density, which is then used in rejection sampling. Whenever a point is rejected by ARS, the envelope is updated to correspond more closely to the true log density, thereby reducing the chance of rejecting subsequent points. Fewer ARS rejection steps implies fewer point-evaluations of the log density. Such evaluations are typically very expensive computationally in applications of Gibbs sampling.

This method is very useful and conceptually simple. The original authors provide a FORTRAN routine. However, it seemed to me that there wasn't a C routine available. Therefore I posted this C function, which can be called directly in R with .C function.

C Function for ARS

To use the main function sample_ars, you need only to include the file ars.c in your C code. See the following examples for demonstration.

Demo Examples

Truncated Normal Distribution

C sampling function,   R wrapper function and testing code,   Testing plots

Posterior of Hyperparameter of Inverse-Gamma (Inverse-Chisquare) Distribution

C sampling function,   R wrapper function and testing code,   Testing plots

Truncated Beta

C sampling function,   R wrapper function and testing code,   Testing plots

Pros of this software

Other Implementations of ARS

In pure R language