Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Censor & Truncate Docstrings #7590

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pymc/distributions/censored.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ class Censored(Distribution):

.. warning:: dist will be cloned, rendering it independent of the one passed as input.

lower : float or None
lower : float, int, array-like or None
Lower (left) censoring point. If `None` the distribution will not be left censored
upper : float or None
upper : float, int, array-like or None
Upper (right) censoring point. If `None`, the distribution will not be right censored.

Warnings
Expand All @@ -101,11 +101,20 @@ class Censored(Distribution):

Examples
--------
Censoring with upper & lower points set to +/-1
.. code-block:: python

with pm.Model():
normal_dist = pm.Normal.dist(mu=0.0, sigma=1.0)
censored_normal = pm.Censored("censored_normal", normal_dist, lower=-1, upper=1)

Partial censoring of normal distributions achienved by passing +/-inf censor points.
Examples of 4 censor conditions: uncensored (-inf, inf), upper censored (-inf, 1),
Comment on lines +111 to +112
Copy link
Member

Choose a reason for hiding this comment

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

First emphasize that censoring bounds can change across dimensions of the variable, and then enumerate the examples. If they don't change, one can use None as upper or lower, not only +/-np.inf

lower censored (-1, inf), and both censored (-1, 1)
.. code-block:: python
Copy link
Member

Choose a reason for hiding this comment

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

I think you need to leave a blank line between the description and the code example for it to render correctly: https://pymcio--7590.org.readthedocs.build/projects/docs/en/7590/api/distributions/censored.html

Before: https://www.pymc.io/projects/docs/en/stable/api/distributions/censored.html

with pm.Model():
normal_dist = pm.Normal.dist(mu=0.0, sigma=1.0)
partially_censored_normals = pm.Censored("partially_censored_normals", normal_dist, lower=[-np.inf, -np.inf, -1, -1], upper=[np.inf, 1, np.inf, 1], shape=(4,))
Copy link
Member

@ricardoV94 ricardoV94 Nov 27, 2024

Choose a reason for hiding this comment

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

make it multiple line so it renders nicely in the docs: https://pymcio--7590.org.readthedocs.build/projects/docs/en/7590/api/distributions/censored.html

The name is probably too long

"""

rv_type = CensoredRV
Expand Down
12 changes: 10 additions & 2 deletions pymc/distributions/truncated.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ class Truncated(Distribution):

.. warning:: dist will be cloned, rendering it independent of the one passed as input.

lower: tensor_like of float or None
lower: tensor_like of float, int, or None
Lower (left) truncation point. If `None` the distribution will not be left truncated.
upper: tensor_like of float or None
upper: tensor_like of float, int, or None
Upper (right) truncation point. If `None`, the distribution will not be right truncated.
max_n_steps: int, defaults 10_000
Maximum number of resamples that are attempted when performing rejection sampling.
Expand All @@ -285,12 +285,20 @@ class Truncated(Distribution):

Examples
--------
Truncation with upper & lower points set to +/-1
.. code-block:: python

with pm.Model():
normal_dist = pm.Normal.dist(mu=0.0, sigma=1.0)
truncated_normal = pm.Truncated("truncated_normal", normal_dist, lower=-1, upper=1)

Partial truncatin of normal distributions achieved by passing +/-inf truncation points.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Partial truncatin of normal distributions achieved by passing +/-inf truncation points.
Partial truncation of normal distributions achieved by passing +/-inf truncation points.

Examples of 4 truncation conditions: untruncated (-inf, inf), upper truncated (-inf, 1),
lower truncated (-1, inf), and both truncated (-1, 1)
.. code-block:: python
with pm.Model():
normal_dist = pm.Normal.dist(mu=0.0, sigma=1.0)
partially_truncated_normal = pm.Truncated("partially_truncated_normal", normal_dist, lower=[-np.inf, -np.inf, -1, -1], upper=[np.inf, 1, np.inf, 1], shape=(4,))
"""

rv_type = TruncatedRV
Expand Down