ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing
ApX logoApX logo
ModelsCalculatorHardwareCoursesPricing

All Courses

Introduction to Deep Learning
Chapter 1: Neural Network Foundations
From Machine Learning to Deep Learning
Biological Inspiration: The Neuron
The Artificial Neuron: A Mathematical Model
The Perceptron: The Simplest Neural Network
Limitations of Single-Layer Perceptrons
Multi-Layer Perceptrons (MLPs): Adding Depth
Hands-on Practical: Building a Simple Perceptron Model
Quiz for Chapter 1
Chapter 2: Activation Functions and Network Architecture
The Role of Activation Functions
Sigmoid Activation
Hyperbolic Tangent (Tanh) Activation
Rectified Linear Unit (ReLU)
Variants of ReLU (Leaky ReLU, PReLU, ELU)
Choosing the Right Activation Function
Understanding Network Layers: Input, Hidden, Output
Designing Feedforward Network Architectures
Hands-on Practical: Implementing Different Activations
Quiz for Chapter 2
Chapter 3: Training Neural Networks: Loss and Optimization
Measuring Performance: Loss Functions
Common Loss Functions for Regression (MSE, MAE)
Common Loss Functions for Classification (Cross-Entropy)
Optimization: Finding the Best Weights
Gradient Descent Algorithm
Learning Rate
Stochastic Gradient Descent (SGD)
Challenges with Gradient Descent
Hands-on Practical: Visualizing Gradient Descent
Quiz for Chapter 3
Chapter 4: Backpropagation and Advanced Optimization
Calculating Gradients: The Chain Rule
Computational Graphs
The Backpropagation Algorithm Explained
Forward Pass vs. Backward Pass
Gradient Descent with Momentum
RMSprop Optimizer
Adam Optimizer
Choosing an Optimization Algorithm
Hands-on Practical: Backpropagation Step-by-Step
Quiz for Chapter 4
Chapter 5: Building and Training Deep Neural Networks
Introduction to Deep Learning Frameworks (TensorFlow/Keras, PyTorch)
Setting up the Development Environment
Preparing Data for Neural Networks
Defining a Feedforward Network Model
Weight Initialization Strategies
Compiling the Model: Loss and Optimizer Selection
Training the Model: The fit Method
Monitoring Training Progress (Loss and Metrics)
Evaluating Model Performance
Hands-on Practical: Training a Classifier on MNIST
Quiz for Chapter 5
Chapter 6: Regularization and Improving Performance
The Problem of Overfitting
Regularization Techniques Overview
L1 and L2 Regularization
Dropout Regularization
Early Stopping
Batch Normalization
Hyperparameter Tuning Fundamentals
Strategies for Hyperparameter Search (Grid Search, Random Search)
Hands-on Practical: Applying Dropout and Early Stopping
Quiz for Chapter 6
Chapter 7: Introduction to Specialized Architectures
Limitations of Feedforward Networks
Convolutional Neural Networks (CNNs): Motivation
Core CNN Operations: Convolution
Core CNN Operations: Pooling
Typical CNN Architecture
Recurrent Neural Networks (RNNs): Motivation
The Concept of Recurrence and Hidden State
Basic RNN Architecture
Challenges with Simple RNNs (Vanishing/Exploding Gradients)
Overview: LSTMs and GRUs
Quiz for Chapter 7
Designing and Optimizing a Deep Neural Network from Scratch

Computational Graphs

Calculating the gradient of the loss function with respect to every single weight in a deep, multi-layered neural network might seem like a daunting task. If we tried to derive the derivative for each weight independently, the expressions would quickly become incredibly complex and unwieldy. Fortunately, we can approach this systematically using Computational Graphs.

A computational graph is a way to represent any mathematical expression, like the ones involved in a neural network's forward pass, as a directed graph. In this graph:

  1. Nodes: Represent either input variables, constants, or mathematical operations (like addition, multiplication, activation functions).
  2. Edges: Represent the flow of data. An edge points from the node providing the output to the node consuming that output as input.

Think of it as breaking down a complex calculation into a sequence of simple, elementary steps.

Visualizing Computations

Let's look at a simple example unrelated to neural networks first. Suppose we have the expression f(x,y,z)=(x+y)∗zf(x, y, z) = (x + y) * zf(x,y,z)=(x+y)∗z. We can visualize this as a graph:

A computational graph for the expression f=(x+y)∗zf = (x + y) * zf=(x+y)∗z. Circles represent variables/values, squares represent operations. Arrows show the flow of computation.

Here, xxx, yyy, and zzz are input nodes. The + node takes xxx and yyy as input and outputs an intermediate value q=x+yq = x + yq=x+y. The * node takes qqq and zzz as input and produces the final output fff.

The Forward and Backward Pass

Computational graphs clarify two distinct phases:

  1. Forward Pass: We start with the input values and proceed through the graph, following the direction of the edges, performing the operation at each node. This computes the value of the expression step-by-step, ultimately yielding the final output value. For our example, if x=2,y=3,z=4x=2, y=3, z=4x=2,y=3,z=4, the forward pass would compute q=2+3=5q = 2 + 3 = 5q=2+3=5, and then f=5∗4=20f = 5 * 4 = 20f=5∗4=20.

  2. Backward Pass: This is where the magic happens for gradient calculation. Starting from the final output node, we move backward through the graph (against the direction of the edges). At each node, we calculate the gradient of the final output with respect to the node's output value, using the gradients calculated from the nodes that consumed its output. This process heavily relies on the chain rule from calculus.

