BUG: Moyal logcdf returns -inf in lower tail where value is finite

Open Beginner friendly
#8,437 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
data

Research direction

Start at pymc.distributions.continuous.Moyal.logcdf and run the reproduction with the listed lower-tail values. Inspect the existing logcdf expression and related distribution tests; done means finite results for values such as -50 that agree with scipy.stats.moyal.logcdf without regressing ordinary inputs.

Written by the indexing model from the issue text.

Description

Describe the issue:

Moyal.logcdf returns -inf in the lower tail for values where the true logcdf is finite and well within floating-point range.

In pymc.distributions.continuous.Moyal.logcdf:

scaled = (value - mu) / sigma
res = pt.log(pt.erfc(pt.exp(-scaled / 2) * (2**-0.5)))

For large negative value, scaled = (value - mu) / sigma becomes a large negative number. pt.exp(-scaled / 2) grows large, causing pt.erfc(...) to underflow to 0.0, resulting in pt.log(0.0) == -inf.

Reproduceable code example:
import numpy as np
import pymc as pm
from scipy import stats

rv = pm.Moyal.dist(mu=0.0, sigma=1.0)
xs = np.array([-10.0, -20.0, -50.0])

print("PyMC logcdf :", pm.logcdf(rv, xs).eval())
print("SciPy logcdf:", stats.moyal.logcdf(xs, loc=0.0, scale=1.0))
Error message:

No exception is raised. logcdf returns -inf for large negative values (e.g. xs = -50.0) where SciPy reports a finite log-probability value.

PyMC version information:
Environment
  • PyMC version: 5.x / 6.x (main branch)
  • PyTensor version: 3.x
  • Python version: 3.11+
  • OS: Windows / Linux / macOS
Context for the issue:

logcdf is used in censored and truncated distribution models (pm.Censored, pm.Truncated). When logcdf prematurely returns -inf in the lower tail, sampling or model evaluation fails with invalid log-probabilities.

Dominant language
Python
Stars
9.8k
Forks
2.3k
Avg merge
21h 39m
Merged PRs (30d)
5

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.

More from pymc-devs/pymc

All issues in pymc-devs/pymc

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.