Skip to content

Commit e79c852

Browse files
committed
add doc strings for logp methods in discrete distribution classes
1 parent 4817bc5 commit e79c852

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed

pymc3/distributions/discrete.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,32 @@ def random(self, point=None, size=None):
8888
size=size)
8989

9090
def logp(self, value):
91+
"""
92+
Calculate log-probability of Binomial distribution at specified value.
93+
94+
Parameters
95+
----------
96+
value : numeric
97+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
98+
values are desired the values must be provided in a numpy array or theano tensor
99+
100+
Returns
101+
-------
102+
TensorVariable
103+
"""
104+
"""
105+
Calculate log-probability of Binomial distribution at specified value.
106+
107+
Parameters
108+
----------
109+
value : numeric
110+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
111+
values are desired the values must be provided in a numpy array or theano tensor
112+
113+
Returns
114+
-------
115+
TensorVariable
116+
"""
91117
n = self.n
92118
p = self.p
93119

@@ -211,6 +237,19 @@ def random(self, point=None, size=None):
211237
size=size)
212238

213239
def logp(self, value):
240+
"""
241+
Calculate log-probability of BetaBinomial distribution at specified value.
242+
243+
Parameters
244+
----------
245+
value : numeric
246+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
247+
values are desired the values must be provided in a numpy array or theano tensor
248+
249+
Returns
250+
-------
251+
TensorVariable
252+
"""
214253
alpha = self.alpha
215254
beta = self.beta
216255
return bound(binomln(self.n, value)
@@ -308,6 +347,19 @@ def random(self, point=None, size=None):
308347
size=size)
309348

310349
def logp(self, value):
350+
"""
351+
Calculate log-probability of Bernoulli distribution at specified value.
352+
353+
Parameters
354+
----------
355+
value : numeric
356+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
357+
values are desired the values must be provided in a numpy array or theano tensor
358+
359+
Returns
360+
-------
361+
TensorVariable
362+
"""
311363
if self._is_logit:
312364
lp = tt.switch(value, self._logit_p, -self._logit_p)
313365
return -log1pexp(-lp)
@@ -374,6 +426,19 @@ def __init__(self, q, beta, *args, **kwargs):
374426
self.median = self._ppf(0.5)
375427

376428
def logp(self, value):
429+
"""
430+
Calculate log-probability of DiscreteWeibull distribution at specified value.
431+
432+
Parameters
433+
----------
434+
value : numeric
435+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
436+
values are desired the values must be provided in a numpy array or theano tensor
437+
438+
Returns
439+
-------
440+
TensorVariable
441+
"""
377442
q = self.q
378443
beta = self.beta
379444

@@ -503,6 +568,19 @@ def random(self, point=None, size=None):
503568
size=size)
504569

505570
def logp(self, value):
571+
"""
572+
Calculate log-probability of Poisson distribution at specified value.
573+
574+
Parameters
575+
----------
576+
value : numeric
577+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
578+
values are desired the values must be provided in a numpy array or theano tensor
579+
580+
Returns
581+
-------
582+
TensorVariable
583+
"""
506584
mu = self.mu
507585
log_prob = bound(
508586
logpow(mu, value) - factln(value) - mu,
@@ -601,6 +679,19 @@ def random(self, point=None, size=None):
601679
return np.asarray(stats.poisson.rvs(g)).reshape(g.shape)
602680

603681
def logp(self, value):
682+
"""
683+
Calculate log-probability of NegativeBinomial distribution at specified value.
684+
685+
Parameters
686+
----------
687+
value : numeric
688+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
689+
values are desired the values must be provided in a numpy array or theano tensor
690+
691+
Returns
692+
-------
693+
TensorVariable
694+
"""
604695
mu = self.mu
605696
alpha = self.alpha
606697
negbinom = bound(binomln(value + alpha - 1, value)
@@ -689,6 +780,19 @@ def random(self, point=None, size=None):
689780
size=size)
690781

691782
def logp(self, value):
783+
"""
784+
Calculate log-probability of Geometric distribution at specified value.
785+
786+
Parameters
787+
----------
788+
value : numeric
789+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
790+
values are desired the values must be provided in a numpy array or theano tensor
791+
792+
Returns
793+
-------
794+
TensorVariable
795+
"""
692796
p = self.p
693797
return bound(tt.log(p) + logpow(1 - p, value - 1),
694798
0 <= p, p <= 1, value >= 1)
@@ -778,6 +882,19 @@ def random(self, point=None, size=None):
778882
size=size)
779883

