Skip to content

Commit 03857d1

Browse files
committed
tweak softmax
1 parent 03bdc61 commit 03857d1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

chapter04/softmax.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function s = softmax(x, dim)
1+
function [Y,s] = softmax(X, dim)
22
% Softmax function
33
% By default dim = 1 (columns).
44
% Written by Mo Chen ([email protected]).
55
if nargin == 1
6-
% Determine which dimension sum will use
7-
dim = find(size(x)~=1,1);
6+
dim = find(size(X)~=1,1);
87
if isempty(dim), dim = 1; end
98
end
10-
s = exp(bsxfun(@minus,x,logsumexp(x,dim)));
9+
s = logsumexp(X,dim);
10+
Y = exp(X-s);

0 commit comments

Comments
 (0)