Skip to content

Commit bdd4d19

Browse files
Add Logistic Moment (#5157)
Co-authored-by: Ricardo Vieira <28983449+ricardoV94@users.noreply.github.com>
1 parent 93c2293 commit bdd4d19

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pymc/distributions/continuous.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,6 +3388,12 @@ def dist(cls, mu=0.0, s=1.0, *args, **kwargs):
33883388
s = at.as_tensor_variable(floatX(s))
33893389
return super().dist([mu, s], *args, **kwargs)
33903390

3391+
def get_moment(rv, size, mu, s):
3392+
mu, _ = at.broadcast_arrays(mu, s)
3393+
if not rv_size_is_none(size):
3394+
mu = at.full(size, mu)
3395+
return mu
3396+
33913397
def logcdf(value, mu, s):
33923398
r"""
33933399
Compute the log of the cumulative distribution function for Logistic distribution

pymc/tests/test_distributions_moments.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
HalfStudentT,
1818
Kumaraswamy,
1919
Laplace,
20+
Logistic,
2021
LogNormal,
2122
Poisson,
2223
StudentT,
@@ -413,3 +414,23 @@ def test_constant_moment(c, size, expected):
413414
with Model() as model:
414415
Constant("x", c=c, size=size)
415416
assert_moment_is_expected(model, expected)
417+
418+
419+
@pytest.mark.parametrize(
420+
"mu, s, size, expected",
421+
[
422+
(1, 1, None, 1),
423+
(1, 1, 5, np.full(5, 1)),
424+
(2, np.arange(1, 6), None, np.full(5, 2)),
425+
(
426+
np.arange(1, 6),
427+
np.arange(1, 6),
428+
(2, 5),
429+
np.full((2, 5), np.arange(1, 6)),
430+
),
431+
],
432+
)
433+
def test_logistic_moment(mu, s, size, expected):
434+
with Model() as model:
435+
Logistic("x", mu=mu, s=s, size=size)
436+
assert_moment_is_expected(model, expected)

0 commit comments

Comments
 (0)