@@ -1776,6 +1776,12 @@ def setup_class(self):
1776
1776
# Test Cholesky parameterization
1777
1777
Z = MvNormal ("Z" , mu = np .zeros (2 ), chol = np .eye (2 ), shape = (2 ,))
1778
1778
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
+
1779
1785
# Expected value of outcome
1780
1786
mu = Deterministic ("mu" , floatX (alpha + tt .dot (X , b )))
1781
1787
@@ -1799,14 +1805,16 @@ def setup_class(self):
1799
1805
# Likelihood (sampling distribution) of observations
1800
1806
Y_obs = Normal ("Y_obs" , mu = mu , sigma = sigma , observed = Y )
1801
1807
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 ]
1803
1809
self .expected = {
1804
1810
"latex" : (
1805
1811
r"$\text{alpha} \sim \text{Normal}$" ,
1806
1812
r"$\text{sigma} \sim \text{HalfNormal}$" ,
1807
1813
r"$\text{mu} \sim \text{Deterministic}$" ,
1808
1814
r"$\text{beta} \sim \text{Normal}$" ,
1809
1815
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}$" ,
1810
1818
r"$\text{Y_obs} \sim \text{Normal}$" ,
1811
1819
r"$\text{bound_var} \sim \text{Bound}$ -- \text{Normal}$" ,
1812
1820
r"$\text{kron_normal} \sim \text{KroneckerNormal}$" ,
@@ -1818,6 +1826,8 @@ def setup_class(self):
1818
1826
r"mu ~ Deterministic" ,
1819
1827
r"beta ~ Normal" ,
1820
1828
r"Z ~ MvNormal" ,
1829
+ r"nb_with_mu_alpha ~ NegativeBinomial" ,
1830
+ r"nb_with_p_n ~ NegativeBinomial" ,
1821
1831
r"Y_obs ~ Normal" ,
1822
1832
r"bound_var ~ Bound-Normal" ,
1823
1833
r"kron_normal ~ KroneckerNormal" ,
@@ -1829,6 +1839,8 @@ def setup_class(self):
1829
1839
r"$\text{mu} \sim \text{Deterministic}(\text{alpha},~\text{Constant},~\text{beta})$" ,
1830
1840
r"$\text{beta} \sim \text{Normal}(\mathit{mu}=0.0,~\mathit{sigma}=10.0)$" ,
1831
1841
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)$" ,
1832
1844
r"$\text{Y_obs} \sim \text{Normal}(\mathit{mu}=\text{mu},~\mathit{sigma}=f(\text{sigma}))$" ,
1833
1845
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)$" ,
1834
1846
r"$\text{kron_normal} \sim \text{KroneckerNormal}(\mathit{mu}=array)$" ,
@@ -1840,6 +1852,8 @@ def setup_class(self):
1840
1852
r"mu ~ Deterministic(alpha, Constant, beta)" ,
1841
1853
r"beta ~ Normal(mu=0.0, sigma=10.0)" ,
1842
1854
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)" ,
1843
1857
r"Y_obs ~ Normal(mu=mu, sigma=f(sigma))" ,
1844
1858
r"bound_var ~ Bound(lower=1.0, upper=None)-Normal(mu=0.0, sigma=10.0)" ,
1845
1859
r"kron_normal ~ KroneckerNormal(mu=array)" ,
@@ -1929,17 +1943,6 @@ def test_issue_3051(self, dims, dist_cls, kwargs):
1929
1943
assert actual_a .shape == (X .shape [0 ],)
1930
1944
pass
1931
1945
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
-
1943
1946
1944
1947
def test_serialize_density_dist ():
1945
1948
def func (x ):
0 commit comments