Skip to content

Commit 68bb77a

Browse files
committed
Rename ZeroInflatedPoisson theta parameter to mu
For consistency with the base Poisson distribution
1 parent d55ca39 commit 68bb77a

File tree

5 files changed

+29
-28
lines changed

5 files changed

+29
-28
lines changed

Diff for: RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ All of the above apply to:
7474
- The function `replace_with_values` function has been added to `gp.utils`.
7575
- `MarginalSparse` has been renamed `MarginalApprox`.
7676
- Removed `MixtureSameFamily`. `Mixture` is now capable of handling batched multivariate components (see [#5438](https://github.com/pymc-devs/pymc/pull/5438)).
77+
- `ZeroInflatedPoisson` `theta` parameter was renamed to `mu` (see [#5584](https://github.com/pymc-devs/pymc/pull/5584)).
7778
- ...
7879

7980
### Expected breaks

Diff for: pymc/distributions/discrete.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1414,8 +1414,8 @@ class ZeroInflatedPoisson:
14141414
14151415
.. math::
14161416
1417-
f(x \mid \psi, \theta) = \left\{ \begin{array}{l}
1418-
(1-\psi) + \psi e^{-\theta}, \text{if } x = 0 \\
1417+
f(x \mid \psi, \mu) = \left\{ \begin{array}{l}
1418+
(1-\psi) + \psi e^{-\mu}, \text{if } x = 0 \\
14191419
\psi \frac{e^{-\theta}\theta^x}{x!}, \text{if } x=1,2,3,\ldots
14201420
\end{array} \right.
14211421
@@ -1428,42 +1428,42 @@ class ZeroInflatedPoisson:
14281428
plt.style.use('arviz-darkgrid')
14291429
x = np.arange(0, 22)
14301430
psis = [0.7, 0.4]
1431-
thetas = [8, 4]
1432-
for psi, theta in zip(psis, thetas):
1433-
pmf = st.poisson.pmf(x, theta)
1431+
mus = [8, 4]
1432+
for psi, mu in zip(psis, mus):
1433+
pmf = st.poisson.pmf(x, mu)
14341434
pmf[0] = (1 - psi) + pmf[0]
14351435
pmf[1:] = psi * pmf[1:]
14361436
pmf /= pmf.sum()
1437-
plt.plot(x, pmf, '-o', label='$\\psi$ = {}, $\\theta$ = {}'.format(psi, theta))
1437+
plt.plot(x, pmf, '-o', label='$\\psi$ = {}, $\\mu$ = {}'.format(psi, mu))
14381438
plt.xlabel('x', fontsize=12)
14391439
plt.ylabel('f(x)', fontsize=12)
14401440
plt.legend(loc=1)
14411441
plt.show()
14421442
14431443
======== ==========================
14441444
Support :math:`x \in \mathbb{N}_0`
1445-
Mean :math:`\psi\theta`
1446-
Variance :math:`\theta + \frac{1-\psi}{\psi}\theta^2`
1445+
Mean :math:`\psi\mu`
1446+
Variance :math:`\mu + \frac{1-\psi}{\psi}\mu^2`
14471447
======== ==========================
14481448
14491449
Parameters
14501450
----------
14511451
psi: float
14521452
Expected proportion of Poisson variates (0 < psi < 1)
1453-
theta: float
1453+
mu: float
14541454
Expected number of occurrences during the given interval
1455-
(theta >= 0).
1455+
(mu >= 0).
14561456
"""
14571457

1458-
def __new__(cls, name, psi, theta, **kwargs):
1458+
def __new__(cls, name, psi, mu, **kwargs):
14591459
return _zero_inflated_mixture(
1460-
name=name, nonzero_p=psi, nonzero_dist=Poisson.dist(mu=theta), **kwargs
1460+
name=name, nonzero_p=psi, nonzero_dist=Poisson.dist(mu=mu), **kwargs
14611461
)
14621462

14631463
@classmethod
1464-
def dist(cls, psi, theta, **kwargs):
1464+
def dist(cls, psi, mu, **kwargs):
14651465
return _zero_inflated_mixture(
1466-
name=None, nonzero_p=psi, nonzero_dist=Poisson.dist(mu=theta), **kwargs
1466+
name=None, nonzero_p=psi, nonzero_dist=Poisson.dist(mu=mu), **kwargs
14671467
)
14681468

14691469

Diff for: pymc/tests/test_distributions.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1747,33 +1747,33 @@ def test_constantdist(self):
17471747
self.check_logcdf(Constant, I, {"c": I}, lambda value, c: np.log(value >= c))
17481748

17491749
def test_zeroinflatedpoisson(self):
1750-
def logp_fn(value, psi, theta):
1750+
def logp_fn(value, psi, mu):
17511751
if value == 0:
1752-
return np.log((1 - psi) * sp.poisson.pmf(0, theta))
1752+
return np.log((1 - psi) * sp.poisson.pmf(0, mu))
17531753
else:
1754-
return np.log(psi * sp.poisson.pmf(value, theta))
1754+
return np.log(psi * sp.poisson.pmf(value, mu))
17551755

1756-
def logcdf_fn(value, psi, theta):
1757-
return np.log((1 - psi) + psi * sp.poisson.cdf(value, theta))
1756+
def logcdf_fn(value, psi, mu):
1757+
return np.log((1 - psi) + psi * sp.poisson.cdf(value, mu))
17581758

17591759
self.check_logp(
17601760
ZeroInflatedPoisson,
17611761
Nat,
1762-
{"psi": Unit, "theta": Rplus},
1762+
{"psi": Unit, "mu": Rplus},
17631763
logp_fn,
17641764
)
17651765

17661766
self.check_logcdf(
17671767
ZeroInflatedPoisson,
17681768
Nat,
1769-
{"psi": Unit, "theta": Rplus},
1769+
{"psi": Unit, "mu": Rplus},
17701770
logcdf_fn,
17711771
)
17721772

17731773
self.check_selfconsistency_discrete_logcdf(
17741774
ZeroInflatedPoisson,
17751775
Nat,
1776-
{"theta": Rplus, "psi": Unit},
1776+
{"mu": Rplus, "psi": Unit},
17771777
)
17781778

17791779
def test_zeroinflatednegativebinomial(self):

Diff for: pymc/tests/test_distributions_moments.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -624,17 +624,17 @@ def test_constant_moment(c, size, expected):
624624

625625

626626
@pytest.mark.parametrize(
627-
"psi, theta, size, expected",
627+
"psi, mu, size, expected",
628628
[
629629
(0.9, 3.0, None, 3),
630630
(0.8, 2.9, 5, np.full(5, 2)),
631631
(0.2, np.arange(1, 5) * 5, None, np.arange(1, 5)),
632632
(0.2, np.arange(1, 5) * 5, (2, 4), np.full((2, 4), np.arange(1, 5))),
633633
],
634634
)
635-
def test_zero_inflated_poisson_moment(psi, theta, size, expected):
635+
def test_zero_inflated_poisson_moment(psi, mu, size, expected):
636636
with Model() as model:
637-
ZeroInflatedPoisson("x", psi=psi, theta=theta, size=size)
637+
ZeroInflatedPoisson("x", psi=psi, mu=mu, size=size)
638638
assert_moment_is_expected(model, expected)
639639

640640

Diff for: pymc/tests/test_sampling.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1128,11 +1128,11 @@ def test_shape_edgecase(self):
11281128

11291129
def test_zeroinflatedpoisson(self):
11301130
with pm.Model():
1131-
theta = pm.Beta("theta", alpha=1, beta=1)
1131+
mu = pm.Beta("mu", alpha=1, beta=1)
11321132
psi = pm.HalfNormal("psi", sd=1)
1133-
pm.ZeroInflatedPoisson("suppliers", psi=psi, theta=theta, size=20)
1133+
pm.ZeroInflatedPoisson("suppliers", psi=psi, mu=mu, size=20)
11341134
gen_data = pm.sample_prior_predictive(samples=5000)
1135-
assert gen_data.prior["theta"].shape == (1, 5000)
1135+
assert gen_data.prior["mu"].shape == (1, 5000)
11361136
assert gen_data.prior["psi"].shape == (1, 5000)
11371137
assert gen_data.prior["suppliers"].shape == (1, 5000, 20)
11381138

0 commit comments

Comments
 (0)