Skip to content

Commit beb489d

Browse files
committed
Added logaddexp
1 parent a99e429 commit beb489d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

pymc3/math.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ def logsumexp(x, axis=None):
3131
x_max = tt.max(x, axis=axis, keepdims=True)
3232
return tt.log(tt.sum(tt.exp(x - x_max), axis=axis, keepdims=True)) + x_max
3333

34+
def logaddexp(a, b):
35+
diff = b - a
36+
return tt.switch(diff > 0,
37+
b + tt.log1p(tt.exp(-diff)),
38+
a + tt.log1p(tt.exp(diff)))
3439

3540
def invlogit(x, eps=sys.float_info.epsilon):
3641
return (1. - 2. * eps) / (1. + tt.exp(-x)) + eps

0 commit comments

Comments
 (0)