Skip to content

Commit 12fd699

Browse files
domenzaintwiecki
authored andcommitted
Implement log CDF for Logistic distribution
1 parent 78e5e69 commit 12fd699

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

pymc3/distributions/continuous.py

+24
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,30 @@ def _repr_latex_(self, name=None, dist=None):
36303630
get_variable_name(mu),
36313631
get_variable_name(s))
36323632

3633+
def logcdf(self, value):
3634+
"""
3635+
Compute the log CDF for the Logistic distribution
3636+
3637+
References
3638+
----------
3639+
.. [Machler2012] Martin Mächler (2012).
3640+
"Accurately computing log(1-exp(-|a|)) Assessed by the Rmpfr
3641+
package"
3642+
"""
3643+
mu = self.mu
3644+
s = self.s
3645+
a = -(value - mu)/s
3646+
return - tt.switch(
3647+
tt.le(a, -37),
3648+
tt.exp(a),
3649+
tt.switch(
3650+
tt.le(a, 18),
3651+
tt.log1p(tt.exp(a)),
3652+
tt.switch(
3653+
tt.le(a, 33.3),
3654+
tt.exp(-a) + a,
3655+
a)))
3656+
36333657

36343658
class LogitNormal(UnitContinuous):
36353659
R"""

pymc3/tests/test_distributions.py

+3
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,9 @@ def test_logistic(self):
11341134
self.pymc3_matches_scipy(Logistic, R, {'mu': R, 's': Rplus},
11351135
lambda value, mu, s: sp.logistic.logpdf(value, mu, s),
11361136
decimal=select_by_precision(float64=6, float32=1))
1137+
self.check_logcdf(Logistic, R, {'mu': R, 's': Rplus},
1138+
lambda value, mu, s: sp.logistic.logcdf(value, mu, s),
1139+
decimal=select_by_precision(float64=6, float32=1))
11371140

11381141
def test_logitnormal(self):
11391142
self.pymc3_matches_scipy(LogitNormal, Unit, {'mu': R, 'sd': Rplus},

0 commit comments

Comments
 (0)