Skip to content

Commit 38f2632

Browse files
jlopezarriazajuan.lopez.arriaza
and
juan.lopez.arriaza
authored
Adding moment for Moyal distribution and corresponding tests (#5179)
Co-authored-by: juan.lopez.arriaza <[email protected]>
1 parent 140dab0 commit 38f2632

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

pymc/distributions/continuous.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,6 +3745,13 @@ def dist(cls, mu=0, sigma=1.0, *args, **kwargs):
37453745

37463746
return super().dist([mu, sigma], *args, **kwargs)
37473747

3748+
def get_moment(rv, size, mu, sigma):
3749+
mean = mu + sigma * (np.euler_gamma + at.log(2))
3750+
3751+
if not rv_size_is_none(size):
3752+
mean = at.full(size, mean)
3753+
return mean
3754+
37483755
def logp(value, mu, sigma):
37493756
"""
37503757
Calculate log-probability of Moyal distribution at specified value.

pymc/tests/test_distributions_moments.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Logistic,
3131
LogitNormal,
3232
LogNormal,
33+
Moyal,
3334
NegativeBinomial,
3435
Normal,
3536
Pareto,
@@ -748,3 +749,18 @@ def test_categorical_moment(p, size, expected):
748749
with Model() as model:
749750
Categorical("x", p=p, size=size)
750751
assert_moment_is_expected(model, expected)
752+
753+
754+
@pytest.mark.parametrize(
755+
"mu, sigma, size, expected",
756+
[
757+
(4.0, 3.0, None, 7.8110885363844345),
758+
(4, np.full(5, 3), None, np.full(5, 7.8110885363844345)),
759+
(np.arange(5), 1, None, np.arange(5) + 1.2703628454614782),
760+
(np.arange(5), np.ones(5), (2, 5), np.full((2, 5), np.arange(5) + 1.2703628454614782)),
761+
],
762+
)
763+
def test_moyal_moment(mu, sigma, size, expected):
764+
with Model() as model:
765+
Moyal("x", mu=mu, sigma=sigma, size=size)
766+
assert_moment_is_expected(model, expected)

0 commit comments

Comments
 (0)