Presentation on theme: "Backpropagation Learning Algorithm. The backpropagation algorithm was used to train the multi layer perception MLP MLP used to describe any general Feedforward."— Presentation transcript:
Backpropagation Learning Algorithm
The backpropagation algorithm was used to train the multi layer perception MLP MLP used to describe any general Feedforward (no recurrent connections) Neural Network FNN However, we will concentrate on nets with units arranged in layers x1x1 xnxn
Architecture of BP Nets Multi-layer, feed-forward networks have the following characteristics: -They must have at least one hidden layer –Hidden units must be non-linear units (usually with sigmoid activation functions) –Fully connected between units in two consecutive layers, but no connection between units within one layer. –For a net with only one hidden layer, each hidden unit receives input from all input units and sends output to all output units –Number of output units need not equal number of input units – Number of hidden units per layer can be more or less than input or output units
Other Feedforward Networks Madaline –Multiple adalines (of a sort) as hidden nodes Adaptive multi-layer networks –Dynamically change the network size (# of hidden nodes) Networks of radial basis function (RBF) –e.g., Gaussian function –Perform better than sigmoid function (e.g., interpolation in function approximation
Introduction to Backpropagation In 1969 a method for learning in multi-layer network, Backpropagation (or generalized delta rule), was invented by Bryson and Ho. It is best-known example of a training algorithm. Uses training data to adjust weights and thresholds of neurons so as to minimize the networks errors of prediction. Slower than gradient descent. Easiest algorithm to understand Backpropagation works by applying the gradient descent rule to a feedforward network.
How many hidden layers and hidden units per layer? –Theoretically, one hidden layer (possibly with many hidden units) is sufficient for any L2 functions –There is no theoretical results on minimum necessary # of hidden units (either problem dependent or independent) –Practical rule : n = # of input units; p = # of hidden units For binary/bipolar data: p = 2n For real data: p >> 2n –Multiple hidden layers with fewer units may be trained faster for similar quality in some applications
Training a BackPropagation Net Feedforward training of input patterns –each input node receives a signal, which is broadcast to all of the hidden units –each hidden unit computes its activation which is broadcast to all output nodes Back propagation of errors –each output node compares its activation with the desired output –based on these differences, the error is propagated back to all previous nodes Delta Rule Adjustment of weights –weights of all links computed simultaneously based on the errors that were propagated back
Three-layer back-propagation neural network
Generalized delta rule Delta rule only works for the output layer. Backpropagation, or the generalized delta rule, is a way of creating desired values for hidden layers
Description of Training BP Net: Feedforward Stage 1. Initialize weights with small, random values 2. While stopping condition is not true –for each training pair (input/output): each input unit broadcasts its value to all hidden units each hidden unit sums its input signals & applies activation function to compute its output signal each hidden unit sends its signal to the output units each output unit sums its input signals & applies its activation function to compute its output signal
Training BP Net: Backpropagation stage 3. Each output computes its error term, its own weight correction term and its bias(threshold) correction term & sends it to layer below 4. Each hidden unit sums its delta inputs from above & multiplies by the derivative of its activation function; it also computes its own weight correction term and its bias correction term
Training a Back Prop Net: Adjusting the Weights 5.Each output unit updates its weights and bias 6. Each hidden unit updates its weights and bias –Each training cycle is called an epoch. The weights are updated in each cycle –It is not analytically possible to determine where the global minimum is. Eventually the algorithm stops in a low point, which may just be a local minimum.
How long should you train? Goal: balance between correct responses for training patterns & correct responses for new patterns (memorization v. generalization) In general, network is trained until it reaches an acceptable error rate (e.g. 95%) If train too long, you run the risk of overfitting
Graphical description of of training multi-layer neural network using BP algorithm To apply the BP algorithm to the following FNN
To teach the neural network we need training data set. The training data set consists of input signals (x 1 and x 2 ) assigned with corresponding target (desired output) z. The network training is an iterative process. In each iteration weights coefficients of nodes are modified using new data from training data set. After this stage we can determine output signals values for each neuron in each network layer. Pictures below illustrate how signal is propagating through the network, Symbols w(x m )n represent weights of connections between network input x m and neuron n in input layer. Symbols y n represents output signal of neuron n.
Propagation of signals through the hidden layer. Symbols w mn represent weights of connections between output of neuron m and input of neuron n in the next layer.
Propagation of signals through the output layer. In the next algorithm step the output signal of the network y is compared with the desired output value (the target), which is found in training data set. The difference is called error signal of output layer neuron.
It is impossible to compute error signal for internal neurons directly, because output values of these neurons are unknown. For many years the effective method for training multilayer networks has been unknown. Only in the middle eighties the backpropagation algorithm has been worked out. The idea is to propagate error signal (computed in single teaching step) back to all neurons, which output signals were input for discussed neuron.
The weights' coefficients w mn used to propagate errors back are equal to this used during computing output value. Only the direction of data flow is changed (signals are propagated from output to inputs one after the other). This technique is used for all network layers. If propagated errors came from few neurons they are added. The illustration is below:
When the error signal for each neuron is computed, the weights coefficients of each neuron input node may be modified. In formulas below df(e)/de represents derivative of neuron activation function (which weights are modified).
Coefficient affects network teaching speed. There are a few techniques to select this parameter. The first method is to start teaching process with large value of the parameter. While weights coefficients are being established the parameter is being decreased gradually. The second, more complicated, method starts teaching with small parameter value. During the teaching process the parameter is being increased when the teaching is advanced and then decreased again in the final stage.
Training Algorithm 1 Step 0: Initialize the weights to small random values Step 1: Feed the training sample through the network and determine the final output Step 2: Compute the error for each output unit, for unit k it is: k = (t k – y k )f’(y_in k ) Required output Actual output Derivative of f
Training Algorithm 2 Step 3: Calculate the weight correction term for each output unit, for unit k it is: w jk = k z j A small constant Hidden layer signal
Training Algorithm 3 Step 4: Propagate the delta terms (errors) back through the weights of the hidden units where the delta input for the j th hidden unit is: _in j = k w jk k=1 m The delta term for the j th hidden unit is: j = in j f’(z_in j ) where f’(z_in j )= f(z_in j )[1- f(z_in j )]
Training Algorithm 4 Step 5: Calculate the weight correction term for the hidden units: Step 6: Update the weights: Step 7: Test for stopping (maximum cylces, small changes, etc) w ij = j x i w jk (new) = w jk (old) + w jk
Options There are a number of options in the design of a backprop system –Initial weights – best to set the initial weights (and all other free parameters) to random numbers inside a small range of values (say: – 0.5 to 0.5) –Number of cycles – tend to be quite large for backprop systems –Number of neurons in the hidden layer – as few as possible
Example The XOR function could not be solved by a single layer perceptron network The function is: X Y F
XOR Architecture x y f v 21 v 11 v 31 f v 22 v 12 v 32 f w 21 w 11 w
Initial Weights Randomly assign small weight values: x y f.21 f -.4 .25.1 f -.2
Feedfoward – 1 st Pass x y f.21 f -.4 .25.1 f -.2 Training Case: (0 0 0) y_in 1 = -.3(1) +.21(0) +.25(0) = -.3 f(y j )= y_in i e Activation function f: f =.43 y_in 2 =.25(1) -.4(0) +.1(0) f =.56 1 y_in 3 = -.4(1) -.2(.43) +.3(.56) = f =.42 (not 0)
Final Result After about 500 iterations: x y f 1 f 1 f -2
More details for gradient descent method + MLP to whom may have interest
In the perceptron/single layer nets, we used gradient descent on the error function to find the correct weights: w ji = (t j - y j ) x i We see that errors/updates are local to the node ie the change in the weight from node i to output j (w ji ) is controlled by the input that travels along the connection and the error signal from output j x1x1 x2x2 But with more layers how are the weights for the first 2 layers found when the error is computed for layer 3 only? There is no direct error signal for the first layers!!!!! ? x1x1 (t j - y j )
Credit assignment problem Problem of assigning ‘credit’ or ‘blame’ to individual elements involved in forming overall response of a learning system (hidden units) In neural networks, problem relates to deciding which weights should be altered, by how much and in which direction. Analogous to deciding how much a weight in the early layer contributes to the output and thus the error We therefore want to find out how weight w ij affects the error ie we want:
Backpropagation learning algorithm ‘BP’ Solution to credit assignment problem in MLP Rumelhart, Hinton and Williams (1986) BP has two phases: Forward pass phase: computes ‘functional signal’, feedforward propagation of input pattern signals through network
Backpropagation learning algorithm ‘BP’ Solution to credit assignment problem in MLP. Rumelhart, Hinton and Williams (1986) (though actually invented earlier in a PhD thesis relating to economics) BP has two phases: Forward pass phase: computes ‘functional signal’, feedforward propagation of input pattern signals through network Backward pass phase: computes ‘error signal’, propagates the error backwards through network starting at output units (where the error is the difference between actual and desired output values)
xnxn x1x1 x2x2 Inputs x i Outputs y j Two-layer networks y1y1 ymym 2nd layer weights w ij from j to i 1st layer weights v ij from j to i Outputs of 1st layer z i
We will concentrate on three-layer, but could easily generalize to more layers z i (t) = g( j v ij (t) x j (t) ) at time t = g ( u i (t) ) y i (t) = g( j w ij (t) z j (t) ) at time t = g ( a i (t) ) a/u known as activation, g the activation function biases set as extra weights
Forward pass Weights are fixed during forward and backward pass at time t 1. Compute values for hidden units 2. compute values for output units xixi v ji (t) w kj (t) zjzj ykyk
Backward Pass Will use a sum of squares error measure. For each training pattern we have: where d k is the target value for dimension k. We want to know how to modify weights in order to decrease E. Use gradient descent ie both for hidden units and output units
How error for pattern changes as function of change in network input to unit j How net input to unit j changes as a function of change in weight w both for hidden units and output units Term A Term B The partial derivative can be rewritten as product of two terms using chain rule for partial differentiation
Term A Let (error terms). Can evaluate these by chain rule: Term B first:
For output units we therefore have:
For hidden units must use the chain rule:
Backward Pass Weights here can be viewed as providing degree of ‘credit’ or ‘blame’ to hidden units jj kk ii w ki w ji i = g’(a i ) j w ji j
Combining A+B gives So to achieve gradient descent in E should change weights by v ij (t+1)-v ij (t) = i (t) x j (n) w ij (t+1)-w ij (t) = i (t) z j (t) Where is the learning rate parameter (0 < <=1)
Summary Weight updates are local output unit hidden unit