stan-dev / stan-dev/math

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

Open
#3,201 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug distributions good first issue numerics
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementations of categorical_logit_rng, multinomial_logit_rng, and the X_logit_lpdf/lupdf functions, then inspect their current bounds checks and how they distinguish data from autodiff arguments. Determine and document behavior for negative infinity, positive infinity, and all-negative-infinity inputs before changing the checks. Done means data arguments accept the supported infinite values, autodiff arguments remain protected, and tests cover the selected edge-case behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.