Skip to content

Commit bb42044

Browse files
committed
added laplace distribution
1 parent 23e2d59 commit bb42044

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

pymc/distributions/continuous.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from dist_math import *
1010

11-
__all__ = ['Uniform', 'Flat', 'Normal', 'Beta','Exponential', 'T', 'Cauchy', 'Gamma', 'Bound', 'Tpos']
11+
__all__ = ['Uniform', 'Flat', 'Normal', 'Beta','Exponential', 'Laplace', 'T', 'Cauchy', 'Gamma', 'Bound', 'Tpos']
1212

1313

1414
@tensordist(continuous)
@@ -175,10 +175,33 @@ def Exponential(lam):
175175
variance = lam**-2
176176

177177
def logp(value):
178-
return log(lam) - lam*value
178+
return bound(log(lam) - lam*value,
179+
value > 0,
180+
lam > 0)
179181

180182
return locals()
181183

184+
@tensordist(continuous)
185+
def Laplace(mu, b):
186+
"""
187+
Laplace distribution
188+
189+
Parameters
190+
----------
191+
mu : float
192+
mean
193+
b : float
194+
scale
195+
"""
196+
197+
mean = median = mode = mu
198+
199+
variance = 2*b**2
200+
201+
def logp(value):
202+
return -log(2*b) - abs(value - mu)/b
203+
204+
return locals()
182205

183206
@tensordist(continuous)
184207
def T(nu, mu=0, lam=1):

0 commit comments

Comments
 (0)