Merge pull request #38 from staticfloat/sf/act_on_your_feelings_young_one

Fix activation functions
This commit is contained in:
Mike J Innes 2017-05-31 14:22:52 +01:00 committed by GitHub
commit 033ed13f69

View File

@ -1,12 +1,12 @@
export σ, relu, softmax, flatten
# Sigmoid
σ(x) = 1 ./ (1 + exp.(-x))
back!(::typeof(σ), Δ, x) = Δ .* σ(x).*(1.-σ(x))
back!(::typeof(σ), Δ, x) = Δ .* σ(x)./(1.-σ(x))
# Rectified Linear Unit
relu(x) = max(0, x)
back!(::typeof(relu), Δ, x) = Δ .* (x .< 0)
back!(::typeof(relu), Δ, x) = Δ .* (x .> 0)
# TODO: correct behaviour with batches
softmax(xs) = exp.(xs) ./ sum(exp.(xs))