# Backpropagation

Backpropagation is a method used in artificial neural networks to calculate a gradient that is needed in the calculation of the weights to be used in the network. Backpropagation is shorthand for "the backward propagation of errors," since an error is computed at the output and distributed backwards throughout the network’s layers. It is commonly used to train deep neural networks.

Backpropagation is a generalization of the delta rule to multi-layered feedforward networks, made possible by using the chain rule to iteratively compute gradients for each layer. It is closely related to the Gauss–Newton algorithm and is part of continuing research in neural backpropagation.

Backpropagation is a special case of a more general technique called automatic differentiation. In the context of learning, backpropagation is commonly used by the gradient descent optimization algorithm to adjust the weight of neurons by calculating the gradient of the loss function.

## Motivation

The goal of any supervised learning algorithm is to find a function that best maps a set of inputs to their correct output. The motivation for backpropagation is to train a multi-layered neural network such that it can learn the appropriate internal representations to allow it to learn any arbitrary mapping of input to output.

## Intuition

### Learning as an optimization problem

To understand the mathematical derivation of the backpropagation algorithm, it helps to first develop some intuition about the relationship between the actual output of a neuron and the correct output for a particular training example. Consider a simple neural network with two input units, one output unit and no hidden units. Each neuron uses a linear output[note 1] that is the weighted sum of its input.

Initially, before training, the weights will be set randomly. Then the neuron learns from training examples, which in this case consist of a set of tuples $(x_{1},x_{2},t)$ where $x_{1}$ and $x_{2}$ are the inputs to the network and t is the correct output (the output the network should produce given those inputs, when it has been trained). The initial network, given $x_{1}$ and $x_{2}$ , will compute an output y that likely differs from t (given random weights). A common method for measuring the discrepancy between the expected output t and the actual output y is the squared error measure:

$E=(t-y)^{2},$ where E is the discrepancy or error.

As an example, consider the network on a single training case: $(1,1,0)$ , thus the input $x_{1}$ and $x_{2}$ are 1 and 1 respectively and the correct output, t is 0. Now if the actual output y is plotted on the horizontal axis against the error E on the vertical axis, the result is a parabola. The minimum of the parabola corresponds to the output y which minimizes the error E. For a single training case, the minimum also touches the horizontal axis, which means the error will be zero and the network can produce an output y that exactly matches the expected output t. Therefore, the problem of mapping inputs to outputs can be reduced to an optimization problem of finding a function that will produce the minimal error.

However, the output of a neuron depends on the weighted sum of all its inputs:

$y=x_{1}w_{1}+x_{2}w_{2},$ where $w_{1}$ and $w_{2}$ are the weights on the connection from the input units to the output unit. Therefore, the error also depends on the incoming weights to the neuron, which is ultimately what needs to be changed in the network to enable learning. If each weight is plotted on a separate horizontal axis and the error on the vertical axis, the result is a parabolic bowl. For a neuron with k weights, the same plot would require an elliptic paraboloid of $k+1$ dimensions.

One commonly used algorithm to find the set of weights that minimizes the error is gradient descent. Backpropagation is then used to calculate the steepest descent direction.

## Derivation for a single-layered network

The gradient descent method involves calculating the derivative of the squared error function with respect to the weights of the network. This is normally done using backpropagation. Assuming one output neuron,[note 2] the squared error function is:

$E={\tfrac {1}{2}}(t-y)^{2},$ where

$E$ is the squared error,
$t$ is the target output for a training sample, and
$y$ is the actual output of the output neuron.

The factor of $\textstyle {\frac {1}{2}}$ is included to cancel the exponent when differentiating. Later, the expression will be multiplied with an arbitrary learning rate, so that it doesn't matter if a constant coefficient is introduced now.

For each neuron $j$ , its output $o_{j}$ is defined as

$o_{j}=\varphi ({\text{net}}_{j})=\varphi \left(\sum _{k=1}^{n}w_{kj}o_{k}\right).$ The input ${\text{net}}_{j}$ to a neuron is the weighted sum of outputs $o_{k}$ of previous neurons. If the neuron is in the first layer after the input layer, the $o_{k}$ of the input layer are simply the inputs $x_{k}$ to the network. The number of input units to the neuron is $n$ . The variable $w_{kj}$ denotes the weight between neurons $k$ and $j$ .

