Activation Function
Study guide: Exam MAS-II
An Activation Function is the non-linear function g that a unit of a neural network applies to the weighted combination of its inputs. The activation of hidden unit k is
A_k = g\!\left(w_{k0} + \sum_{j=1}^{p} w_{kj}X_j\right)
w_{kj}is the weight from predictorX_jto unitk, andw_{k0}is the unit's bias.
A hidden unit has weights
w_ = -1.5,w_ = 0.8andw_ = -0.3. What is its activation forX_1 = 4andX_2 = 2under the ReLU and under the sigmoid?
- The weighted combination is
-1.5 + 0.8(4) - 0.3(2) = 1.1.- The ReLU gives
\max(0, 1.1) = 1.1.- The sigmoid gives
1/(1 + e^{-1.1}) = 0.750.
The idea The activation function is the only non-linear step in a network, so it is the whole source of the network's flexibility.
Common activation functions
The ReLU (rectified linear unit) is
g(z) = \max(0, z)
The sigmoid is
g(z) = \frac{1}{1 + e^{-z}}
The ReLU is the usual choice for hidden layers. It is cheap to compute, and its slope is 1 for every z > 0. The sigmoid squashes its input into (0, 1), and its slope is near zero for large \lvert z \rvert, so backpropagation gradients shrink through a deep stack of sigmoid units. A ReLU unit whose input is negative for every observation outputs zero and stops learning.
A unit's weighted combination is
z = -1.1. What are its ReLU and sigmoid activations?
- The ReLU gives
\max(0, -1.1) = 0, so the unit contributes nothing to this prediction.- The sigmoid gives
1/(1 + e^{1.1}) = 0.250.
Linear activation
With the identity activation g(z) = z, each hidden unit is a linear combination of the inputs, and the output is a linear combination of those. Two linear layers compose into one:
\mathbf{W}_2(\mathbf{W}_1 x) = (\mathbf{W}_2\mathbf{W}_1)x
\mathbf{W}_1and\mathbf{W}_2are the weight matrices of the two layers.
The network is then a linear model with extra weights that cannot be identified, however many layers it has.
A network with the identity activation has one hidden unit
A = 1 + 2Xand outputf = -2 + 3A. What does it compute?
- Substituting the hidden unit gives
f = -2 + 3(1 + 2X).- That is
f = 1 + 6X, a straight line inX, which one linear predictor with two coefficients gives directly.
Output activation
The output unit's activation is chosen by the response. A quantitative response takes the identity, so the output is \beta_0 + \sum_k \beta_k A_k. A binary response takes the sigmoid, so the output is a probability. A response with M classes takes the softmax, which turns the M outputs Z_1, \ldots, Z_M into probabilities:
P(Y = m \mid X) = \frac{e^{Z_m}}{\sum_{\ell=1}^{M} e^{Z_\ell}}