Skip to content

Truncate logjac is NaN instead of -Inf at y = ±Inf #24

Closed

Description

@penelopeysm

For a doubly-bounded Truncate, with_logabsdet_jacobian returns NaN at y = ±Inf, where the correct value is -Inf:

https://github.com/JuliaBayes/Plaice.jl/blob/main/src/univariate/truncated.jl#L44

logjac = log(bma) + y - (2 * log1pexp(y))  # Inf - Inf at y = Inf

This happens in practice when a sample lands exactly on a bound, e.g. Beta(1.0, 0.2) draws 1.0 with probability ~6e-4 in Float64, so logit(x) = Inf. The logjac test then fails with NaN ≈ -Inf (AD gets -Inf correctly, since logistic'(Inf) = 0).

The Bijectors form mentioned in the comment above that line handles this:

absy = abs(y)
logjac = log(bma) - absy - 2 * log1pexp(-absy)

🤖 Generated with Claude Code

Activity

  1. penelopeysm commented on Sep 27, 2026

    @penelopeysm
    MemberAuthor

    (Human comment here) there are similar failure modes when the sample is very close to but not 1 (basically the result will have a loss of numerical precision).

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