From c963acf6c5d243fae98dee3fd98215e69a8c8024 Mon Sep 17 00:00:00 2001 From: Domenico Pellegrino Date: Wed, 1 Dec 2021 00:03:53 +0000 Subject: [PATCH 1/3] Added moment to vonmises distribution --- pymc/distributions/continuous.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pymc/distributions/continuous.py b/pymc/distributions/continuous.py index 97ad4035e1..50f3f1f368 100644 --- a/pymc/distributions/continuous.py +++ b/pymc/distributions/continuous.py @@ -2924,6 +2924,12 @@ def dist(cls, mu=0.0, kappa=None, *args, **kwargs): assert_negative_support(kappa, "kappa", "VonMises") return super().dist([mu, kappa], *args, **kwargs) + def get_moment(rv, size, mu, kappa): + mu, _ = at.broadcast_arrays(mu, kappa) + if not rv_size_is_none(size): + mu = at.full(size, mu) + return mu + class SkewNormalRV(RandomVariable): name = "skewnormal" From dadd81a399884c7f846506debd578499c91f5834 Mon Sep 17 00:00:00 2001 From: Domenico Pellegrino Date: Wed, 1 Dec 2021 00:04:16 +0000 Subject: [PATCH 2/3] Added test --- pymc/tests/test_distributions_moments.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pymc/tests/test_distributions_moments.py b/pymc/tests/test_distributions_moments.py index ad6e234305..e6d860baed 100644 --- a/pymc/tests/test_distributions_moments.py +++ b/pymc/tests/test_distributions_moments.py @@ -54,6 +54,7 @@ Triangular, TruncatedNormal, Uniform, + VonMises, Wald, Weibull, ZeroInflatedBinomial, @@ -437,6 +438,20 @@ def test_pareto_moment(alpha, m, size, expected): Pareto("x", alpha=alpha, m=m, size=size) assert_moment_is_expected(model, expected) +@pytest.mark.parametrize( + "mu, kappa, size, expected", + [ + (0, 1, None, 0), + (0, np.ones(4), None, np.zeros(4)), + (np.arange(4), 0.5, None, np.arange(4)), + (np.arange(4), np.arange(1, 5), (2, 4), np.full((2, 4), np.arange(4))), + ], +) +def test_vonmises_moment(mu, kappa, size, expected): + with Model() as model: + VonMises("x", mu=mu, kappa=kappa, size=size) + assert_moment_is_expected(model, expected) + @pytest.mark.parametrize( "mu, lam, phi, size, expected", From 1d337ca57d0fa348e67b73c05e7c678220c31612 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 1 Dec 2021 10:19:44 +0000 Subject: [PATCH 3/3] Run pre-commit --- pymc/tests/test_distributions_moments.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pymc/tests/test_distributions_moments.py b/pymc/tests/test_distributions_moments.py index e6d860baed..b5d1b0cfd9 100644 --- a/pymc/tests/test_distributions_moments.py +++ b/pymc/tests/test_distributions_moments.py @@ -438,6 +438,7 @@ def test_pareto_moment(alpha, m, size, expected): Pareto("x", alpha=alpha, m=m, size=size) assert_moment_is_expected(model, expected) + @pytest.mark.parametrize( "mu, kappa, size, expected", [