API reference¶
The public API of augax is one sampler per augmentation scheme; each works
inside jax.jit, jax.vmap, lax.scan, and jax.pmap.
Sampling¶
Draw |
|
Draw the Kolmogorov scale |
|
|
Internal helpers¶
These functions support pg_sample() and ks_sample() and are
documented for completeness; they are not part of the stable public API.
Derive an int64 RNG seed from a JAX PRNG key (per-key, reproducible). |
|
|
|
|
|
Module contents¶
augax: on-device draws for conditionally Gaussian augmentation, in JAX.
Each primitive is an XLA FFI custom call that samples one augmentation
variable inside @jax.jit / lax.scan. It ships one:
pg_samplePólya–Gamma,
omega ~ PG(h, z), for the logit and negative-binomial likelihoods (Polson, Scott & Windle 2013).ks_sampleThe Kolmogorov scale of a logistic disturbance,
lam | eps, which makes the logistic a normal scale mixture (Stefanski 1991; Holmes & Held 2006).ks_sample_numpy()is the same draw for host (NumPy) callers.
Draw omega ~ PG(h, z) from inside @jax.jit / lax.scan with no host
round-trip — the native replacement for jax.pure_callback(random_polyagamma)
that taxes every Gibbs sweep (and serializes under jax.pmap).
Draws follow the hybrid scheme of polyagamma’s random_polyagamma
(method=None): exact Devroye draws for the Bernoulli/logit augmentation
(h = 1), the exact alternate sampler for other real h below the
saddlepoint region — e.g. the Negative-Binomial h = y + alpha — a
saddlepoint rejection sampler for larger h, and a moment-matched normal above
h = 50 (see the README).
Example:
import jax, augax
jax.config.update("jax_enable_x64", True)
@jax.jit
def step(h, z, key):
return augax.pg_sample(h, z, key) # on-device PG draw
- augax.ks_sample(u, key)[source]
Draw the Kolmogorov scale
lamgiven a logistic disturbanceu, on-device.A standard logistic \(\varepsilon\) is the normal scale mixture \(\varepsilon \mid \lambda \sim N(0, \lambda^2)\), \(\lambda = 2K\) with \(K\) Kolmogorov distributed. Given \(\varepsilon = u\) this draws \(\lambda\) from
\[p(\lambda \mid u) \propto \lambda^{-1}\,\varphi(u/\lambda)\,f_{2K}(\lambda),\]exactly: a rejection sampler with an inverse-Gaussian proposal for \(1/\lambda^2\) and the alternating-series squeeze of the Kolmogorov density in both of its forms (Holmes & Held 2006).
- augax.ks_sample_numpy(u, rng)[source]
ks_sample()on the host: the same sampler, for NumPy callers.- Parameters:
u (array_like) – The disturbances, any shape, as float64.
rng (numpy.random.Generator) – Supplies the seed of the C++ stream.
- Returns:
lam – The scales, with the shape of
u.- Return type:
- augax.pg_sample(h, z, key)[source]
Draw
omega ~ PG(h, z)element-wise, on-device.- Parameters:
h (array_like) – Shape
[n]float64. PG shape (h = 1 for Bernoulli/logit; positive integer for the exact sum-of-Devroye path).z (array_like) – Shape
[n]float64. PG tilt (the linear predictor).key (jax.Array) – A JAX PRNG key.
vmapover a batch of keys draws each element’s batch with its own RNG stream.
- Returns:
omega – Draws from
PG(h, z)with the same shape ash.- Return type: