Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. ›
  3. posts
  4. ›
  5. …

  6. ›
  7. Backward Propogation

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🍌 Bananas are berries, but strawberries are not.

🍪 This website uses cookies

No personal data is stored on our servers however third party tools Google Analytics cookies to measure traffic and improve your website experience. Learn more

Cover Image for Backpropagation Algorithm

Backpropagation Algorithm

Backpropagation is the algorithm used to minimize the neural network cost function. It computes the gradients of the cost function with respect to the parameters, allowing us to perform gradient descent and update our model.

Hitesh Sahu
Written by Hitesh Sahu, a passionate developer and blogger.

Fri Feb 27 2026

Share This on

Backpropagation Algorithm

Backpropagation is the algorithm used to minimize the neural network cost function.

Just like gradient descent in linear and logistic regression, our goal is:

min⁡ΘJ(Θ)\min_\Theta J(\Theta)Θmin​J(Θ)

That is, we want to find parameters Θ\ThetaΘ that minimize the cost function.


Objective

We want to compute the partial derivatives:

∂∂Θi,j(l)J(Θ)\frac{\partial}{\partial \Theta_{i,j}^{(l)}} J(\Theta)∂Θi,j(l)​∂​J(Θ)

These derivatives are used in gradient descent to update the parameters.


Backpropagation Algorithm

Given training set:

{(x(1),y(1)),…,(x(m),y(m))}\{(x^{(1)}, y^{(1)}), \dots, (x^{(m)}, y^{(m)})\}{(x(1),y(1)),…,(x(m),y(m))}

Step 1: Initialize Accumulators

Set:

Δi,j(l):=0\Delta_{i,j}^{(l)} := 0Δi,j(l)​:=0

for all l,i,jl, i, jl,i,j.

This creates matrices of zeros to accumulate gradients.


Step 2: For each training example t=1t = 1t=1 to mmm

2.1 Forward Propagation

Set:

a(1):=x(t)a^{(1)} := x^{(t)}a(1):=x(t)

Compute forward propagation for:

l=2,3,…,Ll = 2, 3, \dots, Ll=2,3,…,L

to obtain activations a(l)a^{(l)}a(l).


2.2 Compute Output Layer Error

Using the true label y(t)y^{(t)}y(t):

δ(L)=a(L)−y(t)\delta^{(L)} = a^{(L)} - y^{(t)}δ(L)=a(L)−y(t)

This is the error of the output layer.


2.3 Backpropagate the Error

For layers:

l=L−1,L−2,…,2l = L-1, L-2, \dots, 2l=L−1,L−2,…,2

Compute:

δ(l)=((Θ(l))Tδ(l+1))  . ⁣∗  g′(z(l))\delta^{(l)} = \left( (\Theta^{(l)})^T \delta^{(l+1)} \right) \;.\!* \; g'(z^{(l)})δ(l)=((Θ(l))Tδ(l+1)).∗g′(z(l))

For sigmoid activation:

g′(z(l))=a(l)  . ⁣∗  (1−a(l))g'(z^{(l)}) = a^{(l)} \;.\!* \; (1 - a^{(l)})g′(z(l))=a(l).∗(1−a(l))

So equivalently:

δ(l)=((Θ(l))Tδ(l+1))  . ⁣∗  a(l)  . ⁣∗  (1−a(l))\delta^{(l)} = \left( (\Theta^{(l)})^T \delta^{(l+1)} \right) \;.\!* \; a^{(l)} \;.\!* \; (1 - a^{(l)})δ(l)=((Θ(l))Tδ(l+1)).∗a(l).∗(1−a(l))

The operator . ⁣∗.\!* .∗ denotes element-wise multiplication.


2.4 Accumulate Gradients

Update:

Δi,j(l):=Δi,j(l)+aj(l)δi(l+1)\Delta_{i,j}^{(l)} := \Delta_{i,j}^{(l)} + a_j^{(l)} \delta_i^{(l+1)}Δi,j(l)​:=Δi,j(l)​+aj(l)​δi(l+1)​

Vectorized form:

Δ(l):=Δ(l)+δ(l+1)(a(l))T\Delta^{(l)} := \Delta^{(l)} + \delta^{(l+1)} (a^{(l)})^TΔ(l):=Δ(l)+δ(l+1)(a(l))T

Step 3: Compute Gradients

After processing all training examples:

For j≠0j \ne 0j=0 (non-bias terms):

Di,j(l)=1m(Δi,j(l)+λΘi,j(l))D_{i,j}^{(l)} = \frac{1}{m} \left( \Delta_{i,j}^{(l)} + \lambda \Theta_{i,j}^{(l)} \right)Di,j(l)​=m1​(Δi,j(l)​+λΘi,j(l)​)

For bias terms (j=0j = 0j=0):

Di,j(l)=1mΔi,j(l)D_{i,j}^{(l)} = \frac{1}{m} \Delta_{i,j}^{(l)}Di,j(l)​=m1​Δi,j(l)​

Final Result

The gradient of the cost function is:

∂∂Θi,j(l)J(Θ)=Di,j(l)\frac{\partial}{\partial \Theta_{i,j}^{(l)}} J(\Theta) = D_{i,j}^{(l)}∂Θi,j(l)​∂​J(Θ)=Di,j(l)​

The matrix D(l)D^{(l)}D(l) gives the partial derivatives used in gradient descent.


Key Ideas

  • Forward propagation computes activations.
  • Backpropagation computes errors (δ\deltaδ values).
  • Errors are propagated from right to left.
  • Gradients are accumulated in Δ\DeltaΔ.
  • Regularization is added for non-bias weights.
  • Finally, we divide by mmm to obtain the average gradient.
AI-DeepLearning/Backward-Propogation
Let's work together
+49 176-2019-2523
hiteshkrsahu@gmail.com
WhatsApp
Skype
Munich 🥨, Germany 🇩🇪, EU
Playstore
Hitesh Sahu's apps on Google Play Store
Need Help?
Let's Connect
Navigation
  Home/About
  Skills
  Work/Projects
  Lab/Experiments
  Contribution
  Awards
  Art/Sketches
  Thoughts
  Contact
Links
  Sitemap
  Legal Notice
  Privacy Policy

Made with

NextJS logo

NextJS by

hitesh Sahu

| © 2026 All rights reserved.