CroftSoft
 
-About
-Contract
-Library
--Books
---AJGP
--Code
--Courses
--Links
--Media
--Tutorials
-People
--David
---Résumé
--Shannon
-Portfolio
-Update
 

Amazon.com Platinum Visa Card
 
 

Backpropagation

David Wallace Croft

2005-02-18

Introduction

This is a derivation of a popular neural network training algorithm known as backpropagation. It is commonly used with feed-forward multilayer perceptrons.

To see backpropagation in action, check out the applet BackpropXOR in the CroftSoft Collection.

Definitions and Identities

  1. Sigmoid Function

    σ ( x ) = 1 ( 1 + -x )

  2. Derivative of the Sigmoid Function

    σ ' ( x ) = σ ( x ) * [ 1 - σ ( x ) ]

Simplest Case

This is a derivation of the backpropagation neural network training algorithm for the simplest case: a two-layer network with one neuron in each layer. In this derivation, all of the variables are scalars. Deriving the learning rule for the simplest case makes backpropagation easier to understand when vectors and matrices are introduced later.

s → v → b → σ → h → w → a → σ → r

A signal (s) is the input to the first layer hidden neuron. It is multiplied by the first layer weight (v). The weighted input (b) is then squashed by the nonlinear neuron to fall between zero and one using the sigmoidal function (σ). The output of the hidden neuron (h) is then multiplied by the weight (w). The weighted input from the hidden neuron (a) is fed to the squashing function of the second layer output neuron. The difference between the desired response (d) and the actual response (r) of the output neuron is the error (e). The objective function (l) is the scaled square of the error (e).

  1. Objective Function

    l = ½ * e 2

  2. Error Function

    e = d - r

  3. Response from Output Neuron

    r = σ ( a )

  4. Weighted Input from Hidden Neuron to Output Neuron

    a = w * h

  5. Hidden Neuron Output

    h = σ ( b )

  6. Weighted Input to Hidden Neuron

    b = v * s

Output Layer

We seek to minimize the objective function (l) by modifying the weight (w) to the output layer. This is done by taking the partial derivative of the objective function with respect to the weights. This derivative is then used to modify the weight using a gradient descent algorithm.

  1. Gradient for Output Layer Weight, Chain Rule

    l(w) w = l(e) e * e(r) r * r(a) a * a(w) w

  2. Output Layer Weight Gradient, First Term

    l(e) e = ( ½ * e 2 ) e = e = d - r

  3. Output Layer Weight Gradient, Second Term

    e(r) r = ( d - r ) r = -1

  4. Output Layer Weight Gradient, Third Term

    r(a) a = σ ( a ) a = σ ( a ) * ( 1 - σ ( a ) ) = r * ( 1 - r )

  5. Output Layer Weight Gradient, Fourth Term

    a(w) w = ( w * h ) w = h

  6. Gradient for Output Layer Weight, Combined Terms

    l(w) w = [ d - r ] * [ -1 ] * [ r * ( 1 - r ) ] * [ h ]

Hidden Layer

We also seek to minimize the objective function (l) by modifying the weight (v) to the hidden layer. The derivation of the first three terms in the gradient for the hidden layer weight are skipped as they are the same as the first three terms in the gradient for the output layer derived previously.

  1. Gradient for Hidden Layer Weight, Chain Rule

    l(v) v = l(e) e * e(r) r * r(a) a * a(h) h * h(b) b * b(v) v

  2. Hidden Layer Weight Gradient, Fourth Term

    a(h) h = ( w * h ) h = w

  3. Hidden Layer Weight Gradient, Fifth Term

    h(b) b = σ ( b ) b = σ ( b ) * ( 1 - σ ( b ) ) = h * ( 1 - h )

  4. Hidden Layer Weight Gradient, Sixth Term

    b(v) v = ( v * s ) v = s

  5. Gradient for Hidden Layer Weight, Combined Terms

    l(v) v = [ d - r ] * [ -1 ] * [ r * ( 1 - r ) ] * [ w ] * [ h * ( 1 - h ) ] * [ s ]

Local Gradient

We noted that the first three terms of the gradients for the output layer and the hidden layer are the same. The negative product of these three terms is the local gradient. The local gradient can be computed for the output layer and then reused for the hidden layer.

  1. Local Gradient for Output Neuron

    δ o = - l(a) a = - l(e) e * e(r) r * r(a) a = e * r * ( 1 - r )

  2. Output Layer Gradient Abbreviated

    l(w) w = - δ o * h

  3. Hidden Layer Gradient Abbreviated

    l(v) v = - δ o * w * h * ( 1 - h ) * s

Backpropagation

The local gradient shows how the objective function decreases as the weighted input to the neuron increases. The local gradient for an output neuron depends on the error (e). The local gradients for hidden layer neurons, however, depend on the local gradients of the following layer. Thus the computation of the local gradients must be propagated from the back layer of the network to the front. The weight gradients can then be expressed as functions of the local gradients and the unweighted inputs.

  1. Local Gradient for Hidden Neuron

    δ h = - l(b) b = - l(e) e * e(r) r * r(a) a * a(h) h * h(b) b

  2. Local Gradient Backpropagation

    δ h = δ o * a(h) h * h(b) b

  3. The Pattern for Hidden Layers

    δ h = δ o * w * h * ( 1 - h )

  4. Hidden Layer Gradient Abbreviated Further

    l(v) v = - δ h * s

Gradient Descent

Now that we have the gradient of the objective function with respect to the weights in terms of the of local gradients, we can incrementally decrease the objective function, and therefore the overall error, by shifting the weights.

  1. Weight Update Rule

    w (t+1) = w (t) +Δw

  2. Descend the Gradient

    Δw = - η * l(w) w

  3. A Negative Becomes a Positive

    Δw = η * δ o * h

  4. The Weight Update Rule Revised

    w (t+1) = w (t) + η * δ o * h

  5. Similar Pattern for Hidden Weights

    v (t+1) = v (t) + η * δ h * s

Links

 
 

Creative Commons License
Copyright 2005 CroftSoft Inc.
You may copy this webpage under the terms of the
Creative Commons Attribution License.

Shop at Amazon.com