Skip to content

X_logit_{rng, lpdf, lupdf}(theta) should allow -infinite values in theta #3201

Description

@bob-carpenter

The safety checks in the current implementations of categorical_logit_rng and multinomial_logit_rng are too strict. The doc says categorical(softmax(x)) is the same as categorical_logit(x), but that's not the case because softmax allows negative infinite inputs.

There are two things to fix:

  1. Remove the bounds checks in the X_logit_rng functions to allow -infinity.
  2. [Optional] Allow a single +infinity value to produce a deterministic distribution on that value. Multiple +infinity values could either throw or you could make it uniform among the +infinity positions. I'm not sure which mesas more sense.
  3. Remove the bounds check in X_logit_lpdf and X_logit_lupdf when the argument is a data variable.
  4. Throw an exception or make the result uniform if all inputs are negative infinity. Again I'm not sure which makes sense.

For 3, we still need to flag cases where the argument is an autodiff variable because the infinite values will wreak havoc with derivatives.

Activity

  1. godking123 commented on Sep 16, 2026

    @godking123

    Hi, was wondering if this is still open, if so I'd like to take a shot at it.

  2. bob-carpenter commented on Sep 17, 2026

    @bob-carpenter
    MemberAuthor

    Yes, this is still open. I added one more case after reading it.

    I'm not sure what we should do for autodiff if the value is infinite.

    We also have to check if all the values are negative infinity and do something, either make it uniform, or throw an exception.

  3. godking123 commented on Sep 18, 2026

    @godking123

    Hi @bob-carpenter, thanks for the update! I think throwing an error for the all -inf case makes most sense rather than defaulting to uniform. For +inf in _rng, I'll make one +inf deterministic and multiple +infs uniform among those spots, but I'll keep a bound check for the autodiff case for now. Let me know if that sounds good and I'll get started.

  4. bob-carpenter commented on Sep 21, 2026

    @bob-carpenter
    MemberAuthor

    Thanks. That sounds good, @godking123

  5. godking123 commented on Sep 24, 2026

    @godking123

    Hi @bob-carpenter I implemented all of the changes as discussed, this is my first PR in this repo so any tips on commenting/code quality would be really helpful and please do let me know if anything is wrong. Thanks you!

  6. godking123 commented on Sep 24, 2026

    @godking123

    Hi @bob-carpenter I added a new commit to the PR with more comments properly explaining the new bounds checks and more doxygen notes

  7. bob-carpenter commented on Sep 25, 2026

    @bob-carpenter
    MemberAuthor

    Thanks. I'm really hoping @SteveBronder can look at this. I'm going to go down the hall and ping him in person after this.

  8. godking123 commented on Sep 25, 2026

    @godking123

    Sounds good, thanks for the help!

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions