## Introduction
Previously we wrote a short introduction to neural networks, which discusses backpropagation as the training method of choice, described as: "simply a way of minimizing the loss function, or error, of the network by propagating errors backward through the network and adjusting weights accordingly."
This brief writeup is meant to shed light on the mathematics behind backpropagation, deriving (with substantial justification) the weight changing algorithm for a feedforward neural network by means of a standard gradient descent.
## The feedforward algorithm
The activation of a neural network is iteratively defined by
ynxn+1=f(xn)=wnynwhere yn is the output vector at layer n, f is the activation function, xn is the input vector at layer n, and wn is the weight matrix between layers n and n+1. The first layer is n=1 and the last layer is n=N.
## The backpropagation algorithm
The error of the network is defined by
c=21(yN−t)2The error gradient of the input vector at a layer n is defined as
δn=∂xn∂cThe error gradient of the input vector at the last layer N is
δN=∂xN∂c=∂xN∂21(yN−t)2=(∂yN∂21(yN−t)2)∂xN∂yN=(yN−t)∂xN∂f(xN)=(yN−t)f′(xN)The error gradient of the input vector at an inner layer n is
δn=∂xn∂c=∂xn+1∂c∂xn∂xn+1=δn+1∂xn∂xn+1=δn+1∂xn∂wnyn=δn+1∂yn∂wnyn∂xn∂yn=δn+1∂yn∂wnyn∂xn∂f(xn)=δn+1wnf′(xn)Therefore, the error gradient of the input vector at a layer n is
δn=f′(xn){(yN−t)δn+1wnif n=Nif n<NHence, the error gradient of the weight matrix wn is
∂wn∂c=∂xn+1∂c∂wn∂xn+1=δn+1wn∂wnyn=δn+1ynTherefore, the change in weight should be
Δwn=−α∂wn∂c=−αδn+1ynwhere α is the learning rate (or rate of gradient descent). Thus, we have shown the necessary weight change, from which the implementation of a training algorithm follows trivially.
## Citation
Cited as:
Martin, Carlos G. and Schuermann, Lucas V. (Feb 2016). The Math Behind Backpropagation. Writing. https://lucasschuermann.com/writing/math-behind-backpropagation
Or
@misc{martin2016backpropagation,
title = {The Math Behind Backpropagation},
author = {Martin, Carlos G. and Schuermann, Lucas V.},
year = {2016},
month = {Feb},
url = "https://lucasschuermann.com/writing/math-behind-backpropagation"
}