Skip to content

Commit 185b609

Browse files
consolidate regression test into existing one
+ test_issue_4186 was merged into TestStrAndLatexRepr and now all 4 formatting options are covered.
1 parent 5601822 commit 185b609

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

pymc3/tests/test_distributions.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,12 @@ def setup_class(self):
17761776
# Test Cholesky parameterization
17771777
Z = MvNormal("Z", mu=np.zeros(2), chol=np.eye(2), shape=(2,))
17781778

1779+
# NegativeBinomial representations to test issue 4186
1780+
nb1 = pm.NegativeBinomial(
1781+
"nb_with_mu_alpha", mu=pm.Normal("nbmu"), alpha=pm.Gamma("nbalpha", mu=6, sigma=1)
1782+
)
1783+
nb2 = pm.NegativeBinomial("nb_with_p_n", p=pm.Uniform("nbp"), n=10)
1784+
17791785
# Expected value of outcome
17801786
mu = Deterministic("mu", floatX(alpha + tt.dot(X, b)))
17811787

@@ -1799,14 +1805,16 @@ def setup_class(self):
17991805
# Likelihood (sampling distribution) of observations
18001806
Y_obs = Normal("Y_obs", mu=mu, sigma=sigma, observed=Y)
18011807

1802-
self.distributions = [alpha, sigma, mu, b, Z, Y_obs, bound_var]
1808+
self.distributions = [alpha, sigma, mu, b, Z, nb1, nb2, Y_obs, bound_var]
18031809
self.expected = {
18041810
"latex": (
18051811
r"$\text{alpha} \sim \text{Normal}$",
18061812
r"$\text{sigma} \sim \text{HalfNormal}$",
18071813
r"$\text{mu} \sim \text{Deterministic}$",
18081814
r"$\text{beta} \sim \text{Normal}$",
18091815
r"$\text{Z} \sim \text{MvNormal}$",
1816+
r"$\text{nb_with_mu_alpha} \sim \text{NegativeBinomial}$",
1817+
r"$\text{nb_with_p_n} \sim \text{NegativeBinomial}$",
18101818
r"$\text{Y_obs} \sim \text{Normal}$",
18111819
r"$\text{bound_var} \sim \text{Bound}$ -- \text{Normal}$",
18121820
r"$\text{kron_normal} \sim \text{KroneckerNormal}$",
@@ -1818,6 +1826,8 @@ def setup_class(self):
18181826
r"mu ~ Deterministic",
18191827
r"beta ~ Normal",
18201828
r"Z ~ MvNormal",
1829+
r"nb_with_mu_alpha ~ NegativeBinomial",
1830+
r"nb_with_p_n ~ NegativeBinomial",
18211831
r"Y_obs ~ Normal",
18221832
r"bound_var ~ Bound-Normal",
18231833
r"kron_normal ~ KroneckerNormal",
@@ -1829,6 +1839,8 @@ def setup_class(self):
18291839
r"$\text{mu} \sim \text{Deterministic}(\text{alpha},~\text{Constant},~\text{beta})$",
18301840
r"$\text{beta} \sim \text{Normal}(\mathit{mu}=0.0,~\mathit{sigma}=10.0)$",
18311841
r"$\text{Z} \sim \text{MvNormal}(\mathit{mu}=array,~\mathit{chol_cov}=array)$",
1842+
r"$\text{nb_with_mu_alpha} \sim \text{NegativeBinomial}(\mathit{mu}=\text{nbmu},~\mathit{alpha}=\text{nbalpha})$",
1843+
r"$\text{nb_with_p_n} \sim \text{NegativeBinomial}(\mathit{p}=\text{nbp},~\mathit{n}=10)$",
18321844
r"$\text{Y_obs} \sim \text{Normal}(\mathit{mu}=\text{mu},~\mathit{sigma}=f(\text{sigma}))$",
18331845
r"$\text{bound_var} \sim \text{Bound}(\mathit{lower}=1.0,~\mathit{upper}=\text{None})$ -- \text{Normal}(\mathit{mu}=0.0,~\mathit{sigma}=10.0)$",
18341846
r"$\text{kron_normal} \sim \text{KroneckerNormal}(\mathit{mu}=array)$",
@@ -1840,6 +1852,8 @@ def setup_class(self):
18401852
r"mu ~ Deterministic(alpha, Constant, beta)",
18411853
r"beta ~ Normal(mu=0.0, sigma=10.0)",
18421854
r"Z ~ MvNormal(mu=array, chol_cov=array)",
1855+
r"nb_with_mu_alpha ~ NegativeBinomial(mu=nbmu, alpha=nbalpha)",
1856+
r"nb_with_p_n ~ NegativeBinomial(p=nbp, n=10)",
18431857
r"Y_obs ~ Normal(mu=mu, sigma=f(sigma))",
18441858
r"bound_var ~ Bound(lower=1.0, upper=None)-Normal(mu=0.0, sigma=10.0)",
18451859
r"kron_normal ~ KroneckerNormal(mu=array)",
@@ -1929,17 +1943,6 @@ def test_issue_3051(self, dims, dist_cls, kwargs):
19291943
assert actual_a.shape == (X.shape[0],)
19301944
pass
19311945

1932-
def test_issue_4186(self):
1933-
with pm.Model():
1934-
nb = pm.NegativeBinomial(
1935-
"nb", mu=pm.Normal("mu"), alpha=pm.Gamma("alpha", mu=6, sigma=1)
1936-
)
1937-
assert str(nb) == "nb ~ NegativeBinomial(mu=mu, alpha=alpha)"
1938-
1939-
with pm.Model():
1940-
nb = pm.NegativeBinomial("nb", p=pm.Uniform("p"), n=10)
1941-
assert str(nb) == "nb ~ NegativeBinomial(p=p, n=10)"
1942-
19431946

19441947
def test_serialize_density_dist():
19451948
def func(x):

0 commit comments

Comments
 (0)