Skip to content

Commit 3a08b9a

Browse files
Kumaraswamy
1 parent 4ca4bf5 commit 3a08b9a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pymc/distributions/continuous.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,12 @@ def dist(cls, a, b, *args, **kwargs):
13131313

13141314
return super().dist([a, b], *args, **kwargs)
13151315

1316+
def get_moment(rv, size, a, b):
1317+
mean = at.exp(at.log(b) + at.gammaln(1 + 1 / a) + at.gammaln(b) - at.gammaln(1 + 1 / a + b))
1318+
if not rv_size_is_none(size):
1319+
mean = at.full(size, mean)
1320+
return mean
1321+
13161322
def logp(value, a, b):
13171323
"""
13181324
Calculate log-probability of Kumaraswamy distribution at specified value.

pymc/tests/test_distributions_moments.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22
import pytest
33

44
from pymc import Bernoulli, Flat, HalfFlat, Normal, TruncatedNormal, Uniform
5-
from pymc.distributions import Beta, Cauchy, Exponential, HalfNormal, Laplace, StudentT
5+
from pymc.distributions import (
6+
Beta,
7+
Cauchy,
8+
Exponential,
9+
HalfNormal,
10+
Kumaraswamy,
11+
Laplace,
12+
StudentT,
13+
)
614
from pymc.distributions.shape_utils import rv_size_is_none
715
from pymc.initial_point import make_initial_point_fn
816
from pymc.model import Model
@@ -217,3 +225,19 @@ def test_cauchy_moment(alpha, beta, size, expected):
217225
with Model() as model:
218226
Cauchy("x", alpha=alpha, beta=beta, size=size)
219227
assert_moment_is_expected(model, expected)
228+
229+
230+
@pytest.mark.parametrize(
231+
"a, b, size, expected",
232+
[
233+
(1, 1, None, 0.5),
234+
(1, 1, 5, np.full(5, 0.5)),
235+
(1, np.arange(1, 6), None, 1 / np.arange(2, 7)),
236+
(np.arange(1, 6), 1, None, np.arange(1, 6) / np.arange(2, 7)),
237+
(1, np.arange(1, 6), (2, 5), np.full((2, 5), 1 / np.arange(2, 7))),
238+
],
239+
)
240+
def test_kumaraswamy_moment(a, b, size, expected):
241+
with Model() as model:
242+
Kumaraswamy("x", a=a, b=b, size=size)
243+
assert_moment_is_expected(model, expected)

0 commit comments

Comments
 (0)