Skip to content
/ pymc Public
  • Sponsor pymc-devs/pymc

  • Notifications You must be signed in to change notification settings
  • Fork 2.1k

Fix positional arguments for Bounded RVs #3446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -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

17 changes: 9 additions & 8 deletions pymc3/distributions/bound.py
Original file line number Diff line number Diff line change
@@ -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):
@@ -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.')
9 changes: 9 additions & 0 deletions pymc3/tests/test_distributions.py
Original file line number Diff line number Diff line change
@@ -1295,6 +1295,15 @@ 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.)


with Model():
BoundPoissonNamedArgs = Bound(Poisson, upper=6)("y", mu=2.)
BoundPoissonPositionalArgs = Bound(Poisson, upper=6)("x", 2.)


class TestLatex: