Chapter 11 of 13
Course Progress0 of 13 completed (0%)

Machine Learning Foundations · Chapter 11 · ~15 min · Advanced

Neural Networks from Scratch: Perceptrons to Backprop

Demystify deep learning from mathematical first principles. Master the artificial neuron, understand why non-linear activations prevent deep layers from collapsing, and derive the calculus chain rule behind reverse-mode backpropagation.

  • Formulate the artificial neuron z = W^T x + b and non-linear activation functions
  • Prove why stacking linear layers without activations collapses into a single layer
  • Break neuron symmetry using He/Xavier Gaussian random initialization
  • Trace gradient backpropagation step-by-step using the multivariable chain rule

Neural Networks from Scratch: Perceptrons to Backprop: learn it visually

Demystify deep learning from mathematical first principles. Master the artificial neuron, understand why non-linear activations prevent deep layers from collapsing, and derive the calculus chain rule behind reverse-mode backpropagation.

Neural Networks from Scratch: Perceptrons to BackpropDemystify deep learning from mathematical first principles. Master the artificial neuron, understand why non-linear activations prevent deep layers from collapsing, and derive the calculus chain rule behind reverse-mode backpropagation.UNDERSTANDNeural NetworksScratchFOLLOW THE FLOWPerceptrons BackpropAPPLY ITlearningmathematicalprinciplesNeural Networks from Scratch: Perceptrons to BackpropDemystify deep learning from mathematical first principles. Master the artificial neuron, understand why non-linear activations prevent deep layers from collapsing, and derive the calculus chain rule behind reverse-mode backpropagation.UNDERSTANDNeural NetworksScratchFOLLOW THE FLOWPerceptrons BackpropAPPLY ITlearningmathematicalprinciples

1The Perceptron: Biology Meets Linear Algebra

In 1958, Frank Rosenblatt created the Perceptron, inspired by biological neurons in the brain:

z = ∑i=1n wi · xi + b  →  a = σ(z)

Inputs x represent dendrite signals, weights w represent synaptic strengths, bias b is the firing threshold, and σ is the non-linear activation.

Wrong idea: Stacking 100 linear layers without non-linear activations

100 Linear Layers ≡ 1 Single Linear Matrix → Cannot learn XORDeep network with no activations has zero non-linear expressive power

Multiplying linear equations collapses mathematically: W3(W2(W1 · x)) = (W3 · W2 · W1) · x = W_combo · x, equivalent to a simple single-layer regression.

Real system: Non-linear activations (ReLU, GELU, Sigmoid)

a = ReLU(W · x + b) → Universal Approximator for complex boundariesEnables deep networks to carve out intricate high-dimensional decision boundaries

Applying non-linear activation functions bends coordinate spaces, enabling networks to become Universal Function Approximators for arbitrary manifolds.

Concept Check

What happens mathematically if you build a deep neural network with 50 hidden layers but completely omit all non-linear activation functions?

2Activation Functions: ReLU, Sigmoid, and Tanh

Non-linear activation functions introduce the curvature needed to learn complex decision boundaries:

ReLU (Rectified Linear Unit)

f(z) = max(0, z)

The modern default. Derivative is 1 for z > 0, completely avoiding vanishing gradients in deep feedforward architectures.

Sigmoid

f(z) = 1 / (1 + e-z)

Squashes outputs into (0, 1). Ideal for binary probability outputs, but suffers from severe vanishing gradients in hidden layers.

Tanh

f(z) = (ez - e-z) / (ez + e-z)

Zero-centered outputs in (-1, +1). Historically popular in recurrent neural networks and early hidden layers.

Concept Check

Why did ReLU replace Sigmoid as the dominant hidden-layer activation function in modern deep networks?

3Backpropagation: The Multivariable Chain Rule

How does an error at the final output neuron propagate backwards to update weights in the first layer? Through the Calculus Chain Rule:

∂Loss / ∂W[1] = ( ∂Loss / ∂ŷ ) · ( ∂ŷ / ∂z[2] ) · ( ∂z[2] / ∂a[1] ) · ( ∂a[1] / ∂z[1] ) · ( ∂z[1] / ∂W[1] )

By caching intermediate values computed during the forward pass, backpropagation sweeps in reverse from the output layer to the input layer in exactly one single pass!

4Hands-On: 3-Layer Forward & Backprop Visualizer

Interact with the live 3-layer network below. Adjust the inputs x₁ and x₂, click 1. Forward Pass to propagate activations, then click 2. Step Backward to watch gradients flow in reverse:

Interactive 3-Layer Perceptron: Forward Propagation & Backprop Chain Rule

Phase: READY
x₁0.80x₂0.40h₁ReLUh₂ReLUh₃ReLUŷ0.50Input LayerHidden (ReLU)Output (Sigmoid)
Predicted ŷ:Pending
Target y (Ground Truth):1.0
Squared Loss L:Pending
Backprop Gradient dz₂:Idle
0.80
0.40
Network Execution Cycle:

5Bug Hunt: Fix Zero-Weight Symmetry & Broken ReLU Derivative

An AI engineer built a 2-layer perceptron from scratch in NumPy. However, training immediately froze because weights were initialized to all zeros (W = np.zeros) and the backward pass neglected to multiply by the derivative of the ReLU activation function.

Repair the weight initialization and backward activation gradients:

Python Bug Hunt · Neural Network Symmetry & Backprop
Python

🎯 Find and fix the bugs in the code above, then press Run & verify to test your solution.

Need a hint?
  • Break symmetry with Gaussian random weights: W1 = np.random.randn(n_hidden, n_in) * 0.01.
  • Multiply by ReLU derivative in backprop: dz1 = da1 * (z1 > 0).

6Chapter Knowledge Challenge

Test your mastery of neural network architectures, forward passes, and backprop derivatives:

Concept Check 1 of 2
1

What catastrophic problem occurs if all weights in a multi-layer neural network are initialized to 0.0?

Concept Check 2 of 2
2

What is the derivative of the ReLU activation function f(z) = max(0, z) when z > 0?

7Recap

  • An Artificial Neuron computes z = WTx + b and passes it through an activation function.
  • Non-Linear Activations (ReLU, Sigmoid) enable networks to approximate complex non-linear manifolds and prevent multi-layer linear collapse.
  • Random Weight Initialization breaks neuron symmetry so hidden units specialize into distinct feature detectors.
  • Backpropagation leverages the chain rule of calculus to compute exact partial derivatives for millions of parameters in a single reverse sweep.

Ready for Chapter 12? Mark this chapter as complete to proceed:

Enjoying this free lesson? Your support helps us build more free animated chapters.

Support Us