Skip to content

Commit

Permalink
update log1pexp log1mexp
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Aug 26, 2017
1 parent 272477e commit 159d5cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions common/log1mexp.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function y = log1mexp(x)
% Accurately compute y = log(1-exp(-x))
% Accurately compute y = log(1-exp(x))
% reference: Accurately Computing log(1-exp(-|a|)) Martin Machler
y = x;
i = x > log(2);
y(i) = log1p(-exp(-x(i)));
y(~i) = log(-expm1(-x(~i)));
i = x < -log(2);
y(i) = log1p(-exp(x(i)));
y(~i) = log(-expm1(x(~i)));
9 changes: 5 additions & 4 deletions common/log1pexp.m
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
function y = log1pexp(x)
% Accurately compute y = log(1+exp(x))
% reference: Accurately Computing log(1-exp(|a|)) Martin Machler
seed = 33.3;
% reference: Accurately Computing log(1-exp(-|a|)) Martin Machler
y = x;
idx = x<seed;
y(idx) = log1p(exp(x(idx)));
i = x > 18;
j = i & (x <= 33.3);
y(~i) = log1p(exp(x(~i)));
y(j) = x(j)+exp(-x(j));

0 comments on commit 159d5cd

Please sign in to comment.