Skip to content

Commit e2a97ea

Browse files
committed
Add doc strings to all random methods for discrete distribution classes
1 parent 6f2d82f commit e2a97ea

File tree

1 file changed

+208
-0
lines changed

1 file changed

+208
-0
lines changed

pymc3/distributions/discrete.py

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ def __init__(self, n, p, *args, **kwargs):
6666
self.mode = tt.cast(tround(n * p), self.dtype)
6767

6868
def random(self, point=None, size=None):
69+
"""
70+
Draw random values from Binomial distribution.
71+
72+
Parameters
73+
----------
74+
point : dict, optional
75+
Dict of variable values on which random values are to be
76+
conditioned (uses default point if not specified).
77+
size : int, optional
78+
Desired size of random sample (returns one sample if not
79+
specified).
80+
81+
Returns
82+
-------
83+
array
84+
"""
6985
n, p = draw_values([self.n, self.p], point=point, size=size)
7086
return generate_samples(stats.binom.rvs, n=n, p=p,
7187
dist_shape=self.shape,
@@ -172,6 +188,22 @@ def _random(self, alpha, beta, n, size=None):
172188
return samples
173189

174190
def random(self, point=None, size=None):
191+
"""
192+
Draw random values from BetaBinomial distribution.
193+
194+
Parameters
195+
----------
196+
point : dict, optional
197+
Dict of variable values on which random values are to be
198+
conditioned (uses default point if not specified).
199+
size : int, optional
200+
Desired size of random sample (returns one sample if not
201+
specified).
202+
203+
Returns
204+
-------
205+
array
206+
"""
175207
alpha, beta, n = \
176208
draw_values([self.alpha, self.beta, self.n], point=point, size=size)
177209
return generate_samples(self._random, alpha=alpha, beta=beta, n=n,
@@ -254,6 +286,22 @@ def __init__(self, p=None, logit_p=None, *args, **kwargs):
254286
self.mode = tt.cast(tround(self.p), 'int8')
255287

256288
def random(self, point=None, size=None):
289+
"""
290+
Draw random values from Bernoulli distribution.
291+
292+
Parameters
293+
----------
294+
point : dict, optional
295+
Dict of variable values on which random values are to be
296+
conditioned (uses default point if not specified).
297+
size : int, optional
298+
Desired size of random sample (returns one sample if not
299+
specified).
300+
301+
Returns
302+
-------
303+
array
304+
"""
257305
p = draw_values([self.p], point=point, size=size)[0]
258306
return generate_samples(stats.bernoulli.rvs, p,
259307
dist_shape=self.shape,
@@ -350,6 +398,22 @@ def _random(self, q, beta, size=None):
350398
return np.ceil(np.power(np.log(1 - p) / np.log(q), 1. / beta)) - 1
351399

352400
def random(self, point=None, size=None):
401+
"""
402+
Draw random values from DiscreteWeibull distribution.
403+
404+
Parameters
405+
----------
406+
point : dict, optional
407+
Dict of variable values on which random values are to be
408+
conditioned (uses default point if not specified).
409+
size : int, optional
410+
Desired size of random sample (returns one sample if not
411+
specified).
412+
413+
Returns
414+
-------
415+
array
416+
"""
353417
q, beta = draw_values([self.q, self.beta], point=point, size=size)
354418

355419
return generate_samples(self._random, q, beta,
@@ -417,6 +481,22 @@ def __init__(self, mu, *args, **kwargs):
417481
self.mode = intX(tt.floor(mu))
418482

419483
def random(self, point=None, size=None):
484+
"""
485+
Draw random values from Poisson distribution.
486+
487+
Parameters
488+
----------
489+
point : dict, optional
490+
Dict of variable values on which random values are to be
491+
conditioned (uses default point if not specified).
492+
size : int, optional
493+
Desired size of random sample (returns one sample if not
494+
specified).
495+
496+
Returns
497+
-------
498+
array
499+
"""
420500
mu = draw_values([self.mu], point=point, size=size)[0]
421501
return generate_samples(stats.poisson.rvs, mu,
422502
dist_shape=self.shape,
@@ -497,6 +577,22 @@ def __init__(self, mu, alpha, *args, **kwargs):
497577
self.mode = intX(tt.floor(mu))
498578

499579
def random(self, point=None, size=None):
580+
"""
581+
Draw random values from NegativeBinomial distribution.
582+
583+
Parameters
584+
----------
585+
point : dict, optional
586+
Dict of variable values on which random values are to be
587+
conditioned (uses default point if not specified).
588+
size : int, optional
589+
Desired size of random sample (returns one sample if not
590+
specified).
591+
592+
Returns
593+
-------
594+
array
595+
"""
500596
mu, alpha = draw_values([self.mu, self.alpha], point=point, size=size)
501597
g = generate_samples(stats.gamma.rvs, alpha, scale=mu / alpha,
502598
dist_shape=self.shape,
@@ -571,6 +667,22 @@ def __init__(self, p, *args, **kwargs):
571667
self.mode = 1
572668

573669
def random(self, point=None, size=None):
670+
"""
671+
Draw random values from Geometric distribution.
672+
673+
Parameters
674+
----------
675+
point : dict, optional
676+
Dict of variable values on which random values are to be
677+
conditioned (uses default point if not specified).
678+
size : int, optional
679+
Desired size of random sample (returns one sample if not
680+
specified).
681+
682+
Returns
683+
-------
684+
array
685+
"""
574686
p = draw_values([self.p], point=point, size=size)[0]
575687
return generate_samples(np.random.geometric, p,
576688
dist_shape=self.shape,
@@ -643,6 +755,22 @@ def _random(self, lower, upper, size=None):
643755
return samples
644756

645757
def random(self, point=None, size=None):
758+
"""
759+
Draw random values from DiscreteUniform distribution.
760+
761+
Parameters
762+
----------
763+
point : dict, optional
764+
Dict of variable values on which random values are to be
765+
conditioned (uses default point if not specified).
766+
size : int, optional
767+
Desired size of random sample (returns one sample if not
768+
specified).
769+
770+
Returns
771+
-------
772+
array
773+
"""
646774
lower, upper = draw_values([self.lower, self.upper], point=point, size=size)
647775
return generate_samples(self._random,
648776
lower, upper,
@@ -717,6 +845,22 @@ def __init__(self, p, *args, **kwargs):
717845
self.mode = tt.squeeze(self.mode)
718846

719847
def random(self, point=None, size=None):
848+
"""
849+
Draw random values from Categorical distribution.
850+
851+
Parameters
852+
----------
853+
point : dict, optional
854+
Dict of variable values on which random values are to be
855+
conditioned (uses default point if not specified).
856+
size : int, optional
857+
Desired size of random sample (returns one sample if not
858+
specified).
859+
860+
Returns
861+
-------
862+
array
863+
"""
720864
p, k = draw_values([self.p, self.k], point=point, size=size)
721865
p = p / np.sum(p, axis=-1, keepdims=True)
722866

@@ -770,6 +914,22 @@ def __init__(self, c, *args, **kwargs):
770914
self.mean = self.median = self.mode = self.c = c = tt.as_tensor_variable(c)
771915

772916
def random(self, point=None, size=None):
917+
"""
918+
Draw random values from Constant distribution.
919+
920+
Parameters
921+
----------
922+
point : dict, optional
923+
Dict of variable values on which random values are to be
924+
conditioned (uses default point if not specified).
925+
size : int, optional
926+
Desired size of random sample (returns one sample if not
927+
specified).
928+
929+
Returns
930+
-------
931+
array
932+
"""
773933
c = draw_values([self.c], point=point, size=size)[0]
774934
dtype = np.array(c).dtype
775935

@@ -851,6 +1011,22 @@ def __init__(self, psi, theta, *args, **kwargs):
8511011
self.mode = self.pois.mode
8521012

8531013
def random(self, point=None, size=None):
1014+
"""
1015+
Draw random values from ZeroInflatedPoisson distribution.
1016+
1017+
Parameters
1018+
----------
1019+
point : dict, optional
1020+
Dict of variable values on which random values are to be
1021+
conditioned (uses default point if not specified).
1022+
size : int, optional
1023+
Desired size of random sample (returns one sample if not
1024+
specified).
1025+
1026+
Returns
1027+
-------
1028+
array
1029+
"""
8541030
theta, psi = draw_values([self.theta, self.psi], point=point, size=size)
8551031
g = generate_samples(stats.poisson.rvs, theta,
8561032
dist_shape=self.shape,
@@ -944,6 +1120,22 @@ def __init__(self, psi, n, p, *args, **kwargs):
9441120
self.mode = self.bin.mode
9451121

9461122
def random(self, point=None, size=None):
1123+
"""
1124+
Draw random values from ZeroInflatedBinomial distribution.
1125+
1126+
Parameters
1127+
----------
1128+
point : dict, optional
1129+
Dict of variable values on which random values are to be
1130+
conditioned (uses default point if not specified).
1131+
size : int, optional
1132+
Desired size of random sample (returns one sample if not
1133+
specified).
1134+
1135+
Returns
1136+
-------
1137+
array
1138+
"""
9471139
n, p, psi = draw_values([self.n, self.p, self.psi], point=point, size=size)
9481140
g = generate_samples(stats.binom.rvs, n, p,
9491141
dist_shape=self.shape,
@@ -1061,6 +1253,22 @@ def __init__(self, psi, mu, alpha, *args, **kwargs):
10611253
self.mode = self.nb.mode
10621254

10631255
def random(self, point=None, size=None):
1256+
"""
1257+
Draw random values from ZeroInflatedNegativeBinomial distribution.
1258+
1259+
Parameters
1260+
----------
1261+
point : dict, optional
1262+
Dict of variable values on which random values are to be
1263+
conditioned (uses default point if not specified).
1264+
size : int, optional
1265+
Desired size of random sample (returns one sample if not
1266+
specified).
1267+
1268+
Returns
1269+
-------
1270+
array
1271+
"""
10641272
mu, alpha, psi = draw_values(
10651273
[self.mu, self.alpha, self.psi], point=point, size=size)
10661274
g = generate_samples(stats.gamma.rvs, alpha, scale=mu / alpha,

0 commit comments

Comments
 (0)