Skip to content

Commit

Permalink
Refactored code based on Junpeng's comment
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndorra committed Aug 12, 2020
1 parent 3ee52c2 commit 220282a
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions pymc3/distributions/continuous.py
Original file line number Diff line number Diff line change
Expand Up @@ -3268,21 +3268,16 @@ def logp(self, value):
sigma = self.sigma
nu = self.nu

standardized_val = (value - mu) / sigma
cdf_val = std_cdf(standardized_val - sigma / nu)
cdf_val_safe = tt.switch(tt.eq(cdf_val, 0), np.finfo(floatX).eps, cdf_val)

# This condition is suggested by exGAUS.R from gamlss
lp = tt.switch(
tt.gt(nu, 0.05 * sigma),
-tt.log(nu)
+ (mu - value) / nu
+ 0.5 * (sigma / nu) ** 2
+ logpow(
tt.switch(
tt.eq(std_cdf((value - mu) / sigma - sigma / nu), 0),
np.finfo(float).eps,
std_cdf((value - mu) / sigma - sigma / nu)
),
1.0
),
-tt.log(sigma * tt.sqrt(2 * np.pi)) - 0.5 * ((value - mu) / sigma) ** 2,
-tt.log(nu) + (mu - value) / nu + 0.5 * (sigma / nu) ** 2 + logpow(
cdf_val_safe, 1.0),
-tt.log(sigma * tt.sqrt(2 * np.pi)) - 0.5 * standardized_val ** 2,
)

return bound(lp, sigma > 0., nu > 0.)
Expand Down

0 comments on commit 220282a

Please sign in to comment.