Skip to content

Commit

Permalink
Simplify the logp expression
Browse files Browse the repository at this point in the history
Co-authored-by: Ricardo Vieira <28983449+ricardoV94@users.noreply.github.com>
  • Loading branch information
2 people authored and mjhajharia committed Jan 3, 2022
1 parent 39a608c commit 76a06d8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pymc/distributions/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,24 @@ def logp(value, theta, lam):
-------
TensorVariable
"""
log_prob = bound(np.log(theta) + logpow(theta + lam * value, value - 1)
- (theta + lam * value) - factln(value),
theta > 0,
-1 <= lam, -theta/4 <= lam, lam <= 1,
value >= 0)
theta_lam_value = theta + lam * value
log_prob = (
np.log(theta)
+ logpow(theta_lam_value, value - 1)
- theta_lam_value - factln(value)
)

# Probability is 0 when value > m, where m is the largest positive integer for which
# theta + m * lam > 0 (when lam < 0).
return at.switch(theta + value * lam <= 0, -np.inf, log_prob)
log_prob = at.switch(theta_lam_value <= 0, -np.inf, log_prob)

return bound(
log_prob,
value >= 0,
theta > 0,
abs(lam) <= 1,
-theta/4 <= lam,
)


class NegativeBinomial(Discrete):
Expand Down

0 comments on commit 76a06d8

Please sign in to comment.