Skip to content

Conversation

iTzZe4lous
Copy link

@iTzZe4lous iTzZe4lous commented Oct 3, 2025

Description

Changes

  • Added icdf implementation to pymc/distributions/discrete.py.
  • Added test_categorical_icdf, test_categorical_icdf_batch_shapes, and test_categorical_icdf_upper_edge.

Testing

  • All Categorical tests pass locally (pytest -q tests/distributions -k categorical).
  • Pre-commit checks pass.

Related Issue

  • Closes #
  • Related to # 6612

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

📚 Documentation preview 📚: https://pymc--7920.org.readthedocs.build/en/7920/

Copy link

welcome bot commented Oct 3, 2025

Thank You Banner]
💖 Thanks for opening this pull request! 💖 The PyMC community really appreciates your time and effort to contribute to the project. Please make sure you have read our Contributing Guidelines and filled in our pull request template to the best of your ability.

def icdf(value, p):
eps = 1e-12
q = value
q_safe = pt.clip(q, 0.0, 1.0 - eps)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why we need q_safe?

Comment on lines +1209 to +1210
mask = pt.shape_padright(q_safe, 1) <= cdf
idx = pt.argmax(mask, axis=-1).astype("int64")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use search_sorted?

Comment on lines +1205 to +1207
extra = q_ndim - cdf_batch_ndim
axes = list(range(cdf.ndim - 1)) + ["x"] * extra + [cdf.ndim - 1]
cdf = cdf.dimshuffle(axes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use expand_dims for readability

@ricardoV94
Copy link
Member

Thanks for opening the PR @iTzZe4lous

I left some comments above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants