From 892f0ae302daf1c5d2ba1690f688de0fceff582c Mon Sep 17 00:00:00 2001 From: Saurav Shekhar Date: Tue, 9 Apr 2019 00:47:50 +0200 Subject: [PATCH 1/3] Fix positional arguments Bound RV --- pymc3/distributions/bound.py | 13 +++++++------ pymc3/tests/test_distributions.py | 4 ++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/pymc3/distributions/bound.py b/pymc3/distributions/bound.py index b1724e7eba..2fa8d707f5 100644 --- a/pymc3/distributions/bound.py +++ b/pymc3/distributions/bound.py @@ -151,8 +151,8 @@ def __init__(self, distribution, lower, upper, default = None super().__init__( - distribution=distribution, lower=lower, upper=upper, - transform=transform, default=default, *args, **kwargs) + distribution, lower, upper, + default, *args, transform=transform, **kwargs) class Bound: @@ -214,12 +214,13 @@ def __call__(self, name, *args, **kwargs): 'with the cumulative probability function. See ' 'pymc3/examples/censored_data.py for an example.') + transform = kwargs.pop('transform', 'infer') if issubclass(self.distribution, Continuous): - return _ContinuousBounded(name, self.distribution, - self.lower, self.upper, *args, **kwargs) + return _ContinuousBounded(name, self.distribution, self.lower, + self.upper, transform, *args, **kwargs) elif issubclass(self.distribution, Discrete): - return _DiscreteBounded(name, self.distribution, - self.lower, self.upper, *args, **kwargs) + return _DiscreteBounded(name, self.distribution, self.lower, + self.upper, transform, *args, **kwargs) else: raise ValueError( 'Distribution is neither continuous nor discrete.') diff --git a/pymc3/tests/test_distributions.py b/pymc3/tests/test_distributions.py index dbb02d36d8..0b4c692453 100644 --- a/pymc3/tests/test_distributions.py +++ b/pymc3/tests/test_distributions.py @@ -1295,6 +1295,10 @@ def test_bound(): BoundPoisson = Bound(Poisson, upper=6) BoundPoisson(name="y", mu=1) + with Model(): + BoundNormalNamedArgs = Bound(Normal, upper=6)("y", mu=2., sd=1.) + BoundNormalPositionalArgs = Bound(Normal, upper=6)("x", 2., 1.) + class TestLatex: From 83c33a8aaafc89af29994f1bd0af39125fa7833c Mon Sep 17 00:00:00 2001 From: Saurav Shekhar Date: Tue, 9 Apr 2019 20:20:11 +0200 Subject: [PATCH 2/3] Positional argument fix for DiscreteBound --- pymc3/distributions/bound.py | 4 ++-- pymc3/tests/test_distributions.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pymc3/distributions/bound.py b/pymc3/distributions/bound.py index 2fa8d707f5..c12d77d5fc 100644 --- a/pymc3/distributions/bound.py +++ b/pymc3/distributions/bound.py @@ -103,8 +103,8 @@ def __init__(self, distribution, lower, upper, default = lower + 1 super().__init__( - distribution=distribution, lower=lower, upper=upper, - default=default, *args, **kwargs) + distribution, lower, upper, + default, *args, transform=transform, **kwargs) class _ContinuousBounded(_Bounded, Continuous): diff --git a/pymc3/tests/test_distributions.py b/pymc3/tests/test_distributions.py index 0b4c692453..020a91020d 100644 --- a/pymc3/tests/test_distributions.py +++ b/pymc3/tests/test_distributions.py @@ -1300,6 +1300,11 @@ def test_bound(): BoundNormalPositionalArgs = Bound(Normal, upper=6)("x", 2., 1.) + with Model(): + BoundPoissonNamedArgs = Bound(Poisson, upper=6)("y", mu=2.) + BoundPoissonPositionalArgs = Bound(Poisson, upper=6)("x", 2.) + + class TestLatex: def setup_class(self): From 33b2766cbfebcc3b53117d673cc341de43626316 Mon Sep 17 00:00:00 2001 From: Saurav Shekhar Date: Tue, 9 Apr 2019 20:47:02 +0200 Subject: [PATCH 3/3] Update RELEASE-NOTES.md PR #3446 --- RELEASE-NOTES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 1bb05cd86f..2dcbe29bfc 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -30,6 +30,7 @@ - `Categorical` now accepts elements of `p` equal to `0`. `logp` will return `-inf` if there are `values` that index to the zero probability categories. - Add `sigma`, `tau`, and `sd` to signature of `NormalMixture`. - Resolved issue #3248. Set default lower and upper values of -inf and inf for pm.distributions.continuous.TruncatedNormal. This avoids errors caused by their previous values of None. +- Resolved issue #3399. Converted all calls to `pm.distributions.bound._ContinuousBounded` and `pm.distributions.bound._DiscreteBounded` to use only and all positional arguments. ### Deprecations