The activation function $\varphi$ is non-linear and differentiable. A commonly used activation function is the logistic function:

$\varphi (z)={\frac {1}{1+e^{-z}}}$ which has a convenient derivative of:

${\frac {d\varphi (z)}{dz}}=\varphi (z)(1-\varphi (z))$ ### Finding the derivative of the error

Calculating the partial derivative of the error with respect to a weight $w_{ij}$ is done using the chain rule twice:

${\frac {\partial E}{\partial w_{ij}}}={\frac {\partial E}{\partial o_{j}}}{\frac {\partial o_{j}}{\partial {\text{net}}_{j}}}{\frac {\partial {\text{net}}_{j}}{\partial w_{ij}}}$ In the last factor of the right-hand side of the above, only one term in the sum ${\text{net}}_{j}$ depends on $w_{ij}$ , so that

${\frac {\partial {\text{net}}_{j}}{\partial w_{ij}}}={\frac {\partial }{\partial w_{ij}}}\left(\sum _{k=1}^{n}w_{kj}o_{k}\right)={\frac {\partial }{\partial w_{ij}}}w_{ij}o_{i}=o_{i}.$ If the neuron is in the first layer after the input layer, $o_{i}$ is just $x_{i}$ .

The derivative of the output of neuron $j$ with respect to its input is simply the partial derivative of the activation function (assuming here that the logistic function is used):

${\frac {\partial o_{j}}{\partial {\text{net}}_{j}}}={\frac {\partial }{\partial {\text{net}}_{j}}}\varphi ({\text{net}}_{j})=\varphi ({\text{net}}_{j})(1-\varphi ({\text{net}}_{j}))$ This is the reason why backpropagation requires the activation function to be differentiable. (Nevertheless, the ReLU activation function, which is non-differentiable at 0, has become quite popular recently, e.g. in AlexNet)

The first factor is straightforward to evaluate if the neuron is in the output layer, because then $o_{j}=y$ and

${\frac {\partial E}{\partial o_{j}}}={\frac {\partial E}{\partial y}}={\frac {\partial }{\partial y}}{\frac {1}{2}}(t-y)^{2}=y-t$ However, if $j$ is in an arbitrary inner layer of the network, finding the derivative $E$ with respect to $o_{j}$ is less obvious.

Considering $E$ as a function of the inputs of all neurons $L={u,v,\dots ,w}$ receiving input from neuron $j$ ,

${\frac {\partial E(o_{j})}{\partial o_{j}}}={\frac {\partial E(\mathrm {net} _{u},{\text{net}}_{v},\dots ,\mathrm {net} _{w})}{\partial o_{j}}}$ and taking the total derivative with respect to $o_{j}$ , a recursive expression for the derivative is obtained:

${\frac {\partial E}{\partial o_{j}}}=\sum _{\ell \in L}\left({\frac {\partial E}{\partial {\text{net}}_{\ell }}}{\frac {\partial {\text{net}}_{\ell }}{\partial o_{j}}}\right)=\sum _{\ell \in L}\left({\frac {\partial E}{\partial o_{\ell }}}{\frac {\partial o_{\ell }}{\partial {\text{net}}_{\ell }}}w_{j\ell }\right)$ Therefore, the derivative with respect to $o_{j}$ can be calculated if all the derivatives with respect to the outputs $o_{\ell }$ of the next layer – the one closer to the output neuron – are known.

Putting it all together:

${\frac {\partial E}{\partial w_{ij}}}=\delta _{j}o_{i}$ with

$\delta _{j}={\frac {\partial E}{\partial o_{j}}}{\frac {\partial o_{j}}{\partial {\text{net}}_{j}}}={\begin{cases}(o_{j}-t_{j})o_{j}(1-o_{j})&{\text{if }}j{\text{ is an output neuron,}}\\(\sum _{\ell \in L}w_{j\ell }\delta _{\ell })o_{j}(1-o_{j})&{\text{if }}j{\text{ is an inner neuron.}}\end{cases}}$ To update the weight $w_{ij}$ using gradient descent, one must choose a learning rate, $\eta >0$ . The change in weight needs to reflect the impact on $E$ of an increase or decrease in $w_{ij}$ . If ${\frac {\partial E}{\partial w_{ij}}}>0$ , an increase in $w_{ij}$ increases $E$ ; conversely, if ${\frac {\partial E}{\partial w_{ij}}}<0$ , an increase in $w_{ij}$ decreases $E$ . The new $\Delta w_{ij}$ is added to the old weight, and the product of the learning rate and the gradient, multiplied by $-1$ guarantees that $w_{ij}$ changes in a way that always decreases $E$ . In other words, in the equation immediately below, $-\eta {\frac {\partial E}{\partial w_{ij}}}$ always changes $w_{ij}$ in such a way that $E$ is decreased:

