Skip to content

Commit 3ee52c2

Browse files
committed
Replaced 0 by epsilon in ExGaussian logp for numerical stability
1 parent 63eba59 commit 3ee52c2

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pymc3/distributions/continuous.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3268,12 +3268,23 @@ def logp(self, value):
32683268
sigma = self.sigma
32693269
nu = self.nu
32703270

3271-
# This condition suggested by exGAUS.R from gamlss
3272-
lp = tt.switch(tt.gt(nu, 0.05 * sigma),
3273-
- tt.log(nu) + (mu - value) / nu + 0.5 * (sigma / nu)**2
3274-
+ logpow(std_cdf((value - mu) / sigma - sigma / nu), 1.),
3275-
- tt.log(sigma * tt.sqrt(2 * np.pi))
3276-
- 0.5 * ((value - mu) / sigma)**2)
3271+
# This condition is suggested by exGAUS.R from gamlss
3272+
lp = tt.switch(
3273+
tt.gt(nu, 0.05 * sigma),
3274+
-tt.log(nu)
3275+
+ (mu - value) / nu
3276+
+ 0.5 * (sigma / nu) ** 2
3277+
+ logpow(
3278+
tt.switch(
3279+
tt.eq(std_cdf((value - mu) / sigma - sigma / nu), 0),
3280+
np.finfo(float).eps,
3281+
std_cdf((value - mu) / sigma - sigma / nu)
3282+
),
3283+
1.0
3284+
),
3285+
-tt.log(sigma * tt.sqrt(2 * np.pi)) - 0.5 * ((value - mu) / sigma) ** 2,
3286+
)
3287+
32773288
return bound(lp, sigma > 0., nu > 0.)
32783289

32793290
def _repr_latex_(self, name=None, dist=None):

0 commit comments

Comments
 (0)