diff --git a/pymc/distributions/discrete.py b/pymc/distributions/discrete.py index f5ba04c2acf..73c26b8fd08 100644 --- a/pymc/distributions/discrete.py +++ b/pymc/distributions/discrete.py @@ -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):