import Xoshiro128p from '../core/xoshiro'; /** * Class implementing [Adaptive Rejection Sampling]{@link https://doi.org/10.2307/2347565} * (Gilks & Wild, 1992) for a univariate log-concave target density on a finite support bracket. * A piecewise-linear upper hull, built from tangent lines to the log-density at a growing set of * abscissae, gives a piecewise-exponential sampling envelope; a piecewise-linear lower hull built * from the secant lines between the same abscissae gives a cheap "squeeze" test that avoids * evaluating the true log-density whenever possible. Every time the true log-density does have to * be evaluated, the tested point is added to the abscissa set, tightening both hulls so the * acceptance probability increases monotonically as sampling proceeds. Unlike * [MCMC]{@link ran.mc.MCMC} and its subclasses, ARS is not a Markov chain: every draw is an exact, * independent sample from the target (up to the target being genuinely log-concave), with no * warm-up or burn-in. * * @class ARS * @memberof ran.mc * @constructor */ export default class ARS { _h: Function; _dh: Function; _lo: number; _hi: number; r: Xoshiro128p; _pts: { x: number; h: any; dh: any; }[]; _z: any[]; _mass: any[]; _cum: any[]; _total: number; _M: number; /** * @param {Function} logDensity The logarithm of the (unnormalized) target density. * @param {number[]} support The two-element `[lo, hi]` support bracket. Must be finite with * `lo < hi`. * @param {Function=} derivative The derivative of `logDensity`. Estimated via finite differences * when omitted. * @throws {Error} If logDensity is not a function, or support is not a `[lo, hi]` array of two * finite numbers with `lo < hi`, or derivative is provided but is not a function, or the initial * hull already reveals that logDensity is not log-concave. */ constructor(logDensity: Function, support: number[], derivative?: Function | undefined); /** * Draws samples from the target density. * * @method sample * @memberof ran.mc.ARS * @param {number} n Number of samples to generate. * @returns {number[]} The generated samples. * @throws {Error} If the target density turns out not to be log-concave. * @ignore */ sample(n: number): number[]; /** * Sets the seed for the sampler's pseudo random number generator. * * @method seed * @memberof ran.mc.ARS * @param {number|string} value The value of the seed, either a number or a string (for the ease * of tracking seeds). * @returns {this} Reference to the current sampler. * @ignore */ seed(value: number | string): this; _slope(x: any): any; _tangentIntersection(pi: any, pj: any): number; _assertValidHullSegment(pi: any, pj: any, z: any): void; _build(): void; _sampleEnvelope(): { x: any; upper: any; }; _lowerHull(x: any): any; _insert(x: any, h: any, dh: any): void; static _validate(logDensity: any, support: any, derivative: any): void; static _isValidSupport(support: any): boolean; }