# Deriving gradients using the backpropagation idea

### From Ufldl

(Created page with "== Introduction == In the section on the backpropagation algorithm, you were briefly introduced to backpropagation as a means of deriving gradien...") |
|||

Line 26: | Line 26: | ||

<li><math>a^{(l)}_i</math> is the activation of the <math>i</math>th unit in the <math>l</math>th layer | <li><math>a^{(l)}_i</math> is the activation of the <math>i</math>th unit in the <math>l</math>th layer | ||

<li><math>A \bullet B</math> is the Hadamard or element-wise product, which for <math>r \times c</math> matrices <math>A</math> and <math>B</math> yields the <math>r \times c</math> matrix <math>C = A \bullet B</math> such that <math>C_{r, c} = A_{r, c} \cdot B_{r, c}</math> | <li><math>A \bullet B</math> is the Hadamard or element-wise product, which for <math>r \times c</math> matrices <math>A</math> and <math>B</math> yields the <math>r \times c</math> matrix <math>C = A \bullet B</math> such that <math>C_{r, c} = A_{r, c} \cdot B_{r, c}</math> | ||

- | <li><math>f^{(l | + | <li><math>f^{(l)}</math> is the activation function for units in the <math>l</math>th layer |

</ul> | </ul> | ||

Line 51: | Line 51: | ||

</ol> | </ol> | ||

- | [[File:Backpropagation Method Example 1.png]] | + | [[File:Backpropagation Method Example 1.png | 400px]] |

=== Example 2: Smoothed topographic L1 sparsity penalty in sparse coding === | === Example 2: Smoothed topographic L1 sparsity penalty in sparse coding === | ||

Line 60: | Line 60: | ||

We would like to find <math>\nabla_s \sum{ \sqrt{Vss^T + \epsilon} }</math>. As above, let's see this term as an instantiation of a neural network: | We would like to find <math>\nabla_s \sum{ \sqrt{Vss^T + \epsilon} }</math>. As above, let's see this term as an instantiation of a neural network: | ||

- | [[File:Backpropagation Method Example 2.png]] | + | [[File:Backpropagation Method Example 2.png | 600px]] |

## Revision as of 08:05, 29 May 2011

## Contents |

## Introduction

In the section on the backpropagation algorithm, you were briefly introduced to backpropagation as a means of deriving gradients for learning in the sparse autoencoder. It turns out that together with matrix calculus, this provides a powerful method and intuition for deriving gradients for more complex matrix functions (functions from matrices to the reals, or symbolically, from .

First, recall the backpropagation idea, which we present in a modified form appropriate for our purposes below:

- For
- For each node
*i*in layer*l*, set

- For each node
- Compute the desired partial derivatives,

Quick notation recap:

*l*is the number of layers in the neural network*n*_{l}is the number of neurons in the*l*th layer- is the weight from the
*i*th unit in the*l*th layer to the*j*th unit in the (*l*+ 1)th layer - is the input to the
*i*th unit in the*l*th layer - is the activation of the
*i*th unit in the*l*th layer - is the Hadamard or element-wise product, which for matrices
*A*and*B*yields the matrix such that *f*^{(l)}is the activation function for units in the*l*th layer

Notice that we don't consider an objective function in this case, and we allow each layer to have a different activation function *f*^{(l)}. This will be useful in allowing us to compute the gradients of functions of matrices.

## The method

To compute the gradient with respect to some matrix *X* of a complicated function of matrices, it may be helpful to consider the function as a complicated multi-layer neural network, if possible. We will use two functions from the section on sparse coding to illustrate this.

### Example 1: Objective for weight matrix in sparse coding

Recall the objective function for the weight matrix *A*, given the feature matrix *s*:

We would like to find the gradient of *J* with respect to *A*, or in symbols, . Since the objective function is a sum of two terms in *A*, the gradient is the sum of gradients of each of the individual terms. The gradient of the second term is trivial, so we will consider the gradient of the first term instead.

The first term, , can be seen as an instantiation of neural network taking *s* as an input, and proceeding in four steps, as described and illustrated in the paragraph and diagram below:

- Apply
*A*as the weights from the first layer to the second layer. - Subtract
*x*from the activation of the second layer, which uses the identity activation function. - Pass this unchanged to the third layer, via identity weights. Use the square function as the activation function for the third layer.
- Sum all the activations of the third layer.

### Example 2: Smoothed topographic L1 sparsity penalty in sparse coding

Recall the smoothed topographic L1 sparsity penalty on *s* in sparse coding:

We would like to find . As above, let's see this term as an instantiation of a neural network: