You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
BUG: logp of pt.max/pt.min over a multi-dimensional i.i.d. variable has shape x.shape[1:] instead of being a scalar #8635
pt.max(x) and pt.min(x) reduced over every axis of an i.i.d. variable are scalars, but when x has two or more dimensions the derived logp has shape x.shape[1:], with the correct value repeated in every entry. Inside a model those entries are summed, so the observation is counted prod(x.shape[1:]) times: 3x for a (2, 3) base, 12x for (2, 3, 4). This affects continuous and discrete max, and min as well. A 1-D base gives the correct scalar.
The cause is in pymc/logprob/order.py. max_logprob and max_logprob_discrete broadcast the value to the base variable's shape and then take [0] of the result (lines 148–149 and 168–169), which only removes the first axis:
The existing tests don't catch this. test_max_logprob and test_min_logprob include (3, 4) cases, but they compare a scalar against the (4,)-shaped result with np.testing.assert_allclose, which broadcasts, so they pass.
Indexing every axis instead, i.e. [(0,) * base_rv.ndim] in those four places, fixes it. The logp becomes a scalar, model logps match the analytic order-statistic density, and tests/logprob/test_order.py still passes. Adding a shape assertion to the max/min tests would cover the regression. I'm happy to open a PR.
PyMC: 6.4.0 (pip) and main @ bc3904b
PyTensor: 3.3.8
Python: 3.13
OS: Linux
Installed via: pip (release) and pip install -e . (main)
Context for the issue:
Any model whose likelihood uses the max or min of a multi-dimensional batch of i.i.d. draws gets that likelihood raised to the power prod(x.shape[1:]), so the posterior is overconfident without any warning. It looks like a shape problem rather than a deliberate restriction, since a 1-D base is handled correctly.
Hi, I would like to take this one if you are not planning to open a PR yourself. I have read the issue and the relevant code in pymc/logprob/order.py, and I can open a PR with the fix and a shape assertion in tests/logprob/test_order.py. Please let me know.
Activity
welcome commentedon Nov 15, 2026
🎉 Welcome to PyMC! 🎉 We're really excited to have your input into the project! 💖
If you haven't done so already, please make sure you check out our Contributing Guidelines and Code of Conduct.
Dikshant-Neupane commentedon Nov 21, 2026
Hi, I would like to take this one if you are not planning to open a PR yourself. I have read the issue and the relevant code in pymc/logprob/order.py, and I can open a PR with the fix and a shape assertion in tests/logprob/test_order.py. Please let me know.