Skip to content

Commit 7ba1d0f

Browse files
committed
Add test of ZSN variance
1 parent c204131 commit 7ba1d0f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pymc/tests/distributions/test_multivariate.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,23 @@ def assert_zerosum_axes(self, random_samples, axes_to_check, check_zerosum_axes=
15011501
random_samples.mean(axis=ax), 0
15021502
).all(), f"{ax} is not a zerosum_axis, but is nonetheless summing to 0 across all samples."
15031503

1504+
@pytest.mark.parametrize(
1505+
"sigma, n",
1506+
[
1507+
(5, 3),
1508+
(2, 6),
1509+
],
1510+
)
1511+
def test_zsn_variance(self, sigma, n):
1512+
1513+
dist = pm.ZeroSumNormal.dist(sigma=sigma, shape=n)
1514+
random_samples = pm.draw(dist, draws=100_000)
1515+
1516+
empirical_var = random_samples.var(axis=0)
1517+
theoretical_var = sigma**2 * (n - 1) / n
1518+
1519+
np.testing.assert_allclose(empirical_var, theoretical_var, rtol=1e-02)
1520+
15041521

15051522
class TestMvStudentTCov(BaseTestDistributionRandom):
15061523
def mvstudentt_rng_fn(self, size, nu, mu, cov, rng):

0 commit comments

Comments
 (0)