/
concept-collection
/
walnuts-interactive
Jump to
/
Appearance
Match my system
Paper
GitHub
Slate
Midnight
Terminal
Sign in
concept-collection
/
walnuts-interactive
Code
Commits
Issues
0
Pull requests
0
Actions
Branches
1
Tags
0
Site
main
Branches
main
walnuts-interactive
/
helpers
/
logsumexp.m
9 lines · 254 B
Copy
Copied
Blame
History
Raw
1
function s = logsumexp(x)
2
%LOGSUMEXP Numerically stable log(sum(exp(x))) over all elements of x.
3
m = max(x(:));
4
if
~isfinite(m)
5
s = m; % all -Inf -> -Inf (and +Inf -> +Inf); avoids Inf-Inf = NaN
6
return
7
end
8
s = m + log(sum(exp(x(:) - m)));
9
end
↑
↓
move
↵
open
esc
close