Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello committed Mar 23, 2018
1 parent 7cef95a commit c073d39
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ broadcast_ops = [
# "fdim",
("invxback","invxback","(-xi*yi*yi)"),
("reluback","reluback","(yi>0?xi:0)"),
("eluback", "eluback", "ifelse(yi>0,dyi,yi+1)"),
("sigmback","sigmback","(xi*yi*(1-yi))"),
("tanhback","tanhback","(xi*(1-yi*yi))"),
("rpow","rpow","pow(yi,xi)"), # need this for Array.^Scalar
Expand Down
21 changes: 4 additions & 17 deletions src/unary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ unary_ops = [
# "normcdfinv",
# "rcbrt",
("relu", "relu", "(xi>0?xi:0)"),
("elu", "elu", "(xi>0?xi:exp(xi)-1)"),
# "rint",
"round",
# "rsqrt",
Expand Down Expand Up @@ -99,6 +100,7 @@ end
for (f,g,y,dx) in
((:invx, :invxback, :(one(T)/xi), :(-yi*yi*dyi)),
(:relu, :reluback, :(max(zero(T),xi)), :(ifelse(yi>0,dyi,zero(T)))),
(:elu, :eluback, :(ifelse(xi>0,xi,exp(xi)-1)), :(ifelse(yi>0,dyi,yi+1))),
(:tanx, :tanhback, :(tanh(xi)), :(dyi*(one(T)-yi*yi))),
(:sigm, :sigmback,
# Numerically stable implementation from
Expand Down Expand Up @@ -153,21 +155,6 @@ broadcast(::typeof(+), a::KnetArray)=a
+(a::KnetArray)=a
-(a::KnetArray)=broadcast(-,a)

"""
elu(x, alpha=1)
Exponential Linear Unit. Returns
`max(0,x) + alpha*(exp(min(x,0)) - 1)
Paper Ref. :
"Fast and Accurate Deep Network Learning by Exponential Linear Units (ELUs) (ICLR 2016)"
"""
function elu(x, alpha=1)
p = relu(x)
m = -relu(-x)
return p + alpha*(exp(m) - 1)
end

"""
selu(x)
Expand All @@ -180,8 +167,8 @@ Self-Normalizing Neural Networks
https://arxiv.org/abs/1706.02515
"""
function selu(x)
alpha = 1.6732632f
scale = 1.0507009f
alpha = 1.6732632f0
scale = 1.0507009f0
p = relu(x)
m = -relu(-x)
return scale*(p + alpha*(exp(m) - 1))
Expand Down

0 comments on commit c073d39

Please sign in to comment.