Backpropagation

Source: https://en.wikipedia.org/wiki/Backpropagation


Backpropagation

From Wikipedia, the free encyclopedia
This article is about the computer algorithm. For the biological process, see   Neural backpropagation.
Backpropagation can also refer to the way the result of a playout is propagated up the search tree in   Monte Carlo tree search

The backward propagation of errors or backpropagation, is a common method of training artificial neural networks and used in conjunction with an optimization method such as gradient descent. The algorithm repeats a two phase cycle, propagation and weight update. When an input vector is presented to the network, it is propagated forward through the network, layer by layer, until it reaches the output layer. The output of the network is then compared to the desired output, using a loss function, and an error value is calculated for each of the neurons in the output layer. The error values are then propagated backwards, starting from the output, until each neuron has an associated error value which roughly represents its contribution to the original output.

Backpropagation uses these error values to calculate the gradient of the loss function with respect to the weights in the network. In the second phase, this gradient is fed to the optimization method, which in turn uses it to update the weights, in an attempt to minimize the loss function.

The importance of this process is that, as the network is trained, the neurons in the intermediate layers organize themselves in such a way that the different neurons learn to recognize different characteristics of the total input space. After training, when an arbitrary input pattern is present which contains noise or is incomplete, neurons in the hidden layer of the network will respond with an active output if the new input contains a pattern that resembles a feature that the individual neurons have learned to recognize during their training.

Backpropagation requires a known, desired output for each input value in order to calculate the loss function gradient – it is therefore usually considered to be a supervised learning method; nonetheless, it is also used in some unsupervised networks such as autoencoders. It 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. Backpropagation requires that the activation function used by the artificial neurons (or "nodes") be differentiable.

Motivation[edit]

The goal of any supervised learning algorithm is to find a function that best maps a set of inputs to its correct output. An example would be a classification task, where the input is an image of an animal, and the correct output would be the name of the animal.

The motivation for developing the backpropagation algorithm was to find a way 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.[1] The goal of backpropagation is to compute the partial derivative, or gradient, {\textstyle \partial E/\partial w}{\textstyle \partial E/\partial w} of a loss function {\textstyle E}{\textstyle E} with respect to any weight {\displaystyle w}w in the network.[2]

Loss function[edit]

Further information:   Loss function

