Skip to content

Commit df15a62

Browse files
author
Junpeng Lao
authored
bug fixed #2430 (#2432)
* bug fixed #2430 Multinomial random fix for p.shape[0] > 1 * further fix better condition checking for p
1 parent f9d9fa8 commit df15a62

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pymc3/distributions/multivariate.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,16 @@ def __init__(self, n, p, *args, **kwargs):
505505
def _random(self, n, p, size=None):
506506
if size == p.shape:
507507
size = None
508-
return np.random.multinomial(n, p, size=size)
508+
509+
if p.ndim == 1:
510+
randnum = np.random.multinomial(n, p.squeeze(), size=size)
511+
elif p.ndim == 2:
512+
randnum = np.asarray([np.random.multinomial(n, pp, size=size) for pp in p])
513+
else:
514+
raise ValueError('Outcome probabilities must be 1- or 2-dimensional '
515+
'(supplied `p` has {} dimensions)'.format(p.ndim))
516+
517+
return randnum
509518

510519
def random(self, point=None, size=None):
511520
n, p = draw_values([self.n, self.p], point=point)

0 commit comments

Comments
 (0)