pangolin.interface.Interface.log_prob#
- Interface.log_prob(fun)[source]#
A combinator building log probabilities, accepting an RV-like evaluation value.
Calling
log_prob(fun)(value, *args, **kwargs)coercesvalueto an RV and supplies all remaining arguments unchanged tofun. No broadcasting is added. Otherwise, the contract is the same aspangolin.functional.log_prob.- Return type:
Callable[…, RV]
- Parameters:
fun (Callable[[P], RV]) – Function creating one random RV.
- Returns:
log_prob_fun – Function taking an RV-like evaluation value followed by
fun’s arguments, and returning a scalar log-probability RV.
Notes
Newly coerced evaluation values 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 >>> normal_log_prob = pi.log_prob(pi.normal) >>> normal_log_prob(0.0, 0.0, 1.0) RV(LogProb(Normal()), RV(Constant(0.)), 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)) >>> model_log_prob = pi.log_prob(normal_with_log_scale) >>> model_log_prob(0.0, 0.0, 0.0) RV(LogProb(Normal()), RV(Constant(0.)), RV(Constant(0.)), RV(Exp(), RV(Constant(0.))))