Skip to content

Commit 220282a

Browse files
committed
Refactored code based on Junpeng's comment
1 parent 3ee52c2 commit 220282a

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

pymc3/distributions/continuous.py

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

3271+
standardized_val = (value - mu) / sigma
3272+
cdf_val = std_cdf(standardized_val - sigma / nu)
3273+
cdf_val_safe = tt.switch(tt.eq(cdf_val, 0), np.finfo(floatX).eps, cdf_val)
3274+
32713275
# This condition is suggested by exGAUS.R from gamlss
32723276
lp = tt.switch(
32733277
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,
3278+
-tt.log(nu) + (mu - value) / nu + 0.5 * (sigma / nu) ** 2 + logpow(
3279+
cdf_val_safe, 1.0),
3280+
-tt.log(sigma * tt.sqrt(2 * np.pi)) - 0.5 * standardized_val ** 2,
32863281
)
32873282

32883283
return bound(lp, sigma > 0., nu > 0.)

0 commit comments

Comments
 (0)