![]() |
|
adaptive rejection metropolis sampling
| #define XEPS 0.00001 |
(C) Wally Gilks; see documentation below for details. Adaptations for Apophenia (c) 2009 by Ben Klemens. Licensed under the modified GNU GPL v2; see COPYING and COPYING2.
| void apop_arms_draw | ( | double * | out, | |
| gsl_rng * | r, | |||
| apop_model * | m | |||
| ) |
Adaptive rejection metropolis sampling.
This is a function to make random draws from any univariate distribution (more or less).
The author, Wally Gilks, explains on http://www.amsta.leeds.ac.uk/~wally.gilks/adaptive.rejection/web_page/Welcome.html, that ``ARS works by constructing an envelope function of the log of the target density, which is then used in rejection sampling (see, for example, Ripley, 1987). 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.''
apop_arms_settings structure. The structure also holds a history of the points tested to date. That means that the system will be more acurate as more draws are made. It also means that if the parameters change, or you use apop_model_copy, you should call Apop_settings_rm_group(your_model, apop_arms) to clear the model of points that are not valid for a different situation.apop_model_add_group(your_model, apop_arms, .model=your_model, .xl=8, .xr =14);. The model element is mandatory; you'll get a run-time complaint if you forget it.model : the model from which I will draw. Must have either a log_likelihood or p method.
*xinit : a double* giving starting values for x in ascending order. Default: -1, 0, 1. If this isn't NULL, I need at least three items.
ninit : number of elements in xinit
xl : left bound. If you don't give me one, I'll use min[min(xinit)/10, min(xinit)*10].
xr : right bound. If you don't give me one, I'll use max[max(xinit)/10, max(xinit)*10].
convex : adjustment for convexity
npoint : maximum number of envelope points. I malloc space for this many doubles at the outset default = 1e5
do_metro : whether the metropolis step is required (I.e., set to one if you're not sure if the function is log-concave). Set to 'y'es or 'n'o
*xprev : previous value from markov chain
*neval : on exit, the number of function evaluations performed