Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pymc/distributions/discrete.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ def dist(cls, alpha, beta, n, *args, **kwargs):
n = at.as_tensor_variable(intX(n))
return super().dist([n, alpha, beta], **kwargs)

def get_moment(rv, size, n, alpha, beta):
mean = at.round((n * alpha) / (alpha + beta))
if not rv_size_is_none(size):
mean = at.full(size, mean)
return mean

def logp(value, n, alpha, beta):
r"""
Calculate log-probability of BetaBinomial distribution at specified value.
Expand Down
16 changes: 16 additions & 0 deletions pymc/tests/test_distributions_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pymc.distributions import (
Bernoulli,
Beta,
BetaBinomial,
Binomial,
Cauchy,
ChiSquared,
Expand Down Expand Up @@ -209,6 +210,21 @@ def test_beta_moment(alpha, beta, size, expected):
assert_moment_is_expected(model, expected)


@pytest.mark.parametrize(
"n, alpha, beta, size, expected",
[
(10, 1, 1, None, 5),
(10, 1, 1, 5, np.full(5, 5)),
(10, 1, np.arange(1, 6), None, np.round(10 / np.arange(2, 7))),
(10, 1, np.arange(1, 6), (2, 5), np.full((2, 5), np.round(10 / np.arange(2, 7)))),
],
)
def test_beta_binomial_moment(alpha, beta, n, size, expected):
with Model() as model:
BetaBinomial("x", alpha=alpha, beta=beta, n=n, size=size)
assert_moment_is_expected(model, expected)


@pytest.mark.parametrize(
"nu, size, expected",
[
Expand Down