From aa33cd18637b621d72f9910b47dd7979032912cd Mon Sep 17 00:00:00 2001 From: Sayam753 Date: Sun, 6 Dec 2020 21:49:52 +0530 Subject: [PATCH 1/6] Made sample_shape same across all contexts, thereby resolves #3758 --- pymc3/distributions/distribution.py | 1 + pymc3/tests/test_distributions_random.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/pymc3/distributions/distribution.py b/pymc3/distributions/distribution.py index 408da9a312..238395d1b5 100644 --- a/pymc3/distributions/distribution.py +++ b/pymc3/distributions/distribution.py @@ -690,6 +690,7 @@ def draw_values(params, point=None, size=None): """ # The following check intercepts and redirects calls to # draw_values in the context of sample_posterior_predictive + size = to_tuple(size) ppc_sampler = vectorized_ppc.get(None) if ppc_sampler is not None: # this is being done inside new, vectorized sample_posterior_predictive diff --git a/pymc3/tests/test_distributions_random.py b/pymc3/tests/test_distributions_random.py index 3f8f73ddd0..5b60aec91a 100644 --- a/pymc3/tests/test_distributions_random.py +++ b/pymc3/tests/test_distributions_random.py @@ -1664,6 +1664,10 @@ def test_issue_3758(self): for var in "abcd": assert not np.isnan(np.std(samples[var])) + for var in "bcd": + std = np.std(samples[var] - samples["a"]) + np.testing.assert_allclose(std, 1, rtol=1e-2) + def test_issue_3829(self): with pm.Model() as model: x = pm.MvNormal("x", mu=np.zeros(5), cov=np.eye(5), shape=(2, 5)) From ec8e671e51436d00f160dcab2b03c51d559edca8 Mon Sep 17 00:00:00 2001 From: Sayam753 Date: Sun, 6 Dec 2020 23:23:23 +0530 Subject: [PATCH 2/6] Pass the failing test --- pymc3/distributions/simulator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymc3/distributions/simulator.py b/pymc3/distributions/simulator.py index c64ca3f1cf..a9e4fff480 100644 --- a/pymc3/distributions/simulator.py +++ b/pymc3/distributions/simulator.py @@ -115,10 +115,10 @@ def random(self, point=None, size=None): array """ params = draw_values([*self.params], point=point, size=size) - if size is None: + if not size: return self.function(*params) else: - return np.array([self.function(*params) for _ in range(size)]) + return np.array([self.function(*params) for _ in range(size[0])]) def _str_repr(self, name=None, dist=None, formatting="plain"): if dist is None: From 7a3583a86ead02584322daf6e1b96a8fd0114421 Mon Sep 17 00:00:00 2001 From: Sayam753 Date: Thu, 10 Dec 2020 20:48:38 +0530 Subject: [PATCH 3/6] Worked on suggestions --- pymc3/distributions/simulator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc3/distributions/simulator.py b/pymc3/distributions/simulator.py index a9e4fff480..fc4fe147b0 100644 --- a/pymc3/distributions/simulator.py +++ b/pymc3/distributions/simulator.py @@ -115,7 +115,7 @@ def random(self, point=None, size=None): array """ params = draw_values([*self.params], point=point, size=size) - if not size: + if (size is None) or (len(size) == 0): return self.function(*params) else: return np.array([self.function(*params) for _ in range(size[0])]) From 34e13177e16d21c723e84b3bc20b4952fc84465a Mon Sep 17 00:00:00 2001 From: Sayam753 Date: Thu, 10 Dec 2020 21:00:48 +0530 Subject: [PATCH 4/6] Used to_tuple for size --- pymc3/distributions/simulator.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pymc3/distributions/simulator.py b/pymc3/distributions/simulator.py index fc4fe147b0..1277ec4c82 100644 --- a/pymc3/distributions/simulator.py +++ b/pymc3/distributions/simulator.py @@ -18,7 +18,7 @@ from scipy.spatial import cKDTree -from pymc3.distributions.distribution import NoDistribution, draw_values +from pymc3.distributions.distribution import NoDistribution, draw_values, to_tuple __all__ = ["Simulator"] @@ -114,8 +114,9 @@ def random(self, point=None, size=None): ------- array """ + size = to_tuple(size) params = draw_values([*self.params], point=point, size=size) - if (size is None) or (len(size) == 0): + if len(size) == 0: return self.function(*params) else: return np.array([self.function(*params) for _ in range(size[0])]) From da81fd8be55f40c63571e56215eb42c1165d194a Mon Sep 17 00:00:00 2001 From: Sayam753 Date: Fri, 11 Dec 2020 10:24:54 +0530 Subject: [PATCH 5/6] Given a mention in release notes --- RELEASE-NOTES.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index e6c404520b..d08fb641c6 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,5 +1,10 @@ # Release Notes +## PyMC3 3.10.x + +### Maintenance +- Make `sample_shape` same across all contexts in `draw_values` (see [#4305](https://github.com/pymc-devs/pymc3/pull/4305)). + ## PyMC3 3.10.0 (7 December 2020) This is a major release with many exciting new features. The biggest change is that we now rely on our own fork of [Theano-PyMC](https://github.com/pymc-devs/Theano-PyMC). This is in line with our [big announcement about our commitment to PyMC3 and Theano](https://pymc-devs.medium.com/the-future-of-pymc3-or-theano-is-dead-long-live-theano-d8005f8a0e9b). From a749d754cb6da90ca4c52a72950c7f62ce9824a7 Mon Sep 17 00:00:00 2001 From: Thomas Wiecki Date: Fri, 11 Dec 2020 07:17:07 +0100 Subject: [PATCH 6/6] Update RELEASE-NOTES.md --- RELEASE-NOTES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index d08fb641c6..83b56aa4ed 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -1,6 +1,6 @@ # Release Notes -## PyMC3 3.10.x +## PyMC3 3.10.1 (on deck) ### Maintenance - Make `sample_shape` same across all contexts in `draw_values` (see [#4305](https://github.com/pymc-devs/pymc3/pull/4305)).