Here is my attempt at finding the derivatives of common activation functions of neural network namely sigmoid, tanh, ReLU and leaky ReLU functions.
1. Sigmoid function
f(x)=σ(x)1=1+e−x
Differentiating both sides,
f′(x)=dxd(σ(x)1)=dxd(1+e−x)
−σ(x)2σ′(x)=−e−x
−σ(x)2σ′(x)=1−f(x)
−σ(x)2σ′(x)=1−f(x)
−σ(x)2σ′(x)=1−σ(x)1
−σ(x)2σ′(x)=σ(x)σ(x)−1
Rearranging the terms,
σ(x)2σ′(x)=σ(x)1−σ(x)
σ′(x)=σ(x)2(σ(x)1−σ(x))
σ′(x)=σ(x)(1−σ(x))
2. tanh function
f(x)=tanh(x)=ex+e−xex−e−x
Differentiating both sides,
dxdtanh(x)=dxd(cosh(x)sinh(x))
Using quotient rule,
tanh′(x)=(cosh(x)dxdsinh(x)−sinh(x)dxdcosh(x))/cosh2(x)
tanh′(x)=(cosh(x)cosh(x)−sinh(x)sinh(x))/cosh2(x)
tanh′(x)=1−tanh2(x)
3. ReLU function
f(x)=max(0,x)
\begin{cases}
1, & \text{if $x$ > 0} \\
0, & \text{otherwise}
\end{cases} $$
Note: In software, we can use f'(x) = 1 for x = 0 (Prof. Andrew NG in Deep Learning Coursera Course)
---
**4. Leaky ReLU function**
$$ f(x) = max(0.01, x) $$
$$ f'(x) =
\begin{cases}
1, & \text{if x > 0} \\
0.01, & \text{otherwise}
\end{cases} $$
Note: In software, we can use f'(x) = 1 or 0.01 for x = 0 (Prof. Andrew NG in Deep Learning Coursera Course)