Skip to content

Commit 036b4bb

Browse files
jessegrabowskiricardoV94
authored andcommitted
Avoid deprecated pymc.math.log1mexp_numpy
1 parent 5d1b1df commit 036b4bb

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pymc_experimental/distributions/discrete.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@
2020
from pytensor.tensor.random.op import RandomVariable
2121

2222

23+
def log1mexp(x):
24+
cond = x < np.log(0.5)
25+
return np.piecewise(
26+
x,
27+
[cond, ~cond],
28+
[lambda x: np.log1p(-np.exp(x)), lambda x: np.log(-np.expm1(x))],
29+
)
30+
31+
2332
class GeneralizedPoissonRV(RandomVariable):
2433
name = "generalized_poisson"
2534
ndim_supp = 0
@@ -74,7 +83,7 @@ def _inverse_rng_fn(cls, rng, theta, lam, dist_size, idxs_mask):
7483
log1p_lam_m_C = np.where(
7584
pos_lam,
7685
np.log1p(np.exp(abs_log_lam - log_c)),
77-
pm.math.log1mexp_numpy(abs_log_lam - log_c, negative_input=True),
86+
log1mexp(abs_log_lam - log_c),
7887
)
7988
log_p = log_c + log1p_lam_m_C * (x_ - 1) + log_p - np.log(x_) - lam
8089
log_s = np.logaddexp(log_s, log_p)

0 commit comments

Comments
 (0)