Skip to content

Commit 625435e

Browse files
katoshJunpeng Lao
authored andcommitted
fix logpow for case x = m = 0 (#3059)
* fix logpow for case x = m = 0 * update doc for Dirichlet * corrected typo in Dirichlet doc
1 parent d1a1328 commit 625435e

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

pymc3/distributions/dist_math.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def logpow(x, m):
6565
Calculates log(x**m) since m*log(x) will fail when m, x = 0.
6666
"""
6767
# return m * log(x)
68-
return tt.switch(tt.eq(x, 0) & ~tt.eq(m + x, 0), -np.inf, m * tt.log(x))
68+
return tt.switch(tt.eq(x, 0), tt.switch(tt.eq(m, 0), 0.0, -np.inf), m * tt.log(x))
6969

7070

7171
def factln(n):

pymc3/distributions/multivariate.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,9 @@ class Dirichlet(Continuous):
383383
384384
.. math::
385385
386-
f(\mathbf{x}) =
387-
\frac{\Gamma(\sum_{i=1}^k \theta_i)}{\prod \Gamma(\theta_i)}
388-
\prod_{i=1}^{k-1} x_i^{\theta_i - 1}
389-
\left(1-\sum_{i=1}^{k-1}x_i\right)^\theta_k
386+
f(\mathbf{x}|\mathbf{a}) =
387+
\frac{\Gamma(\sum_{i=1}^k a_i)}{\prod_{i=1}^k \Gamma(a_i)}
388+
\prod_{i=1}^k x_i^{a_i - 1}
390389
391390
======== ===============================================
392391
Support :math:`x_i \in (0, 1)` for :math:`i \in \{1, \ldots, K\}`
@@ -400,11 +399,6 @@ class Dirichlet(Continuous):
400399
----------
401400
a : array
402401
Concentration parameters (a > 0).
403-
404-
Notes
405-
-----
406-
Only the first `k-1` elements of `x` are expected. Can be used
407-
as a parent of Multinomial and Categorical nevertheless.
408402
"""
409403

410404
def __init__(self, a, transform=transforms.stick_breaking,

0 commit comments

Comments
 (0)