org.knowceans.util
Class ArmSampler

java.lang.Object
  extended by org.knowceans.util.ArmSampler

public abstract class ArmSampler
extends java.lang.Object

ArmSampler implements an adaptive rejection Metropolis sampler (ARMS) that can sample from virtually any univariate distribution. The method performs best if a log-concave density is being sampled from, but it also works for other densities, for which an additional Metropolis step is inserted. The greater the difference to log-concave shape, the more Metropolis rejections must be expected.

This implementation is a port of the original c / fortran implementation by Wally Gilks available at http://www.mrc-bsu.cam.ac.uk/BSUsite/Research/ars.shtml.

Please acknowledge this work by referencing the relevant scientific literature and program code (Web: http://www.arbylon.net/projects).

References:

Gilks, W. R. (1992) Derivative-free adaptive rejection sampling for Gibbs sampling. Bayesian Statistics 4, (eds. Bernardo, J., Berger, J., Dawid, A. P., and Smith, A. F. M.) Oxford University Press.

Gilks, W. R., Best, N. G. and Tan, K. K. C. (1995) Adaptive rejection Metropolis sampling. Applied Statistics, 44, 455-472.

Gilks, W. R. and Wild, P. (1992) Adaptive rejection sampling for Gibbs sampling. Applied Statistics 41, pp 337-348.

Author:
gregor heinrich

Field Summary
static int DEREF
          dereference for ported c pointers
static double EYEPS
          critical relative exp(y) difference
static double XEPS
          critical relative x-value difference
static double YCEIL
          maximum y avoiding overflow in exp(y)
static double YEPS
          critical y-value difference
 
Constructor Summary
ArmSampler()
          init (nothing to do)
 
Method Summary
 double[] arms(java.lang.Object params, double[] xinit, int ninit, double[] xl, double[] xr, double[] convex, int npoint, boolean dometrop, double[] xprev, double[] xsamp, int nsamp, double[] qcent, double[] xcent, int ncent, int[] neval)
          to perform derivative-free adaptive rejection sampling with metropolis step
 double armsSimple(java.lang.Object params, int ninit, double[] xl, double[] xr, boolean dometrop, double[] xprev)
          adaptive rejection metropolis sampling - simplified argument list
abstract  double logpdf(double x, java.lang.Object params)
          Abstract function to implement the log pdf.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEREF

public static final int DEREF
dereference for ported c pointers

See Also:
Constant Field Values

XEPS

public static final double XEPS
critical relative x-value difference

See Also:
Constant Field Values

YEPS

public static final double YEPS
critical y-value difference

See Also:
Constant Field Values

EYEPS

public static final double EYEPS
critical relative exp(y) difference

See Also:
Constant Field Values

YCEIL

public static final double YCEIL
maximum y avoiding overflow in exp(y)

See Also:
Constant Field Values
Constructor Detail

ArmSampler

public ArmSampler()
init (nothing to do)

Method Detail

logpdf

public abstract double logpdf(double x,
                              java.lang.Object params)
Abstract function to implement the log pdf.

Parameters:
x -
params -
Returns:

armsSimple

public double armsSimple(java.lang.Object params,
                         int ninit,
                         double[] xl,
                         double[] xr,
                         boolean dometrop,
                         double[] xprev)
                  throws java.lang.Exception
adaptive rejection metropolis sampling - simplified argument list

Parameters:
params[] - parameters of the pdf to be sampled
ninit - : number of starting values to be used
xl[] - : left bound ([] for pointer)
xr[] - : right bound ([] for pointer)
dometrop - : whether metropolis step is required
xprev[] - : current value from markov chain ([] for pointer)
Returns:
: sampled value
Throws:
java.lang.Exception

arms

public double[] arms(java.lang.Object params,
                     double[] xinit,
                     int ninit,
                     double[] xl,
                     double[] xr,
                     double[] convex,
                     int npoint,
                     boolean dometrop,
                     double[] xprev,
                     double[] xsamp,
                     int nsamp,
                     double[] qcent,
                     double[] xcent,
                     int ncent,
                     int[] neval)
              throws java.lang.Exception
to perform derivative-free adaptive rejection sampling with metropolis step

Parameters:
params - parameters of the pdf to be sampled
xinit[] - : starting values for x in ascending order
ninit - : number of starting values supplied
xl[] - : left bound ([] for pointer)
xr[] - : right bound ([] for pointer)
convex[] - : adjustment for convexity ([] for pointer)
npoint - : maximum number of envelope points
dometrop - : whether metropolis step is required
xprev[] - : previous value from markov chain ([] for pointer)
xsamp[] - : to store sampled values
nsamp - : number of sampled values to be obtained
qcent[] - : percentages for envelope centiles
xcent[] - : to store requested centiles
ncent - : number of centiles requested
neval[] - : on exit, the number of function evaluations performed ([] for pointer)
Returns:
xsamp[] : sampled values
Throws:
java.lang.Exception