You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
log1p_exp() for logistic_lcdf() and logistic_lccdf() #2827
The logistic_lcdf() and logistic_lccdf() function break down at standardised values beyond 36 or so, due to numerical underflow (e.g., here and here).
This underflow can be solved by using log1p_exp() in the implementation instead of computing the CDF/CCDF directly.
I don't understand the full complexity of the templates in stan-math enough to make a pull request – sorry! – but I think this should be a pretty quick fix for anybody who understands the library well.
Example
Stan returns -Inf for log_lccdf(40 | 0, 1)...
Expected Output
...whereas -log1p_exp(40) evaluates cleanly to -40.
If you're making a numerical stability sweep, perhaps it's also worth updating logistic_lpdf() to use log1p_exp() instead of just log1p() (see here). It's splitting hairs a bit, but again, it seems like a quick fix and could be worth it given that the logistic distribution is the backbone of so many models
Activity
andrjohns commentedon Oct 19, 2022
Thanks for opening this @jaburgoyne! I'm working on the numerical stability of a few of the LCDF's at the moment, so I'll tackle this as well
jaburgoyne commentedon Oct 21, 2022
If you're making a numerical stability sweep, perhaps it's also worth updating logistic_lpdf() to use log1p_exp() instead of just log1p() (see here). It's splitting hairs a bit, but again, it seems like a quick fix and could be worth it given that the logistic distribution is the backbone of so many models
avehtari commentedon Oct 8, 2026
This is fixed by #3398 (not yet merged)