780884
def logp(self, value):
885+
"""
886+
Calculate log-probability of DiscreteUniform distribution at specified value.
887+
888+
Parameters
889+
----------
890+
value : numeric
891+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
892+
values are desired the values must be provided in a numpy array or theano tensor
893+
894+
Returns
895+
-------
896+
TensorVariable
897+
"""
781898
upper = self.upper
782899
lower = self.lower
783900
return bound(-tt.log(upper - lower + 1),
@@ -871,6 +988,19 @@ def random(self, point=None, size=None):
871988
size=size)
872989

873990
def logp(self, value):
991+
"""
992+
Calculate log-probability of Categorical distribution at specified value.
993+
994+
Parameters
995+
----------
996+
value : numeric
997+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
998+
values are desired the values must be provided in a numpy array or theano tensor
999+
1000+
Returns
1001+
-------
1002+
TensorVariable
1003+
"""
8741004
p_ = self.p
8751005
k = self.k
8761006

@@ -940,6 +1070,19 @@ def _random(c, dtype=dtype, size=None):
9401070
size=size).astype(dtype)
9411071

9421072
def logp(self, value):
1073+
"""
1074+
Calculate log-probability of Constant distribution at specified value.
1075+
1076+
Parameters
1077+
----------
1078+
value : numeric
1079+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
1080+
values are desired the values must be provided in a numpy array or theano tensor
1081+
1082+
Returns
1083+
-------
1084+
TensorVariable
1085+
"""
9431086
c = self.c
9441087
return bound(0, tt.eq(value, c))
9451088

@@ -1035,6 +1178,19 @@ def random(self, point=None, size=None):
10351178
return g * (np.random.random(g.shape) < psi)
10361179

10371180
def logp(self, value):
1181+
"""
1182+
Calculate log-probability of ZeroInflatedPoisson distribution at specified value.
1183+
1184+
Parameters
1185+
----------
1186+
value : numeric
1187+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
1188+
values are desired the values must be provided in a numpy array or theano tensor
1189+
1190+
Returns
1191+
-------
1192+
TensorVariable
1193+
"""
10381194
psi = self.psi
10391195
theta = self.theta
10401196

@@ -1144,6 +1300,19 @@ def random(self, point=None, size=None):
11441300
return g * (np.random.random(g.shape) < psi)
11451301

11461302
def logp(self, value):
1303+
"""
1304+
Calculate log-probability of ZeroInflatedBinomial distribution at specified value.
1305+
1306+
Parameters
1307+
----------
1308+
value : numeric
1309+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
1310+
values are desired the values must be provided in a numpy array or theano tensor
1311+
1312+
Returns
1313+
-------
1314+
TensorVariable
1315+
"""
11471316
psi = self.psi
11481317
p = self.p
11491318
n = self.n
@@ -1279,6 +1448,19 @@ def random(self, point=None, size=None):
12791448
return stats.poisson.rvs(g) * (np.random.random(g.shape) < psi)
12801449

12811450
def logp(self, value):
1451+
"""
1452+
Calculate log-probability of ZeroInflatedNegativeBinomial distribution at specified value.
1453+
1454+
Parameters
1455+
----------
1456+
value : numeric
1457+
Value(s) for which log-probability is calculated. If the log probabilities for multiple
1458+
values are desired the values must be provided in a numpy array or theano tensor
1459+
1460+
Returns
1461+
-------
1462+
TensorVariable
1463+
"""
12821464
alpha = self.alpha
12831465
mu = self.mu
12841466
psi = self.psi

0 commit comments

Comments
 (0)