|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.knowceans.arms.ArmSampler
public abstract class ArmSampler
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.
Nested Class Summary | |
---|---|
(package private) class |
ArmSampler.Envelope
attributes of the entire rejection envelope |
(package private) class |
ArmSampler.Metropolis
for metropolis step |
(package private) class |
ArmSampler.Point
a point in the x,y plane |
Field Summary | |
---|---|
static int |
DEREF
dereference for ported c pointers |
static double |
EYEPS
critical relative exp(y) difference |
(package private) java.lang.Object |
params
|
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 | |
---|---|
(package private) double |
area(ArmSampler.Point q)
To integrate piece of exponentiated envelope to left of POINT q |
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 |
(package private) void |
cumulate(ArmSampler.Envelope env)
to exponentiate and integrate envelope |
(package private) double |
expshift(double y,
double y0)
to exponentiate shifted y without underflow |
(package private) int |
initial(double[] xinit,
int ninit,
double xl,
double xr,
int npoint,
ArmSampler.Envelope env,
double[] convex,
int[] neval,
ArmSampler.Metropolis metrop)
to set up initial envelope |
(package private) void |
invert(double prob,
ArmSampler.Envelope env,
ArmSampler.Point p)
to obtain a point corresponding to a qiven cumulative probability |
abstract double |
logpdf(double x,
java.lang.Object params)
Abstract function to implement the log pdf. |
(package private) double |
logshift(double y,
double y0)
inverse of function expshift |
(package private) int |
meet(ArmSampler.Point q,
ArmSampler.Envelope env,
ArmSampler.Metropolis metrop)
To find where two chords intersect |
(package private) double |
perfunc(ArmSampler.Envelope env,
double x)
to evaluate log density and increment count of evaluations |
(package private) void |
sample(ArmSampler.Envelope env,
ArmSampler.Point p)
To sample from piecewise exponential envelope |
(package private) int |
test(ArmSampler.Envelope env,
ArmSampler.Point p,
ArmSampler.Metropolis metrop)
to perform rejection, squeezing, and metropolis tests |
(package private) int |
update(ArmSampler.Envelope env,
ArmSampler.Point p,
ArmSampler.Metropolis metrop)
to update envelope to incorporate new point on log density |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
java.lang.Object params
public static final int DEREF
public static final double XEPS
public static final double YEPS
public static final double EYEPS
public static final double YCEIL
Constructor Detail |
---|
public ArmSampler()
Method Detail |
---|
public abstract double logpdf(double x, java.lang.Object params)
x
- params
-
public double armsSimple(java.lang.Object params, int ninit, double[] xl, double[] xr, boolean dometrop, double[] xprev) throws java.lang.Exception
params[]
- parameters of the pdf to be sampledninit
- : number of starting values to be usedxl[]
- : left bound ([] for pointer)xr[]
- : right bound ([] for pointer)dometrop
- : whether metropolis step is requiredxprev[]
- : current value from markov chain ([] for pointer)
java.lang.Exception
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
params
- parameters of the pdf to be sampledxinit[]
- : starting values for x in ascending orderninit
- : number of starting values suppliedxl[]
- : left bound ([] for pointer)xr[]
- : right bound ([] for pointer)convex[]
- : adjustment for convexity ([] for pointer)npoint
- : maximum number of envelope pointsdometrop
- : whether metropolis step is requiredxprev[]
- : previous value from markov chain ([] for pointer)xsamp[]
- : to store sampled valuesnsamp
- : number of sampled values to be obtainedqcent[]
- : percentages for envelope centilesxcent[]
- : to store requested centilesncent
- : number of centiles requestedneval[]
- : on exit, the number of function evaluations performed
([] for pointer)
java.lang.Exception
int initial(double[] xinit, int ninit, double xl, double xr, int npoint, ArmSampler.Envelope env, double[] convex, int[] neval, ArmSampler.Metropolis metrop) throws java.lang.Exception
xinit
- : initial x-valuesninit
- : number of initial x-valuesxl,xr
- : lower and upper x-boundsnpoint
- : maximum number of POINTs allowed in envelopeenv[]
- : rejection envelope attributesconvex[]
- : adjustment for convexity ([] for pointer)neval[]
- : current number of function evaluations ([] for pointer)metrop
- : for metropolis step
java.lang.Exception
void sample(ArmSampler.Envelope env, ArmSampler.Point p) throws java.lang.Exception
env
- : envelope attributesp
- : a working POINT to hold the sampled value
java.lang.Exception
void invert(double prob, ArmSampler.Envelope env, ArmSampler.Point p) throws java.lang.Exception
prob
- : cumulative probability under envelopeenv
- : envelope attributesp
- : a working POINT to hold the sampled value
java.lang.Exception
int test(ArmSampler.Envelope env, ArmSampler.Point p, ArmSampler.Metropolis metrop) throws java.lang.Exception
env
- : envelope attributesp
- : point to be testedmetrop
- : data required for metropolis step
java.lang.Exception
int update(ArmSampler.Envelope env, ArmSampler.Point p, ArmSampler.Metropolis metrop) throws java.lang.Exception
env
- : envelope attributesp
- : point to be incorporatedmetrop
- : for metropolis step
java.lang.Exception
void cumulate(ArmSampler.Envelope env) throws java.lang.Exception
env
- : envelope attributes
java.lang.Exception
int meet(ArmSampler.Point q, ArmSampler.Envelope env, ArmSampler.Metropolis metrop) throws java.lang.Exception
q
- : to store point of intersectionenv
- : envelope attributesmetrop
- : for metropolis step
java.lang.Exception
double area(ArmSampler.Point q) throws java.lang.Exception
Point
- q
java.lang.Exception
double expshift(double y, double y0)
double logshift(double y, double y0)
double perfunc(ArmSampler.Envelope env, double x)
*lpdf
- : structure containing pointers to log-density function and
data*env
- : envelope attributesx
- : point at which to evaluate log density
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |