Skip to content

log1p_exp() for logistic_lcdf() and logistic_lccdf() #2827

Description

@jaburgoyne

Description

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.

Current Version:

v4.4.0

Activity

  1. andrjohns commented on Oct 19, 2022

    @andrjohns
    Collaborator

    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

  2. jaburgoyne commented on Oct 21, 2022

    @jaburgoyne
    CollaboratorAuthor

    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

  3. avehtari commented on Oct 8, 2026

    @avehtari
    Member

    This is fixed by #3398 (not yet merged)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions