Skip to content

Commit c8d8ee1

Browse files
authored
Merge pull request #3446 from sshekh/patch-1
Fix positional arguments for Bounded RVs
2 parents fbe86a4 + 33b2766 commit c8d8ee1

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- `Categorical` now accepts elements of `p` equal to `0`. `logp` will return `-inf` if there are `values` that index to the zero probability categories.
3131
- Add `sigma`, `tau`, and `sd` to signature of `NormalMixture`.
3232
- 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.
33+
- Resolved issue #3399. Converted all calls to `pm.distributions.bound._ContinuousBounded` and `pm.distributions.bound._DiscreteBounded` to use only and all positional arguments.
3334

3435
### Deprecations
3536

pymc3/distributions/bound.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ def __init__(self, distribution, lower, upper,
103103
default = lower + 1
104104

105105
super().__init__(
106-
distribution=distribution, lower=lower, upper=upper,
107-
default=default, *args, **kwargs)
106+
distribution, lower, upper,
107+
default, *args, transform=transform, **kwargs)
108108

109109

110110
class _ContinuousBounded(_Bounded, Continuous):
@@ -151,8 +151,8 @@ def __init__(self, distribution, lower, upper,
151151
default = None
152152

153153
super().__init__(
154-
distribution=distribution, lower=lower, upper=upper,
155-
transform=transform, default=default, *args, **kwargs)
154+
distribution, lower, upper,
155+
default, *args, transform=transform, **kwargs)
156156

157157

158158
class Bound:
@@ -214,12 +214,13 @@ def __call__(self, name, *args, **kwargs):
214214
'with the cumulative probability function. See '
215215
'pymc3/examples/censored_data.py for an example.')
216216

217+
transform = kwargs.pop('transform', 'infer')
217218
if issubclass(self.distribution, Continuous):
218-
return _ContinuousBounded(name, self.distribution,
219-
self.lower, self.upper, *args, **kwargs)
219+
return _ContinuousBounded(name, self.distribution, self.lower,
220+
self.upper, transform, *args, **kwargs)
220221
elif issubclass(self.distribution, Discrete):
221-
return _DiscreteBounded(name, self.distribution,
222-
self.lower, self.upper, *args, **kwargs)
222+
return _DiscreteBounded(name, self.distribution, self.lower,
223+
self.upper, transform, *args, **kwargs)
223224
else:
224225
raise ValueError(
225226
'Distribution is neither continuous nor discrete.')

pymc3/tests/test_distributions.py

+9
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,15 @@ def test_bound():
12951295
BoundPoisson = Bound(Poisson, upper=6)
12961296
BoundPoisson(name="y", mu=1)
12971297

1298+
with Model():
1299+
BoundNormalNamedArgs = Bound(Normal, upper=6)("y", mu=2., sd=1.)
1300+
BoundNormalPositionalArgs = Bound(Normal, upper=6)("x", 2., 1.)
1301+
1302+
1303+
with Model():
1304+
BoundPoissonNamedArgs = Bound(Poisson, upper=6)("y", mu=2.)
1305+
BoundPoissonPositionalArgs = Bound(Poisson, upper=6)("x", 2.)
1306+
12981307

12991308
class TestLatex:
13001309

0 commit comments

Comments
 (0)