Skip to content

Commit a9f1b02

Browse files
committed
Implement log CDF for Laplace distribution
1 parent dc8cf20 commit a9f1b02

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

pymc3/distributions/continuous.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,20 @@ def logp(self, value):
612612

613613
return -tt.log(2 * b) - abs(value - mu) / b
614614

615+
def logcdf(self, value):
616+
a = self.mu
617+
b = self.b
618+
y = (value - a) / b
619+
return tt.switch(
620+
tt.le(value, a),
621+
tt.log(0.5) + y,
622+
tt.switch(
623+
tt.gt(y, 1),
624+
tt.log1p(-0.5 * tt.exp(-y)),
625+
tt.log(1 - 0.5 * tt.exp(-y))
626+
)
627+
)
628+
615629

616630
class Lognormal(PositiveContinuous):
617631
R"""

pymc3/tests/test_distributions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,8 @@ def test_fun(value, mu, alpha):
456456
def test_laplace(self):
457457
self.pymc3_matches_scipy(Laplace, R, {'mu': R, 'b': Rplus},
458458
lambda value, mu, b: sp.laplace.logpdf(value, mu, b))
459+
self.check_logcdf(Laplace, R, {'mu': R, 'b': Rplus},
460+
lambda value, mu, b: sp.laplace.logcdf(value, mu, b))
459461

460462
def test_lognormal(self):
461463
self.pymc3_matches_scipy(

0 commit comments

Comments
 (0)