Skip to content

Commit cbff818

Browse files
committed
Add HalfCauchy moment
1 parent fe369a3 commit cbff818

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pymc/distributions/continuous.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,12 @@ def dist(cls, beta, *args, **kwargs):
21062106
assert_negative_support(beta, "beta", "HalfCauchy")
21072107
return super().dist([0.0, beta], **kwargs)
21082108

2109+
def get_moment(rv, size, loc, beta):
2110+
mean = beta
2111+
if not rv_size_is_none(size):
2112+
mean = at.full(size, mean)
2113+
return mean
2114+
21092115
def logcdf(value, loc, beta):
21102116
"""
21112117
Compute the log of the cumulative distribution function for HalfCauchy distribution

pymc/tests/test_distributions_moments.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Beta,
77
Cauchy,
88
Exponential,
9+
HalfCauchy,
910
HalfNormal,
1011
Kumaraswamy,
1112
Laplace,
@@ -262,3 +263,22 @@ def test_lognormal_moment(mu, sigma, size, expected):
262263
with Model() as model:
263264
LogNormal("x", mu=mu, sigma=sigma, size=size)
264265
assert_moment_is_expected(model, expected)
266+
267+
268+
@pytest.mark.parametrize(
269+
"beta, size, expected",
270+
[
271+
(1, None, 1),
272+
(1, 5, np.ones(5)),
273+
(np.arange(5), None, np.arange(5)),
274+
(
275+
np.arange(5),
276+
(2, 5),
277+
np.full((2, 5), np.arange(5)),
278+
),
279+
],
280+
)
281+
def test_halfcauchy_moment(beta, size, expected):
282+
with Model() as model:
283+
HalfCauchy("x", beta=beta, size=size)
284+
assert_moment_is_expected(model, expected)

0 commit comments

Comments
 (0)