Let's trace the backward pass for our simple example, f=q∗zf = q * zf=q∗z, where q=x+yq = x + yq=x+y. We want to find ∂f∂x\frac{\partial f}{\partial x}∂x∂f​, ∂f∂y\frac{\partial f}{\partial y}∂y∂f​, and ∂f∂z\frac{\partial f}{\partial z}∂z∂f​.

  • Start at the end: The gradient of fff with respect to itself is trivial: ∂f∂f=1\frac{\partial f}{\partial f} = 1∂f∂f​=1.
  • Move to the * node: This node computes f=q∗zf = q * zf=q∗z. We need the gradients with respect to its inputs, qqq and zzz.
    • The local gradient ∂f∂q=z\frac{\partial f}{\partial q} = z∂q∂f​=z.
    • The local gradient ∂f∂z=q\frac{\partial f}{\partial z} = q∂z∂f​=q. Using the chain rule, the gradient flowing back to qqq is ∂f∂f×∂f∂q=1×z=z\frac{\partial f}{\partial f} \times \frac{\partial f}{\partial q} = 1 \times z = z∂f∂f​×∂q∂f​=1×z=z. The gradient flowing back to zzz is ∂f∂f×∂f∂z=1×q=q\frac{\partial f}{\partial f} \times \frac{\partial f}{\partial z} = 1 \times q = q∂f∂f​×∂z∂f​=1×q=q. (If zzz were computed by other nodes, this gradient would flow further back).
  • Move to the q node: This node receives the gradient ∂f∂q=z\frac{\partial f}{\partial q} = z∂q∂f​=z from the * node.
  • Move to the + node: This node computes q=x+yq = x + yq=x+y. We need the local gradients:
    • ∂q∂x=1\frac{\partial q}{\partial x} = 1∂x∂q​=1.
    • ∂q∂y=1\frac{\partial q}{\partial y} = 1∂y∂q​=1. Using the chain rule again, we multiply the incoming gradient (∂f∂q\frac{\partial f}{\partial q}∂q∂f​) by the local gradients:
    • The gradient flowing back to xxx is ∂f∂q×∂q∂x=z×1=z\frac{\partial f}{\partial q} \times \frac{\partial q}{\partial x} = z \times 1 = z∂q∂f​×∂x∂q​=z×1=z. This is ∂f∂x\frac{\partial f}{\partial x}∂x∂f​.
    • The gradient flowing back to yyy is ∂f∂q×∂q∂y=z×1=z\frac{\partial f}{\partial q} \times \frac{\partial q}{\partial y} = z \times 1 = z∂q∂f​×∂y∂q​=z×1=z. This is ∂f∂y\frac{\partial f}{\partial y}∂y∂f​.

So, we have systematically found: ∂f∂x=z\frac{\partial f}{\partial x} = z∂x∂f​=z, ∂f∂y=z\frac{\partial f}{\partial y} = z∂y∂f​=z, and ∂f∂z=q=x+y\frac{\partial f}{\partial z} = q = x + y∂z∂f​=q=x+y. Notice how the chain rule allows us to break down the overall gradient calculation into local gradients at each operation node.

Computational Graphs for Neural Networks

Now, imagine a neural network. The entire process of calculating the output (the forward pass) can be represented as a potentially very large computational graph. Each neuron's weighted sum, each activation function application, and the final loss calculation are all nodes in this graph.

A computational graph representing a single neuron's computation: a=σ(w1x1+w2x2+b)a = \sigma(w_1x_1 + w_2x_2 + b)a=σ(w1​x1​+w2​x2​+b). Input variables (x1,x2x_1, x_2x1​,x2​), parameters (w1,w2,bw_1, w_2, bw1​,w2​,b), intermediate values (p1,p2,s,zp_1, p_2, s, zp1​,p2​,s,z), and the final output (aaa) are shown along with the operations (*, +, σ).

The backpropagation algorithm, which we will detail next, is essentially the process of performing the backward pass on this neural network computational graph. It starts from the final loss value and efficiently computes the gradient of the loss with respect to every single parameter (weights and biases) in the network by applying the chain rule recursively through the graph structure.

Modern deep learning frameworks like PyTorch and TensorFlow rely heavily on this concept. They automatically build a computational graph (often dynamically during the forward pass) and then perform the backward pass to compute gradients. This process is often called automatic differentiation or autodiff, and it frees us from having to manually derive and implement these complex gradient calculations. Understanding computational graphs provides insight into how these powerful tools work under the hood.

  • Deep Learning, Ian Goodfellow, Yoshua Bengio, and Aaron Courville, 2016 (MIT Press) - A fundamental textbook that provides a comprehensive explanation of computational graphs and their application in backpropagation for training deep neural networks.
  • Automatic Differentiation in Machine Learning: a Survey, Atilim Gunes Baydin, Barak A. Pearlmutter, Jeffrey Mark Siskind, and David I. Innes, 2018 Journal of Machine Learning Research, Vol. 18 (Journal of Machine Learning Research) DOI: 10.5555/3313076.3313077 - This survey paper offers an academic overview of automatic differentiation, the core technique relying on computational graphs to efficiently compute gradients in machine learning.
  • Autograd: automatic differentiation, PyTorch Contributors, 2016 - The official PyTorch documentation explaining its automatic differentiation engine, which builds and uses computational graphs for gradient computation.
  • Backpropagation, Intuitions, Andrej Karpathy and Justin Johnson, 2017 Stanford CS231n Course Notes (Stanford University) - These well-regarded course notes provide a clear and intuitive explanation of backpropagation, heavily utilizing computational graphs to illustrate the forward and backward passes.

© 2026 ApX Machine Learning