$\Delta w_{ij}=-\eta {\frac {\partial E}{\partial w_{ij}}}=-\eta \delta _{j}o_{i}$ ## Loss function

The loss function is a function that maps values of one or more variables onto a real number intuitively representing some "cost" associated with those values. For backpropagation, the loss function calculates the difference between the network output and its expected output, after a training example has propagated through the network.

### Assumptions

The mathematical expression of the loss function must fullfill two conditions in order for it to be possibly used in back propagation. The first is that it can be written as an average ${\textstyle E={\frac {1}{n}}\sum _{x}E_{x}}$ over error functions ${\textstyle E_{x}}$ , for ${\textstyle n}$ individual training examples, ${\textstyle x}$ . The reason for this assumption is that the backpropagation algorithm calculates the gradient of the error function for a single training example, which needs to be generalized to the overall error function. The second assumption is that it can be written as a function of the outputs from the neural network.

### Example loss function

Let $y,y'$ be vectors in $\mathbb {R} ^{n}$ .

Select an error function $E(y,y')$ measuring the difference between two outputs. The standard choice is the square of the Euclidean distance between the vectors $y$ and $y'$ :

$E(y,y')={\tfrac {1}{2}}\lVert y-y'\rVert ^{2}$ The error function over ${\textstyle n}$ training examples can then be written as an average of losses over individual examples:
$E={\frac {1}{2n}}\sum _{x}\lVert (y(x)-y'(x))\rVert ^{2}$ ## Limitations

• Gradient descent with backpropagation is not guaranteed to find the global minimum of the error function, but only a local minimum; also, it has trouble crossing plateaus in the error function landscape. This issue, caused by the non-convexity of error functions in neural networks, was long thought to be a major drawback, but Yann LeCun et al. argue that in many practical problems, it is not.
• Backpropagation learning does not require normalization of input vectors; however, normalization could improve performance.

## History

The basics of continuous backpropagation were derived in the context of control theory by Henry J. Kelley in 1960 and by Arthur E. Bryson in 1961. They used principles of dynamic programming. In 1962, Stuart Dreyfus published a simpler derivation based only on the chain rule. Bryson and Ho described it as a multi-stage dynamic system optimization method in 1969.

Backpropagation was derived by multiple researchers in the early 60's and implemented to run on computers as early as 1970 by Seppo Linnainmaa Examples of 1960s researchers include Arthur E. Bryson and Yu-Chi Ho in 1969. Paul Werbos was first in the US to propose that it could be used for neural nets after analyzing it in depth in his 1974 PhD Thesis. In 1986, through the work of David E. Rumelhart, Geoffrey E. Hinton, Ronald J. Williams, and James McClelland, backpropagation gained recognition.

In 1970 Linnainmaa published the general method for automatic differentiation (AD) of discrete connected networks of nested differentiable functions. This corresponds to backpropagation, which is efficient even for sparse networks.

In 1973 Dreyfus used backpropagation to adapt parameters of controllers in proportion to error gradients. In 1974 Werbos mentioned the possibility of applying this principle to artificial neural networks, and in 1982 he applied Linnainmaa's AD method to neural networks in the way that is used today.

In 1986 Rumelhart, Hinton and Williams showed experimentally that this method can generate useful internal representations of incoming data in hidden layers of neural networks. In 1993, Wan was the first to win an international pattern recognition contest through backpropagation.

During the 2000s it fell out of favour, but returned in the 2010s, benefitting from cheap, powerful GPU-based computing systems. This has been especially so in language structure learning research, where the connectionist models using this algorithm have been able to explain a variety of phenomena related to first and second language learning.