From 106b960d3490e30519c66199460b42c55f20bc71 Mon Sep 17 00:00:00 2001 From: Shivam Sahni <56823758+shivam15s@users.noreply.github.com> Date: Mon, 8 Nov 2021 21:56:25 +0530 Subject: [PATCH 1/5] Update pymc/tests/test_distributions_moments.py Co-authored-by: Ricardo Vieira <28983449+ricardoV94@users.noreply.github.com> --- pymc/tests/test_distributions_moments.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc/tests/test_distributions_moments.py b/pymc/tests/test_distributions_moments.py index 7eb39ac965..b209d60912 100644 --- a/pymc/tests/test_distributions_moments.py +++ b/pymc/tests/test_distributions_moments.py @@ -348,7 +348,7 @@ def test_weibull_moment(alpha, beta, size, expected): [ (1, 1, None, 1), (1, 1, 5, np.full(5, 1)), - (np.arange(1, 6), np.arange(1, 6), None, np.arange(1, 6)), + (2, np.arange(1, 6), None, np.full(5, 2)), ( np.arange(1, 6), np.arange(1, 6), From e2d1ee78697a838ad740f736d464a38375112189 Mon Sep 17 00:00:00 2001 From: shivam15s Date: Tue, 9 Nov 2021 01:58:11 +0530 Subject: [PATCH 2/5] Add Logistic Moment --- pymc/distributions/continuous.py | 6 ++++++ pymc/tests/test_distributions_moments.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pymc/distributions/continuous.py b/pymc/distributions/continuous.py index 9d4b770140..bd1b803167 100644 --- a/pymc/distributions/continuous.py +++ b/pymc/distributions/continuous.py @@ -3386,6 +3386,12 @@ def dist(cls, mu=0.0, s=1.0, *args, **kwargs): s = at.as_tensor_variable(floatX(s)) return super().dist([mu, s], *args, **kwargs) + def get_moment(rv, size, mu, s): + mu, _ = at.broadcast_arrays(mu, s) + if not rv_size_is_none(size): + mu = at.full(size, mu) + return mu + def logcdf(value, mu, s): r""" Compute the log of the cumulative distribution function for Logistic distribution diff --git a/pymc/tests/test_distributions_moments.py b/pymc/tests/test_distributions_moments.py index a01b7cc469..7eb39ac965 100644 --- a/pymc/tests/test_distributions_moments.py +++ b/pymc/tests/test_distributions_moments.py @@ -14,6 +14,7 @@ HalfNormal, Kumaraswamy, Laplace, + Logistic, LogNormal, StudentT, Weibull, @@ -341,3 +342,22 @@ def test_weibull_moment(alpha, beta, size, expected): with Model() as model: Weibull("x", alpha=alpha, beta=beta, size=size) assert_moment_is_expected(model, expected) + +@pytest.mark.parametrize( + "mu, s, size, expected", + [ + (1, 1, None, 1), + (1, 1, 5, np.full(5, 1)), + (np.arange(1, 6), np.arange(1, 6), None, np.arange(1, 6)), + ( + np.arange(1, 6), + np.arange(1, 6), + (2, 5), + np.full((2, 5), np.arange(1,6)), + ), + ], +) +def test_logistic_moment(mu, s, size, expected): + with Model() as model: + Logistic("x", mu=mu, s=s, size=size) + assert_moment_is_expected(model, expected) From cc4d440fbd83f1667751487477774919482cdda1 Mon Sep 17 00:00:00 2001 From: shivam15s Date: Tue, 9 Nov 2021 03:58:41 +0530 Subject: [PATCH 3/5] Fixed linting --- pymc/tests/test_distributions_moments.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pymc/tests/test_distributions_moments.py b/pymc/tests/test_distributions_moments.py index 7eb39ac965..3e19e8fef0 100644 --- a/pymc/tests/test_distributions_moments.py +++ b/pymc/tests/test_distributions_moments.py @@ -343,17 +343,18 @@ def test_weibull_moment(alpha, beta, size, expected): Weibull("x", alpha=alpha, beta=beta, size=size) assert_moment_is_expected(model, expected) + @pytest.mark.parametrize( "mu, s, size, expected", [ (1, 1, None, 1), (1, 1, 5, np.full(5, 1)), - (np.arange(1, 6), np.arange(1, 6), None, np.arange(1, 6)), + (2, np.arange(1, 6), None, np.full(5, 2)), ( np.arange(1, 6), np.arange(1, 6), (2, 5), - np.full((2, 5), np.arange(1,6)), + np.full((2, 5), np.arange(1, 6)), ), ], ) From e1b8f0ce5c722df8d9e70cfa6eda03f9f4092c26 Mon Sep 17 00:00:00 2001 From: shivam15s Date: Tue, 9 Nov 2021 04:30:03 +0530 Subject: [PATCH 4/5] pre-commit done --- pymc/tests/test_distributions_moments.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pymc/tests/test_distributions_moments.py b/pymc/tests/test_distributions_moments.py index 1fafaa8169..7ea14a6b14 100644 --- a/pymc/tests/test_distributions_moments.py +++ b/pymc/tests/test_distributions_moments.py @@ -383,7 +383,8 @@ def test_poisson_moment(mu, size, expected): with Model() as model: Poisson("x", mu=mu, size=size) assert_moment_is_expected(model, expected) - + + @pytest.mark.parametrize( "mu, s, size, expected", [ From ec7a59c673f0d74228fbbdfad189045883125e77 Mon Sep 17 00:00:00 2001 From: shivam15s Date: Tue, 9 Nov 2021 07:24:17 +0530 Subject: [PATCH 5/5] pre-commit done --- pymc/tests/test_distributions_moments.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pymc/tests/test_distributions_moments.py b/pymc/tests/test_distributions_moments.py index 46b478a03c..9e2d56afdb 100644 --- a/pymc/tests/test_distributions_moments.py +++ b/pymc/tests/test_distributions_moments.py @@ -434,4 +434,3 @@ def test_logistic_moment(mu, s, size, expected): with Model() as model: Logistic("x", mu=mu, s=s, size=size) assert_moment_is_expected(model, expected) -