Skip to content

Commit bcf87a2

Browse files
committed
Raise TypeError in logcdf methods that only accept scalar values.
Fix docstring formatting.
1 parent 670a652 commit bcf87a2

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

pymc3/distributions/discrete.py

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,14 @@ def logcdf(self, value):
163163
-------
164164
TensorVariable
165165
"""
166-
# TODO: work with multiple values (see #4342)
166+
# incomplete_beta function can only handle scalar values (see #4342)
167+
if np.ndim(value):
168+
raise TypeError(
169+
"Binomial.logcdf expects a scalar value but received a {}-dimensional object.".format(
170+
np.ndim(value)
171+
)
172+
)
173+
167174
n = self.n
168175
p = self.p
169176
value = tt.floor(value)
@@ -326,7 +333,14 @@ def logcdf(self, value):
326333
-------
327334
TensorVariable
328335
"""
329-
# TODO: fix for multiple values
336+
# logcdf can only handle scalar values at the moment
337+
if np.ndim(value):
338+
raise TypeError(
339+
"BetaBinomial.logcdf expects a scalar value but received a {}-dimensional object.".format(
340+
np.ndim(value)
341+
)
342+
)
343+
330344
alpha = self.alpha
331345
beta = self.beta
332346
n = self.n
@@ -446,11 +460,13 @@ def logcdf(self, value):
446460
"""
447461
Compute the log of the cumulative distribution function for Bernoulli distribution
448462
at the specified value.
463+
449464
Parameters
450465
----------
451466
value: numeric
452467
Value(s) for which log CDF is calculated. If the log CDF for multiple
453468
values are desired the values must be provided in a numpy array or theano tensor.
469+
454470
Returns
455471
-------
456472
TensorVariable
@@ -583,11 +599,13 @@ def logcdf(self, value):
583599
"""
584600
Compute the log of the cumulative distribution function for Discrete Weibull distribution
585601
at the specified value.
602+
586603
Parameters
587604
----------
588605
value: numeric
589606
Value(s) for which log CDF is calculated. If the log CDF for multiple
590607
values are desired the values must be provided in a numpy array or theano tensor.
608+
591609
Returns
592610
-------
593611
TensorVariable
@@ -696,11 +714,13 @@ def logcdf(self, value):
696714
"""
697715
Compute the log of the cumulative distribution function for Poisson distribution
698716
at the specified value.
717+
699718
Parameters
700719
----------
701720
value: numeric
702721
Value(s) for which log CDF is calculated. If the log CDF for multiple
703722
values are desired the values must be provided in a numpy array or theano tensor.
723+
704724
Returns
705725
-------
706726
TensorVariable
@@ -887,7 +907,14 @@ def logcdf(self, value):
887907
-------
888908
TensorVariable
889909
"""
890-
# TODO: work with multiple values (see #4342)
910+
# incomplete_beta function can only handle scalar values (see #4342)
911+
if np.ndim(value):
912+
raise TypeError(
913+
"NegativeBinomial.logcdf expects a scalar value but received a {}-dimensional object.".format(
914+
np.ndim(value)
915+
)
916+
)
917+
891918
# TODO: avoid `p` recomputation if distribution was defined in terms of `p`
892919
alpha = self.alpha
893920
p = alpha / (self.mu + alpha)
@@ -987,11 +1014,13 @@ def logcdf(self, value):
9871014
"""
9881015
Compute the log of the cumulative distribution function for Geometric distribution
9891016
at the specified value.
1017+
9901018
Parameters
9911019
----------
9921020
value: numeric
9931021
Value(s) for which log CDF is calculated. If the log CDF for multiple
9941022
values are desired the values must be provided in a numpy array or theano tensor.
1023+
9951024
Returns
9961025
-------
9971026
TensorVariable
@@ -1124,15 +1153,24 @@ def logcdf(self, value):
11241153
"""
11251154
Compute the log of the cumulative distribution function for HyperGeometric distribution
11261155
at the specified value.
1156+
11271157
Parameters
11281158
----------
11291159
value: numeric
11301160
Value for which log CDF is calculated.
1161+
11311162
Returns
11321163
-------
11331164
TensorVariable
11341165
"""
1135-
# TODO: fix for multiple values
1166+
# logcdf can only handle scalar values at the moment
1167+
if np.ndim(value):
1168+
raise TypeError(
1169+
"BetaBinomial.logcdf expects a scalar value but received a {}-dimensional object.".format(
1170+
np.ndim(value)
1171+
)
1172+
)
1173+
11361174
# TODO: Use lower upper in locgdf for smarter logsumexp?
11371175
N = self.N
11381176
n = self.n
@@ -1247,11 +1285,13 @@ def logcdf(self, value):
12471285
"""
12481286
Compute the log of the cumulative distribution function for Discrete uniform distribution
12491287
at the specified value.
1288+
12501289
Parameters
12511290
----------
12521291
value: numeric
12531292
Value(s) for which log CDF is calculated. If the log CDF for multiple
12541293
values are desired the values must be provided in a numpy array or theano tensor.
1294+
12551295
Returns
12561296
-------
12571297
TensorVariable
@@ -1558,11 +1598,13 @@ def logcdf(self, value):
15581598
"""
15591599
Compute the log of the cumulative distribution function for ZeroInflatedPoisson distribution
15601600
at the specified value.
1601+
15611602
Parameters
15621603
----------
15631604
value: numeric
15641605
Value(s) for which log CDF is calculated. If the log CDF for multiple
15651606
values are desired the values must be provided in a numpy array or theano tensor.
1607+
15661608
Returns
15671609
-------
15681610
TensorVariable
@@ -1698,7 +1740,14 @@ def logcdf(self, value):
16981740
-------
16991741
TensorVariable
17001742
"""
1701-
# TODO: work with multiple values (see #4342)
1743+
# logcdf can only handle scalar values due to limitation in Binomial.logcdf
1744+
if np.ndim(value):
1745+
raise TypeError(
1746+
"ZeroInflatedBinomial.logcdf expects a scalar value but received a {}-dimensional object.".format(
1747+
np.ndim(value)
1748+
)
1749+
)
1750+
17021751
psi = self.psi
17031752

17041753
return bound(
@@ -1861,7 +1910,13 @@ def logcdf(self, value):
18611910
-------
18621911
TensorVariable
18631912
"""
1864-
# TODO: work with multiple values (see #4342)
1913+
# logcdf can only handle scalar values due to limitation in NegativeBinomial.logcdf
1914+
if np.ndim(value):
1915+
raise TypeError(
1916+
"ZeroInflatedNegativeBinomial.logcdf expects a scalar value but received a {}-dimensional object.".format(
1917+
np.ndim(value)
1918+
)
1919+
)
18651920
psi = self.psi
18661921

18671922
return bound(

0 commit comments

Comments
 (0)