From 03764d0300a19aa0d4f9e330894dc1ffbd9b4928 Mon Sep 17 00:00:00 2001 From: RyanAugust Date: Mon, 25 Nov 2024 17:27:00 -0800 Subject: [PATCH 1/6] int and array-like typing --- pymc/distributions/censored.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymc/distributions/censored.py b/pymc/distributions/censored.py index 4be21b1c9d..eb826138b9 100644 --- a/pymc/distributions/censored.py +++ b/pymc/distributions/censored.py @@ -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 From 685dcd0229379172b53f57e096b0ebe15d4ff7bc Mon Sep 17 00:00:00 2001 From: RyanAugust Date: Mon, 25 Nov 2024 17:27:17 -0800 Subject: [PATCH 2/6] example with partial censor --- pymc/distributions/censored.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pymc/distributions/censored.py b/pymc/distributions/censored.py index eb826138b9..dd178d95db 100644 --- a/pymc/distributions/censored.py +++ b/pymc/distributions/censored.py @@ -106,6 +106,9 @@ class Censored(Distribution): 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) + with pm.Model(): + normal_dist = pm.Normal.dist(mu=0.0, sigma=1.0) + partially_censored_normal = pm.Censored("partially_censored_normal", normal_dist, lower=-1, upper=np.inf) """ rv_type = CensoredRV From eb31d65e91530226c6a726afd5e4139e97078252 Mon Sep 17 00:00:00 2001 From: RyanAugust Date: Mon, 25 Nov 2024 22:51:45 -0800 Subject: [PATCH 3/6] int typing for Truncated --- pymc/distributions/truncated.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pymc/distributions/truncated.py b/pymc/distributions/truncated.py index 36b4395263..99ee254105 100644 --- a/pymc/distributions/truncated.py +++ b/pymc/distributions/truncated.py @@ -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. @@ -290,7 +290,6 @@ class Truncated(Distribution): 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) - """ rv_type = TruncatedRV From 578808b2eb035b66cb903bd12aa18886a417b144 Mon Sep 17 00:00:00 2001 From: RyanAugust Date: Mon, 25 Nov 2024 22:52:17 -0800 Subject: [PATCH 4/6] Truncated partial example --- pymc/distributions/truncated.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pymc/distributions/truncated.py b/pymc/distributions/truncated.py index 99ee254105..44f030248b 100644 --- a/pymc/distributions/truncated.py +++ b/pymc/distributions/truncated.py @@ -290,6 +290,9 @@ class Truncated(Distribution): 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) + 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, upper=1) """ rv_type = TruncatedRV From f070e8887ee2aee2c8b55005fef59f94819ad0f1 Mon Sep 17 00:00:00 2001 From: RyanAugust Date: Tue, 26 Nov 2024 11:21:32 -0800 Subject: [PATCH 5/6] example breakout for partial censor + trunc strategies --- pymc/distributions/censored.py | 8 +++++++- pymc/distributions/truncated.py | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pymc/distributions/censored.py b/pymc/distributions/censored.py index dd178d95db..128dbe7615 100644 --- a/pymc/distributions/censored.py +++ b/pymc/distributions/censored.py @@ -101,14 +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), + lower censored (-1, inf), and both censored (-1, 1) + .. code-block:: python with pm.Model(): normal_dist = pm.Normal.dist(mu=0.0, sigma=1.0) - partially_censored_normal = pm.Censored("partially_censored_normal", normal_dist, lower=-1, upper=np.inf) + 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,)) """ rv_type = CensoredRV diff --git a/pymc/distributions/truncated.py b/pymc/distributions/truncated.py index 44f030248b..a946444c26 100644 --- a/pymc/distributions/truncated.py +++ b/pymc/distributions/truncated.py @@ -285,14 +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. + 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, upper=1) + 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 From 50948b41c289b0b468ff1121838655047c8e8d8c Mon Sep 17 00:00:00 2001 From: RyanAugust Date: Tue, 26 Nov 2024 11:34:35 -0800 Subject: [PATCH 6/6] strip whitespace --- pymc/distributions/censored.py | 4 ++-- pymc/distributions/truncated.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pymc/distributions/censored.py b/pymc/distributions/censored.py index 128dbe7615..6122cd25f8 100644 --- a/pymc/distributions/censored.py +++ b/pymc/distributions/censored.py @@ -107,8 +107,8 @@ class Censored(Distribution): 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. + + Partial censoring of normal distributions achienved by passing +/-inf censor points. Examples of 4 censor conditions: uncensored (-inf, inf), upper censored (-inf, 1), lower censored (-1, inf), and both censored (-1, 1) .. code-block:: python diff --git a/pymc/distributions/truncated.py b/pymc/distributions/truncated.py index a946444c26..900eaa9bae 100644 --- a/pymc/distributions/truncated.py +++ b/pymc/distributions/truncated.py @@ -291,8 +291,8 @@ class Truncated(Distribution): 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. + + Partial truncatin 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