Skip to content

Commit f6a44a4

Browse files
committed
Use simplified form of derivatives
1 parent 3a01d33 commit f6a44a4

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/forward_operators/activation_functions.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ The `maxsig` activation function `maxsig(x) = max(x, 1.0/(1.0 + exp(-x)))`.
9999
if x > 1.0/(exp(-x) + 1.0)
100100
return 1.0
101101
end
102-
return exp(x)/(exp(x) + 1.0)^2
102+
return exp(-x)/(exp(-x) + 1.0)^2
103103
end
104104
@inline function maxsig_deriv2(x::Float64)
105105
if x > 1.0/(exp(-x) + 1.0)
106106
return 0.0
107107
end
108-
return exp(x)*(1.0 - exp(x))/(exp(x) + 1.0)^3
108+
return exp(x)*(1.0 - exp(x))/(exp(x) + 1.0)^3 #
109109
end
110110
function maxsig_kernel(x::MC{N,T}, z::Interval{Float64}) where {N, T<:Union{NS,MV}}
111111
xLc = z.lo
@@ -231,8 +231,8 @@ The `softplus` activation function `softplus(x) = log(1.0 + exp(x))`.
231231
@inline softplus(x) = log(1.0 + exp(x))
232232
@inline softplus(x::Float64) = log(1.0 + exp(x))
233233
@inline softplus(x::Interval{Float64}) = log(1.0 + exp(x))
234-
@inline softplus_deriv(x::Float64) = exp(x)/(exp(x) + 1.0)
235-
@inline softplus_deriv2(x::Float64) = exp(x)/(exp(x) + 1.0)^2
234+
@inline softplus_deriv(x::Float64) = 1.0/(exp(-x) + 1.0)
235+
@inline softplus_deriv2(x::Float64) = exp(-x)/(exp(-x) + 1.0)^2
236236
function softplus_kernel(x::MC{N,T}, z::Interval{Float64}) where {N, T<:Union{NS,MV}}
237237
xLc = z.lo
238238
xUc = z.hi
@@ -585,7 +585,7 @@ The Swish-1 activation function `swish1(x) = x/(1.0 + exp(-x))`.
585585
return Interval(xLcv, xUcv)
586586
end
587587
@inline function swish1_deriv(x::Float64)
588-
exp(x)*(x + exp(x) + 1.0)/(exp(x) + 1.0)^2
588+
sigmoid(x) + x*sigmoid_deriv(x)
589589
end
590590
@inline function swish1_deriv2(x::Float64)
591591
frac1 = 2.0*exp(-2.0*x)/(exp(-x) + 1.0)^3

0 commit comments

Comments
 (0)