Skip to content

Commit

Permalink
add lognormexp
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Mar 26, 2017
1 parent 8ffe5dc commit 330fe22
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions common/lognormexp.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function [Y,s] = lognormexp(X, dim)
% Compute log(normalize(exp(x),dim)) while avoiding numerical underflow.
% By default dim = 1 (columns).
% Written by Mo Chen ([email protected]).
if nargin == 1
dim = find(size(X)~=1,1);
if isempty(dim), dim = 1; end
end
s = logsumexp(X,dim);
Y = exp(X-s);

0 comments on commit 330fe22

Please sign in to comment.