Skip to content

Commit

Permalink
numeric stability
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeInnes committed Sep 12, 2017
1 parent 3fca9d0 commit f446498
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/activation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

relu(x) = max(0, x)

softmax!(out::AbstractVecOrMat, xs::AbstractVecOrMat) =
out .= exp.(xs) ./ sum(exp, xs, 1)
function softmax!(out::AbstractVecOrMat, xs::AbstractVecOrMat)
out .= xs .- maximum(xs)

This comment has been minimized.

Copy link
@CarloLucibello

CarloLucibello Sep 13, 2017

Member

maximum(xs, 1) would be better here

This comment has been minimized.

Copy link
@MikeInnes

MikeInnes Sep 22, 2017

Author Member

Any particular reason?

out .= exp.(out) ./ sum(exp, out, 1)
end

softmax!(xs) = softmax!(xs, xs)
softmax(xs) = softmax!(similar(xs), xs)
Expand Down

0 comments on commit f446498

Please sign in to comment.