Backpropagation Algorithm
Forward Propagation and the Purpose of Backpropagation
How an artificial neuron works
An artificial neuron, or perceptron, performs two main operations:
Calculate a weighted sum of its inputs, including a bias: $$ z = \sum_i w_i x_i + b $Here,x_iaretheinputs,w_iaretheirweights,andbisthebias.Thebiascanberepresentedasaweightmultipliedbyaconstantinputof1$.
Apply an activation function to the weighted sum: $$ a = \sigma(z) $Theresulta$ is the neuron's output, also called its activation.
The activation function helps introduce nonlinearity into the network. Without nonlinear activations, stacking layers would still produce a function equivalent to a single linear transformation, limiting what the network could learn.
Sigmoid activation
The example network uses the sigmoid function:
Sigmoid maps any real-valued input to a value strictly between 0 and 1. Its derivative is:
Equivalently, if a=σ(z), then:
This derivative is useful during backpropagation because it describes how a neuron's output changes when its weighted sum changes.
Other activation functions include hyperbolic tangent, whose outputs range from −1 to 1, and ReLU. The choice of activation function affects the behavior and learning of the network.
Example network and parameters
The network has three layers:
Input layer: two inputs, i1 and i2.
Hidden layer: two neurons, h1 and h2.
Output layer: two neurons, o1 and o2.
The arrows between neurons represent trainable weights. Each hidden and output neuron also has a bias.
For the worked example, the inputs and targets are:
Here, t1 and t2 are the target values—the desired outputs against which the network’s predictions are compared.
The example uses these weights and biases:
From the inputs to the hidden layer:
w1=0.15,w2=0.20,w3=0.25,w4=0.30,b1=0.35From the hidden layer to the output layer:
w5=0.40,w6=0.45,w7=0.50,w8=0.55,b2=0.60
The bias value is added to each neuron’s weighted input. In this example, the same bias value is used for the neurons within a layer.
Forward propagation
Forward propagation sends information from the input layer through the hidden layer to the output layer. At each hidden or output neuron, the network first calculates a weighted sum and then applies the activation function. Once the output layer produces predictions, those predictions can be compared with the targets to calculate the error.
1. Calculate the hidden-layer weighted sums
For the first hidden neuron, the weighted sum is:
Substituting the example values:
The second hidden neuron receives its own weights:
2. Apply sigmoid to the hidden-layer sums
The hidden neurons’ outputs are:
The values ah1 and ah2 become the inputs to the output layer.
3. Calculate the output-layer weighted sums
The first output neuron receives signals from both hidden neurons:
The second output neuron uses its own incoming weights:
4. Apply sigmoid to obtain predictions
The network’s predicted outputs are:
The hats indicate that these are predictions, not target values. The targets remain t1=0.01 and t2=0.99.
Measuring prediction error
A cost function measures how far the network’s predictions are from the target values. For each output neuron, the example uses half the squared error:
Squaring the difference makes the contribution nonnegative, whether the prediction is above or below the target. The factor 21 is convenient when differentiating the squared-error expression.
For the first output:
For the second output:
The total cost is the sum of the two output errors:
The sign convention for the difference does not change these squared-error values: squaring either tj−y^j or y^j−tj gives the same result.
Forward propagation produces predictions and uses the cost function to quantify their difference from the targets.
Backpropagation and weight updates
Backpropagation uses the output error to determine how the network’s weights and biases should change. It works backward from the output layer toward the input layer, tracing how the parameters contributed to the error.
The learning cycle is:
Perform forward propagation to compute predictions.
Compare predictions with targets to calculate the cost.
Use backpropagation to determine how the weights and biases contributed to that cost.
Use gradient descent to adjust the weights and biases in directions that reduce the cost.
Perform forward propagation again with the updated parameters and measure the new cost.
Repeat the process until the cost is sufficiently small or another stopping condition is met.
Gradient descent uses information about the cost’s rate of change with respect to each parameter. The sigmoid derivative, σ(z)(1−σ(z)), is one component used when calculating these changes for sigmoid neurons.
The process is iterative: each update aims to reduce the cost, and the updated parameters are tested by another forward pass. Repetition can yield a network that predicts more accurately for the training examples. Gradient descent aims to minimize the cost, though it does not guarantee that every run will find a global minimum.

Ask anything
We've read this whole study set, so questions about it get the best answers.