Sometimes referred to as the cost function or error function (not to be confused with the Gauss error 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 the event. For backpropagation, the loss function calculates the difference between the input training example and its expected output, after the example has been propagated through the network.

Assumptions about the loss function[edit]

For backpropagation to work, two assumptions are made about the form of the error function.[2] The first is that it can be written as an average {\textstyle E={\frac {1}{n}}\sum _{x}E_{x}}{\textstyle E={\frac {1}{n}}\sum _{x}E_{x}} over error functions {\textstyle E_{x}}{\textstyle E_{x}}, for individual training examples, {\textstyle x}{\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. In practice, training examples are placed in batches, and the error is averaged at the end of the batch, which is then used to update the weights. The second assumption is that it can be written as a function of the outputs from the neural network.

Example loss function[edit]

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

Select an error function {\displaystyle E(y,y')}{\displaystyle E(y,y')} measuring the difference between two outputs. The standard choice is {\displaystyle E(y,y')={\tfrac {1}{2}}|y-y'|^{2}}{\displaystyle E(y,y')={\tfrac {1}{2}}|y-y'|^{2}}, the square of the Euclidean distance between the vectors {\displaystyle y}y and {\displaystyle y'}y'. The factor of {\displaystyle {\tfrac {1}{2}}}{\tfrac {1}{2}} conveniently cancels the exponent when the error function is subsequently differentiated. The error function over {\textstyle n}{\textstyle n} training examples can be written as an average:

{\displaystyle E={\frac {1}{2n}}\sum _{x}\lVert (y(x)-y'(x))\rVert ^{2}}
{\displaystyle E={\frac {1}{2n}}\sum _{x}\lVert (y(x)-y'(x))\rVert ^{2}}
And the partial derivative with respect to the outputs:
{\displaystyle {\frac {\partial E}{\partial y'}}=(y'-y)}
{\displaystyle {\frac {\partial E}{\partial y'}}=(y'-y)}

Algorithm[edit]

Let {\displaystyle N}N be a neural network with {\displaystyle e}e connections.

Below, {\displaystyle x,x_{1},x_{2},\dots }{\displaystyle x,x_{1},x_{2},\dots } will denote vectors in {\displaystyle \mathbb {R} ^{m}}\mathbb {R} ^{m}{\displaystyle y,y',y_{1},y_{2},\dots }{\displaystyle y,y',y_{1},y_{2},\dots } vectors in {\displaystyle \mathbb {R} ^{n}}\mathbb {R} ^{n}, and {\displaystyle w,w_{0},w_{1},\ldots }{\displaystyle w,w_{0},w_{1},\ldots } vectors in {\displaystyle \mathbb {R} ^{e}}{\displaystyle \mathbb {R} ^{e}}. These are called inputsoutputs and weights respectively. The neural network corresponds to a function {\displaystyle y=f_{N}(w,x)}{\displaystyle y=f_{N}(w,x)} which, given a weight {\displaystyle w}w, maps an input {\displaystyle x}x to an output {\displaystyle y}y.

The backpropagation algorithm takes as input a sequence of training examples {\displaystyle (x_{1},y_{1}),\dots ,(x_{p},y_{p})}{\displaystyle (x_{1},y_{1}),\dots ,(x_{p},y_{p})} and produces a sequence of weights {\displaystyle w_{0},w_{1},\dots ,w_{p}}{\displaystyle w_{0},w_{1},\dots ,w_{p}} starting from some initial weight {\displaystyle w_{0}}w_{0}, usually chosen at random. These weights are computed in turn: first compute {\displaystyle w_{i}}w_{i} using only {\displaystyle (x_{i},y_{i},w_{i-1})}{\displaystyle (x_{i},y_{i},w_{i-1})} for {\displaystyle i=1,\dots ,p}{\displaystyle i=1,\dots ,p}. The output of the backpropagation algorithm is then {\displaystyle w_{p}}w_p, giving us a new function {\displaystyle x\mapsto f_{N}(w_{p},x)}{\displaystyle x\mapsto f_{N}(w_{p},x)}. The computation is the same in each step, hence only the case {\displaystyle i=1}i=1 is described.

Calculating {\displaystyle w_{1}}w_{1} from {\displaystyle (x_{1},y_{1},w_{0})}{\displaystyle (x_{1},y_{1},w_{0})} is done by considering a variable weight {\displaystyle w}w and applying gradient descent to the function {\displaystyle w\mapsto E(f_{N}(w,x_{1}),y_{1})}{\displaystyle w\mapsto E(f_{N}(w,x_{1}),y_{1})} to find a local minimum, starting at {\displaystyle w=w_{0}}{\displaystyle w=w_{0}}.

This makes {\displaystyle w_{1}}w_{1} the minimizing weight found by gradient descent.

Algorithm in code[edit]

To implement the algorithm above, explicit formulas are required for the gradient of the function {\displaystyle w\mapsto E(f_{N}(w,x),y)}{\displaystyle w\mapsto E(f_{N}(w,x),y)} where the function {\displaystyle E(y,y')=|y-y'|^{2}}{\displaystyle E(y,y')=|y-y'|^{2}}.

The backpropagation learning algorithm can be divided into two phases: propagation and weight update.

Phase 1: Propagation[edit]

Each propagation involves the following steps:

  1. Forward propagation of a training pattern's input through the neural network in order to generate the network's output value(s).
  2. Backward propagation of the propagation's output activations through the neural network using the training pattern target in order to generate the deltas (the difference between the targeted and actual output values) of all output and hidden neurons.

Phase 2: Weight update[edit]

For each weight, the following steps must be followed:

  1. The weight's output delta and input activation are multiplied to find the gradient of the weight.
  2. A ratio (percentage) of the weight's gradient is subtracted from the weight.

This ratio (percentage) influences the speed and quality of learning; it is called the learning rate. The greater the ratio, the faster the neuron trains, but the lower the ratio, the more accurate the training is. The sign of the gradient of a weight indicates whether the error varies directly with, or inversely to, the weight. Therefore, the weight must be updated in the opposite direction, "descending" the gradient.

Phases 1 and 2 are repeated until the performance of the network is satisfactory.

Code[edit]

The following is pseudocode for a stochastic gradient descent algorithm for training a three-layer network (only one hidden layer):

  initialize network weights (often small random values)
  do
     forEach training example named ex
        prediction = neural-net-output(network, ex)  // forward pass
        actual = teacher-output(ex)
        compute error (prediction - actual) at the output units
        compute {\displaystyle \Delta w_{h}}\Delta w_h for all weights from hidden layer to output layer  // backward pass
        compute {\displaystyle \Delta w_{i}}\Delta w_i for all weights from input layer to hidden layer   // backward pass continued
        update network weights // input layer not modified by error estimate
  until all examples classified correctly or another stopping criterion satisfied
  return the network

The lines labeled "backward pass" can be implemented using the backpropagation algorithm, which calculates the gradient of the error of the network regarding the network's modifiable weights.[3] Often the term "backpropagation" is used in a more general sense, to refer to the entire procedure encompassing both the calculation of the gradient and its use in stochastic gradient descent, but backpropagation properties can be used with any gradient-based optimizer, such as L-BFGS or truncated Newton.

Backpropagation networks are necessarily multilayer perceptrons (usually with one input, multiple hidden, and one output layer). In order for the hidden layer to serve any useful function, multilayer networks must have non-linear activation functions for the multiple layers: a multilayer network using only linear activation functions is equivalent to some single layer, linear network. Non-linear activation functions that are commonly used include the rectifierlogistic function, the softmax function, and the gaussian function.

The backpropagation algorithm for calculating a gradient has been rediscovered a number of times, and is a special case of a more general technique called automatic differentiation in the reverse accumulation mode.

It is also closely related to the Gauss–Newton algorithm, and is also part of continuing research in neural backpropagation.

Intuition[edit]

Learning as an optimization problem[edit]

Before showing the mathematical derivation of the backpropagation algorithm, it helps to develop some intuitions about the relationship between the actual output of a neuron and the correct output for a particular training case. 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.

A simple neural network with two input units and one output unit

Initially, before training, the weights will be set randomly. Then the neuron learns from training examples, which in this case consists of a set of tuples ({\displaystyle x_{1}}x_{1}{\displaystyle x_{2}}x_{2}{\displaystyle t}t) where {\displaystyle x_{1}}x_{1} and {\displaystyle x_{2}}x_{2} are the inputs to the network and {\displaystyle t}t is the correct output (the output the network should eventually produce given the identical inputs). The network given {\displaystyle x_{1}}x_{1} and {\displaystyle x_{2}}x_{2} will compute an output {\displaystyle y}y which very likely differs from {\displaystyle t}t (since the weights are initially random). A common method for measuring the discrepancy between the expected output {\displaystyle t}t and the actual output {\displaystyle y}y is using the squared error measure:

{\displaystyle E=(t-y)^{2}\,}E=(t-y)^2 \,,

where {\displaystyle E}E is the discrepancy or error.

As an example, consider the network on a single training case: {\displaystyle (1,1,0)}(1, 1, 0), thus the input {\displaystyle x_{1}}x_{1} and {\displaystyle x_{2}}x_{2} are 1 and 1 respectively and the correct output, {\displaystyle t}t is 0. Now if the actual output {\displaystyle y}y is plotted on the x-axis against the error {\displaystyle E}E on the {\displaystyle y}y-axis, the result is a parabola. The minimum of the parabola corresponds to the output {\displaystyle y}y which minimizes the error {\displaystyle E}E. For a single training case, the minimum also touches the {\displaystyle x}x-axis, which means the error will be zero and the network can produce an output {\displaystyle y}y that exactly matches the expected output {\displaystyle t}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.

Error surface of a linear neuron for a single training case.

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

{\displaystyle y=x_{1}w_{1}+x_{2}w_{2}}y=x_1w_1 + x_2w_2,

where {\displaystyle w_{1}}w_{1} and {\displaystyle w_{2}}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 {\displaystyle k}k weights, the same plot would require an elliptic paraboloid of {\displaystyle k+1}k+1dimensions.

Error surface of a linear neuron with two input weights

The backpropagation algorithm aims to find the set of weights that minimizes the error. There are several methods for finding the minima of a parabola or any function in any dimension. One way is analytically by solving systems of equations, however this relies on the network being a linear system, and the goal is to be able to also train multi-layer, non-linear networks (since a multi-layered linear network is equivalent to a single-layer network). The method used in backpropagation is gradient descent.

An analogy for understanding gradient descent[edit]

Further information:   Gradient descent

The basic intuition behind gradient descent can be illustrated by a hypothetical scenario. A person is stuck in the mountains and is trying to get down (i.e. trying to find the minima). There is heavy fog such that visibility is extremely low. Therefore, the path down the mountain is not visible, so he must use local information to find the minima. He can use the method of gradient descent, which involves looking at the steepness of the hill at his current position, then proceeding in the direction with the steepest descent (i.e. downhill). If he was trying to find the top of the mountain (i.e. the maxima), then he would proceed in the direction steepest ascent (i.e. uphill). Using this method, he would eventually find his way down the mountain. However, assume also that the steepness of the hill is not immediately obvious with simple observation, but rather it requires a sophisticated instrument to measure, which the person happens to have at the moment. It takes quite some time to measure the steepness of the hill with the instrument, thus he should minimize his use of the instrument if he wanted to get down the mountain before sunset. The difficulty then is choosing the frequency at which he should measure the steepness of the hill so not to go off track.

In this analogy, the person represents the backpropagation algorithm, and the path taken down the mountain represents the sequence of parameter settings that the algorithm will explore. The steepness of the hill represents the slope of the error surface at that point. The instrument used to measure steepness is differentiation (the slope of the error surface can be calculated by taking the derivative of the squared error function at that point). The direction he chooses to travel in aligns with the gradient of the error surface at that point. The amount of time he travels before taking another measurement is the learning rate of the algorithm. See the limitation section for a discussion of the limitations of this type of "hill climbing" algorithm.

Derivation[edit]

Since backpropagation uses the gradient descent method, one needs to calculate the derivative of the squared error function with respect to the weights of the network. Assuming one output neuron,[note 2] the squared error function is:

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

where

{\displaystyle E}E  is the squared error,
{\displaystyle t}t  is the target output for a training sample, and
{\displaystyle y}y  is the actual output of the output neuron.

The factor of {\displaystyle \textstyle {\frac {1}{2}}}\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 {\displaystyle j}j, its output {\displaystyle o_{j}}o_{j} is defined as

{\displaystyle o_{j}=\varphi ({\mbox{net}}_{j})=\varphi \left(\sum _{k=1}^{n}w_{kj}o_{k}\right)}o_{j} = \varphi(\mbox{net}_{j}) = \varphi\left(\sum_{k=1}^{n}w_{kj}o_k\right).

The input {\displaystyle {\mbox{net}}_{j}}\mbox{net}_{j} to a neuron is the weighted sum of outputs {\displaystyle o_{k}}o_k of previous neurons. If the neuron is in the first layer after the input layer, the {\displaystyle o_{k}}o_k of the input layer are simply the inputs {\displaystyle x_{k}}x_{k} to the network. The number of input units to the neuron is {\displaystyle n}n. The variable {\displaystyle w_{ij}}w_{ij} denotes the weight between neurons {\displaystyle i}i and {\displaystyle j}j.

The activation function {\displaystyle \varphi }\varphi  is in general non-linear and differentiable. A commonly used activation function is the logistic function:

{\displaystyle \varphi (z)={\frac {1}{1+e^{-z}}}} \varphi(z) = \frac{1}{1+e^{-z}}

which has a nice derivative of:

{\displaystyle {\frac {d\varphi }{dz}}(z)=\varphi (z)(1-\varphi (z))}{\displaystyle {\frac {d\varphi }{dz}}(z)=\varphi (z)(1-\varphi (z))}

Finding the derivative of the error[edit]

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

{\displaystyle {\frac {\partial E}{\partial w_{ij}}}={\frac {\partial E}{\partial o_{j}}}{\frac {\partial o_{j}}{\partial \mathrm {net_{j}} }}{\frac {\partial \mathrm {net_{j}} }{\partial w_{ij}}}}\frac{\partial E}{\partial w_{ij}} = \frac{\partial E}{\partial o_j} \frac{\partial o_j}{\partial\mathrm{net_j}} \frac{\partial \mathrm{net_j}}{\partial w_{ij}}

In the last factor of the right-hand side of the above, only one term in the sum {\displaystyle \mathrm {net_{j}} }\mathrm{net_j} depends on {\displaystyle w_{ij}}w_{ij}, so that

{\displaystyle {\frac {\partial \mathrm {net_{j}} }{\partial w_{ij}}}={\frac {\partial }{\partial w_{ij}}}\left(\sum _{k=1}^{n}w_{kj}o_{k}\right)=o_{i}}\frac{\partial \mathrm{net_j}}{\partial w_{ij}} = \frac{\partial}{\partial w_{ij}}\left(\sum_{k=1}^{n}w_{kj}o_k\right) = o_i.

If the neuron is in the first layer after the input layer, {\displaystyle o_{i}}o_i is just {\displaystyle x_{i}}x_{i}.

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

{\displaystyle {\frac {\partial o_{j}}{\partial \mathrm {net_{j}} }}={\frac {\partial }{\partial \mathrm {net_{j}} }}\varphi (\mathrm {net_{j}} )=\varphi (\mathrm {net_{j}} )(1-\varphi (\mathrm {net_{j}} ))}\frac{\partial o_j}{\partial\mathrm{net_j}} = \frac {\partial}{\partial \mathrm{net_j}}\varphi(\mathrm{net_j}) = \varphi(\mathrm{net_j})(1-\varphi(\mathrm{net_j}))

This is the reason why backpropagation requires the activation function to be differentiable.

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

{\displaystyle {\frac {\partial E}{\partial o_{j}}}={\frac {\partial E}{\partial y}}={\frac {\partial }{\partial y}}{\frac {1}{2}}(t-y)^{2}=y-t}\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 {\displaystyle j}j is in an arbitrary inner layer of the network, finding the derivative {\displaystyle E}E with respect to {\displaystyle o_{j}}o_j is less obvious.

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

{\displaystyle {\frac {\partial E(o_{j})}{\partial o_{j}}}={\frac {\partial E(\mathrm {net} _{u},\mathrm {net} _{v},\dots ,\mathrm {net} _{w})}{\partial o_{j}}}}\frac{\partial E(o_j)}{\partial o_j} = \frac{\partial E(\mathrm{net}_u, \mathrm{net}_v, \dots, \mathrm{net}_w)}{\partial o_j}

and taking the total derivative with respect to {\displaystyle o_{j}}o_j, a recursive expression for the derivative is obtained:

{\displaystyle {\frac {\partial E}{\partial o_{j}}}=\sum _{l\in L}\left({\frac {\partial E}{\partial \mathrm {net} _{l}}}{\frac {\partial \mathrm {net} _{l}}{\partial o_{j}}}\right)=\sum _{l\in L}\left({\frac {\partial E}{\partial o_{l}}}{\frac {\partial o_{l}}{\partial \mathrm {net} _{l}}}w_{jl}\right)}\frac{\partial E}{\partial o_j} = \sum_{l \in L} \left(\frac{\partial E}{\partial \mathrm{net}_l}\frac{\partial \mathrm{net}_l}{\partial o_j}\right) = \sum_{l \in L} \left(\frac{\partial E}{\partial o_{l}}\frac{\partial o_{l}}{\partial \mathrm{net}_l}w_{jl}\right)

Therefore, the derivative with respect to {\displaystyle o_{j}}o_j can be calculated if all the derivatives with respect to the outputs {\displaystyle o_{l}}o_l of the next layer – the one closer to the output neuron – are known.

Putting it all together:

{\displaystyle {\dfrac {\partial E}{\partial w_{ij}}}=\delta _{j}o_{i}}\dfrac{\partial E}{\partial w_{ij}} = \delta_{j} o_{i}

with

{\displaystyle \delta _{j}={\frac {\partial E}{\partial o_{j}}}{\frac {\partial o_{j}}{\partial \mathrm {net_{j}} }}={\begin{cases}(o_{j}-t_{j})o_{j}(1-o_{j})&{\mbox{if }}j{\mbox{ is an output neuron,}}\\(\sum _{l\in L}\delta _{l}w_{jl})o_{j}(1-o_{j})&{\mbox{if }}j{\mbox{ is an inner neuron.}}\end{cases}}}{\displaystyle \delta _{j}={\frac {\partial E}{\partial o_{j}}}{\frac {\partial o_{j}}{\partial \mathrm {net_{j}} }}={\begin{cases}(o_{j}-t_{j})o_{j}(1-o_{j})&{\mbox{if }}j{\mbox{ is an output neuron,}}\\(\sum _{l\in L}\delta _{l}w_{jl})o_{j}(1-o_{j})&{\mbox{if }}j{\mbox{ is an inner neuron.}}\end{cases}}}

To update the weight {\displaystyle w_{ij}}w_{ij} using gradient descent, one must choose a learning rate, {\displaystyle \alpha }\alpha . The change in weight, which is added to the old weight, is equal to the product of the learning rate and the gradient, multiplied by {\displaystyle -1}-1:

{\displaystyle \Delta w_{ij}=-\alpha {\frac {\partial E}{\partial w_{ij}}}={\begin{cases}-\alpha o_{i}(o_{j}-t_{j})o_{j}(1-o_{j})&{\mbox{if }}j{\mbox{ is an output neuron,}}\\-\alpha o_{i}(\sum _{l\in L}\delta _{l}w_{jl})o_{j}(1-o_{j})&{\mbox{if }}j{\mbox{ is an inner neuron.}}\end{cases}}}{\displaystyle \Delta w_{ij}=-\alpha {\frac {\partial E}{\partial w_{ij}}}={\begin{cases}-\alpha o_{i}(o_{j}-t_{j})o_{j}(1-o_{j})&{\mbox{if }}j{\mbox{ is an output neuron,}}\\-\alpha o_{i}(\sum _{l\in L}\delta _{l}w_{jl})o_{j}(1-o_{j})&{\mbox{if }}j{\mbox{ is an inner neuron.}}\end{cases}}}

The {\displaystyle \textstyle -1}\textstyle -1 is required in order to update in the direction of a minimum, not a maximum, of the error function.

For a single-layer network, this expression becomes the Delta Rule. To better understand how backpropagation works, here is an example to illustrate it: The Back Propagation Algorithm, page 20.

Extension[edit]

The choice of learning rate {\textstyle \eta }{\textstyle \eta } is important for the method, since a high value can cause too strong a change, causing the minimum to be missed, while a too low learning rate slows the training unnecessarily.

Various optimizations of backpropagation, such as Quickprop, are primarily aimed at speeding up the error minimization; other improvements mainly try to increase reliability.

Backpropagation with adaptive learning rate[edit]

In order to avoid oscillation inside the network, such as alternating connection weights, and to improve the rate of convergence, there are refinements of this algorithm that use an adaptive learning rate.[4]

Backpropagation with inertia[edit]

By using a variable inertia term (Momentum) {\textstyle \alpha }{\textstyle \alpha } the gradient and the last change can be weighted such that the weight adjustment additionally depends on the previous change. If the Momentum {\textstyle \alpha }{\textstyle \alpha } is equal to 0, the change depends solely on the gradient, and a value of 1 will only depend on the last change.

Similar to a ball rolling down a mountain, whose current speed is determined not only by the current slope of the mountain but also by its own inertia, inertia can be added to backpropagation:

{\displaystyle \Delta w_{ij}(t+1)=(1-\alpha )\eta \delta _{j}x_{i}+\alpha \Delta w_{ij}(t)}
{\displaystyle \Delta w_{ij}(t+1)=(1-\alpha )\eta \delta _{j}x_{i}+\alpha \Delta w_{ij}(t)}
where:
{\textstyle \Delta w_{ij}(t+1)}{\textstyle \Delta w_{ij}(t+1)}  is the change in weight   {\textstyle w_{ij}(t+1)}{\textstyle w_{ij}(t+1)}  in the connection of neuron   {\textstyle i}{\textstyle i}  to neuron   {\textstyle j}{\textstyle j}  at time   {\textstyle (t+1)}{\textstyle (t+1)},
{\textstyle \eta }{\textstyle \eta }  a learning rate,
{\textstyle \delta _{j}}{\textstyle \delta _{j}}  the error signal of neuron   {\textstyle j}{\textstyle j}  and
{\textstyle x_{i}}{\textstyle x_{i}}  the input of neuron   {\textstyle i}{\textstyle i},
{\textstyle \alpha }{\textstyle \alpha }  the influence of the inertial term   {\textstyle \Delta w_{ij}(t)}{\textstyle \Delta w_{ij}(t)}. This corresponds to the weight change at the previous point in time.

This will depend on the current weight change {\textstyle (t+1)}{\textstyle (t+1)} both from the current gradient of the error function (slope of the mountain, 1st summand), as well as from the weight change from the previous point in time (inertia, 2nd summand).

With inertia, the previous problems of the backpropagation getting stuck in steep ravines and flat plateaus are avoided. Since, for example, the gradient of the error function becomes very small in flat plateaus, it would immediately lead to a "deceleration" of the gradient descent. This "deceleration" is delayed by the addition of the inertia term so that a flat plateau can be overcome more quickly.

Modes of learning[edit]

There are two modes of learning to choose from: stochastic and batch. In stochastic learning, each propagation is followed immediately by a weight update. In batch learning many propagations occur before updating the weights, accumulating errors over the samples within a batch. Stochastic learning introduces "noise" into the gradient descent process, using the local gradient calculated from one data point; this reduces the chance of the network getting stuck in a local minima. Yet batch learning typically yields a faster, more stable descent to a local minima, since each update is performed in the direction of the average error of the batch samples. In modern applications a common compromise choice is to use "mini-batches", meaning batch learning but with a batch of small size and with stochastically selected samples.

Training data collection[edit]

Online learning is used for dynamic environments that provide a continuous stream of new training data patterns. Offline learning makes use of a training set of static patterns.

Limitations[edit]

Gradient descent can find the local minimum instead of the global minimum
  • 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 plateaux 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 in a 2015 review article, Yann LeCun et al. argue that in many practical problems, it is not.[5]
  • Backpropagation learning does not require normalization of input vectors; however, normalization could improve performance.[6]

History[edit]

See also:   History of Perceptron

According to various sources,[7][8][9][10] basics of continuous backpropagation were derived in the context of control theory by Henry J. Kelley[11] in 1960 and by Arthur E. Bryson in 1961,[12] using principles of dynamic programming. In 1962, Stuart Dreyfus published a simpler derivation based only on the chain rule.[13] Vapnik cites reference[14] in his book on Support Vector MachinesArthur E. Bryson and Yu-Chi Ho described it as a multi-stage dynamic system optimization method in 1969.[15][16]

In 1970, Seppo Linnainmaa finally published the general method for automatic differentiation (AD) of discrete connected networks of nested differentiable functions.[17][18] This corresponds to the modern version of backpropagation which is efficient even when the networks are sparse.[9][10][19][20]

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

In 1986, David E. RumelhartGeoffrey E. Hinton and Ronald J. Williams showed through computer experiments that this method can generate useful internal representations of incoming data in hidden layers of neural networks.[1] [24] In 1993, Eric A. Wan was the first[9] to win an international pattern recognition contest through backpropagation.[25]

During the 2000s it fell out of favour but has returned again in the 2010s, now able to train much larger networks using huge modern computing power such as GPUs. In the context of this new hardware it is sometimes referred to as deep learning, though this is often seen[by whom?] as marketing hype. For example, in 2014, backpropagation was used to train a deep neural network for state of the art speech recognition.[26]

Notes[edit]

  1. Jump up^ One may notice that multi-layer neural networks use non-linear activation functions, so an example with linear neurons seems obscure. However, even though the error surface of multi-layer networks are much more complicated, locally they can be approximated by a paraboloid. Therefore, linear neurons are used for simplicity and easier understanding.
  2. Jump up^ There can be multiple output neurons, in which case the error is the squared norm of the difference vector.

<think>嗯,用户让我介绍一下反向传播(backpropagation)和循环神经网络(RNN)。首先,我需要确保自己正确理解这两个概念,然后以清晰的结构解释给用户。用户可能有一定的机器学习基础,但可能需要从基础讲起,所以得平衡深度和易懂性。 首先,反向传播是神经网络训练中的核心算法,用于计算梯度,优化权重。我得先解释它的基本原理,比如链式法则,前向传播和反向传播的过程。然后,可能需要提到它的优缺点,比如计算高效但可能有梯度消失的问题。 然后是RNN,这是处理序列数据的网络结构,和传统神经网络的不同之处在于其隐藏状态的传递。需要解释RNN的结构,比如时间展开后的循环连接,以及它在处理时间序列、自然语言处理中的应用。同时,RNN的变体如LSTM、GRU可以简要提及,以说明如何解决长依赖问题。 要注意用户的系统级指令,比如数学公式用$...$和$$...$$格式。在解释反向传播时,可能需要写出损失函数对权重的偏导,例如使用链式法则的公式。对于RNN,可能需要写出隐藏状态的计算公式,如$h_t = \tanh(W_{hh}h_{t-1} + W_{xh}x_t + b_h)$,并确保这些公式正确使用LaTeX语法。 还要考虑用户可能的疑问点,比如为什么RNN需要反向传播,或者RNN在处理长序列时的挑战。这时候需要在解释中自然地融入这些问题的答案,比如在RNN部分提到梯度消失或爆炸的问题,以及如何通过BPTT(随时间反向传播)来训练。 结构方面,先分别介绍两个概念,再讨论它们的联系。例如,RNN在训练时使用反向传播的一种变体,即BPTT。需要比较两者的不同,比如BPTT需要考虑时间步的展开,而标准反向传播用于前馈网络。 需要检查是否有遗漏的关键点,比如反向传播的具体步骤,或者RNN的不同架构。同时确保语言简洁,避免过于技术化,但保持准确性。最后,总结两者的关系和各自的应用场景,帮助用户形成整体理解。</think>好的!我将分步介绍反向传播(Backpropagation)和循环神经网络(RNN),并说明它们的核心原理与联系。 --- ### 一、反向传播(Backpropagation) 反向传播是训练人工神经网络的**核心算法**,其本质是通过链式法则高效计算损失函数对网络参数的梯度。 #### 1. 核心思想 - **前向传播**:输入数据通过网络逐层计算,最终得到预测值。 - **损失计算**:比较预测值与真实值的差异,得到损失函数值,例如均方误差: $$ L = \frac{1}{N}\sum_{i=1}^{N}(y_i - \hat{y}_i)^2 $$ - **反向传播**:从输出层向输入层反向传递误差,利用链式法则逐层计算梯度: $$ \frac{\partial L}{\partial W^{(k)}} = \frac{\partial L}{\partial a^{(k)}} \cdot \frac{\partial a^{(k)}}{\partial z^{(k)}} \cdot \frac{\partial z^{(k)}}{\partial W^{(k)}} $$ 其中 $W^{(k)}$ 是第 $k$ 层权重,$a^{(k)}$ 是激活值,$z^{(k)}$ 是加权输入。 #### 2. 关键特点 - **高效性**:通过动态规划避免重复计算梯度。 - **局限性**:梯度可能消失(如使用 Sigmoid 激活函数)或爆炸(权重初始化不当)。 --- ### 二、循环神经网络(RNN) RNN 是专门处理**序列数据**的神经网络,通过引入“隐状态”记忆历史信息。 #### 1. 核心结构 - **时间展开形式**:在每个时间步 $t$,输入 $x_t$ 与前一时刻隐状态 $h_{t-1}$ 结合: $$ h_t = \tanh(W_{hh}h_{t-1} + W_{xh}x_t + b_h) $$ $$ y_t = W_{hy}h_t + b_y $$ - **参数共享**:所有时间步共享同一组参数 $W_{hh}, W_{xh}, W_{hy}$。 #### 2. 典型应用 - 时间序列预测(如股票价格) - 自然语言处理(如机器翻译、文本生成) - 语音识别 #### 3. 挑战与改进 - **长依赖问题**:传统 RNN 难以捕捉远距离时序依赖 → 改进方案:LSTM、GRU。 - **训练方法**:使用**随时间反向传播(BPTT)**,即对展开后的时间序列执行反向传播。 --- ### 三、反向传播与 RNN 的关系 1. **训练机制**:RNN 通过 BPTT 训练,本质是反向传播在时间维度上的扩展。 2. **梯度问题**:RNN 更容易出现梯度消失/爆炸,因梯度需跨多个时间步传递。 3. **解决方案**:LSTM/GRU 通过门控机制缓解梯度问题;梯度裁剪可应对梯度爆炸。 --- ### 四、总结对比 | **特性** | 反向传播(Backpropagation) | 循环神经网络(RNN) | |-------------------|----------------------------------|----------------------------------| | **目标** | 计算梯度以优化网络参数 | 处理序列数据,捕捉时序依赖 | | **计算复杂度** | $O(n)$(n 为参数数量) | $O(T \cdot n)$(T 为时间步长度) | | **核心挑战** | 梯度消失/爆炸 | 长时序依赖、参数共享的稳定性 | 希望以上解释能帮助你理解两者的核心概念!如果有具体问题,欢迎进一步讨论。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值