pangolin.interface.quantile#
- pangolin.interface.quantile(fun)#
A combinator building quantiles, accepting an RV-like probability.
Calling
quantile(fun)(probability, *args, **kwargs)coercesprobabilityto a scalar RV and supplies all remaining arguments unchanged tofun. No broadcasting is added. Otherwise, the contract is the same aspangolin.functional.quantile.- Return type:
Callable[…, RV]
- Parameters:
fun (Callable[[P], RV]) – Function creating one scalar random RV.
- Returns:
quantile_fun – Function taking a scalar RV-like probability followed by
fun’s arguments, and returning a scalar quantile RV. Numerical support depends on the backend; seepangolin.jax_backend.lower_quantilefor JAX’s supported distributions.
Notes
Newly coerced probabilities use this interface; existing RVs are preserved. The result retains the interface of the random RV returned by
fun.Examples
>>> from pangolin import interface as pi >>> pi.quantile(pi.normal)(0.5, 0.0, 1.0) RV(Quantile(Normal()), RV(Constant(0.5)), RV(Constant(0.)), RV(Constant(1.)))
The supplied function can include ordinary parameter calculations:
>>> def normal_with_log_scale(mean, log_scale): ... return pi.normal(mean, pi.exp(log_scale)) >>> pi.quantile(normal_with_log_scale)(0.5, 0.0, 0.0) RV(Quantile(Normal()), RV(Constant(0.5)), RV(Constant(0.)), RV(Exp(), RV(Constant(0.))))
Use explicit vectorization for several probabilities; the distribution inside
quantilemust remain scalar:>>> probabilities = pi.constant([0.1, 0.5, 0.9]) >>> y = pi.vmap(pi.quantile(pi.normal), (0, None, None))(probabilities, 0.0, 1.0) >>> y.op VMap(Quantile(Normal()), [0, None, None], 3) >>> y.shape (3,)