Skip to content

Allow passing name as kwarg to pm.Bound RVs #3152

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 1 commit into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions pymc3/distributions/bound.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,23 @@ def __init__(self, distribution, lower=None, upper=None):
self.lower = lower
self.upper = upper

def __call__(self, *args, **kwargs):
def __call__(self, name, *args, **kwargs):
if 'observed' in kwargs:
raise ValueError('Observed Bound distributions are not supported. '
'If you want to model truncated data '
'you can use a pm.Potential in combination '
'with the cumulative probability function. See '
'pymc3/examples/censored_data.py for an example.')
first, args = args[0], args[1:]

if issubclass(self.distribution, Continuous):
return _ContinuousBounded(first, self.distribution,
return _ContinuousBounded(name, self.distribution,
self.lower, self.upper, *args, **kwargs)
elif issubclass(self.distribution, Discrete):
return _DiscreteBounded(first, self.distribution,
return _DiscreteBounded(name, self.distribution,
self.lower, self.upper, *args, **kwargs)
else:
raise ValueError('Distribution is neither continuous nor discrete.')
raise ValueError(
'Distribution is neither continuous nor discrete.')

def dist(self, *args, **kwargs):
if issubclass(self.distribution, Continuous):
Expand Down
4 changes: 4 additions & 0 deletions pymc3/tests/test_distributions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,10 @@ def test_bound():
assert rand.dtype in [np.int16, np.int32, np.int64]
assert rand >= 5 and rand <= 8

with Model():
BoundPoisson = Bound(Poisson, upper=6)
BoundPoisson(name="y", mu=1)


class TestLatex(object):

Expand Down