Skip to content

Commit

Permalink
fix common functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sth4nth committed Jan 26, 2016
1 parent c0db46a commit d3eb24d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions common/logsumexp.m
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
function s = logsumexp(x, dim)
% Compute log(sum(exp(x),dim)) while avoiding numerical underflow.
function s = logsumexp(X, dim)
% Compute log(sum(exp(X),dim)) while avoiding numerical underflow.
% By default dim = 1 (columns).
% Written by Michael Chen ([email protected]).
if nargin == 1,
% Determine which dimension sum will use
dim = find(size(x)~=1,1);
dim = find(size(X)~=1,1);
if isempty(dim), dim = 1; end
end

% subtract the largest in each dim
y = max(x,[],dim);
s = y+log(sum(exp(bsxfun(@minus,x,y)),dim)); % TODO: use log1p
y = max(X,[],dim);
s = y+log(sum(exp(bsxfun(@minus,X,y)),dim)); % TODO: use log1p
i = isinf(y);
if any(i(:))
s(i) = y(i);
Expand Down
2 changes: 1 addition & 1 deletion common/normalize.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
% Written by Michael Chen ([email protected]).
if nargin == 1,
% Determine which dimension sum will use
dim = find(size(x)~=1,1);
dim = find(size(X)~=1,1);
if isempty(dim), dim = 1; end
end
s = sum(X,dim);
Expand Down
2 changes: 1 addition & 1 deletion common/standardize.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
% Written by Michael Chen ([email protected]).
if nargin == 1,
% Determine which dimension sum will use
dim = find(size(x)~=1,1);
dim = find(size(X)~=1,1);
if isempty(dim), dim = 1; end
end
X = bsxfun(@minux,X,mean(X,2));
Expand Down
2 changes: 1 addition & 1 deletion common/unitize.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
% Written by Michael Chen ([email protected]).
if nargin == 1,
% Determine which dimension sum will use
dim = find(size(x)~=1,1);
dim = find(size(X)~=1,1);
if isempty(dim), dim = 1; end
end
s = sqrt(sum(X.^2,dim));
Expand Down

0 comments on commit d3eb24d

Please sign in to comment.