Skip to content

Commit

Permalink
Add Logistic Moment (#5157)
Browse files Browse the repository at this point in the history
Co-authored-by: Ricardo Vieira <28983449+ricardoV94@users.noreply.github.com>
  • Loading branch information
shivam15s and ricardoV94 authored Nov 8, 2021
1 parent 93c2293 commit bdd4d19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pymc/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -3388,6 +3388,12 @@ def dist(cls, mu=0.0, s=1.0, *args, **kwargs):
s = at.as_tensor_variable(floatX(s))
return super().dist([mu, s], *args, **kwargs)

def get_moment(rv, size, mu, s):
mu, _ = at.broadcast_arrays(mu, s)
if not rv_size_is_none(size):
mu = at.full(size, mu)
return mu

def logcdf(value, mu, s):
r"""
Compute the log of the cumulative distribution function for Logistic distribution
Expand Down
21 changes: 21 additions & 0 deletions pymc/tests/test_distributions_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
HalfStudentT,
Kumaraswamy,
Laplace,
Logistic,
LogNormal,
Poisson,
StudentT,
Expand Down Expand Up @@ -413,3 +414,23 @@ def test_constant_moment(c, size, expected):
with Model() as model:
Constant("x", c=c, size=size)
assert_moment_is_expected(model, expected)


@pytest.mark.parametrize(
"mu, s, size, expected",
[
(1, 1, None, 1),
(1, 1, 5, np.full(5, 1)),
(2, np.arange(1, 6), None, np.full(5, 2)),
(
np.arange(1, 6),
np.arange(1, 6),
(2, 5),
np.full((2, 5), np.arange(1, 6)),
),
],
)
def test_logistic_moment(mu, s, size, expected):
with Model() as model:
Logistic("x", mu=mu, s=s, size=size)
assert_moment_is_expected(model, expected)

0 comments on commit bdd4d19

Please sign in to comment.