Computational graphs: local derivatives and backward accumulation
Assistance allowed only after prediction and observed evidence are recorded.
Prerequisites
Days 19-20 chain rule and gradient drills; if any step is shaky, open the day-level recovery link first.
Learning Objective
Decompose a scalar expression into a computational graph, compute each node's forward value, then propagate derivatives backward by multiplying local chain-rule factors.
Instructions
Take L = (a*b + c)^2 with a = 2, b = 3, c = 1. Forward: n1 = a*b = 6, n2 = n1 + c = 7, L = n2^2 = 49. Backward: dL/dn2 = 2*n2 = 14; dL/dn1 = 14 * ∂n2/∂n1 = 14 * 1 = 14; dL/dc = 14 * ∂n2/∂c = 14; dL/da = 14 * ∂n1/∂a = 14 * b = 42; dL/db = 14 * ∂n1/∂b = 14 * a = 28. Every step is the Day 19-20 chain rule applied to one local edge. Predict dL/da before perturbing a in code.
Practice & Prediction Log
Draw the graph for L = (a*b + c)^2 at (2, 3, 1), fill in forward values 6, 7, 49, then compute all input gradients by hand. Verify dL/da, dL/db, dL/dc against central finite differences and record agreement.
Reverse mode: the adjoint at n2 travels BACKWARDS over the forward edges into it - n1->n2 and c->n2 - to n1 and c. So dL/dn2 = dL/dn1 = dL/dc = 14; applying local factors gives input gradients dL/da = 42, dL/db = 28, dL/dc = 14.
Forward: n1 = 6, n2 = 7, L = 49. Backward: dL/dn2 = 14; dL/dn1 = 14, dL/dc = 14; dL/da = 14*3 = 42; dL/db = 14*2 = 28. Finite differences ((L(2+h,3,1) - L(2-h,3,1)) / 2h with h = 1e-5, and likewise for b, c) return about 42.0000, 28.0000, 14.0000 — the same numbers a micrograd-style engine would report for .grad on each input.
You reproduce forward values 6, 7, 49 and backward values 42, 28, 14 unaided, name the local derivative on every edge, and your finite-difference run agrees with each hand gradient.
Authoritative Source Resources & Provenance
micrograd: A tiny scalar-valued autograd engine
Relevant Section / Range: micrograd/engine.py: class Value (_backward closures and backward() topological sort); README 'Example usage'
Verified Version & Date: 2022 (verified 2026-10-30)
The scalar computational graph in this lesson is exactly the micrograd engine walkthrough; it previews the autograd project without importing any material.
Chain rule and partial derivatives (Study Days 19-20).
The full forward and backward pass is derived locally with numeric verification; no video is required.
Compared Candidate Sources & Selection Analysis (2)
Normative production documentation, but micrograd's pure Python implementation provides far superior initial clarity.
High visual quality, pairs cleanly as optional supplementary visual reference.
OpenStax Calculus Volume 3
Relevant Section / Range: Section 4.5: tree-diagram rule used to justify backward accumulation
Verified Version & Date: OpenStax Calculus Volume 3 web edition (verified 2026-10-30)
Provides the formal chain rule statement that the graph walkthrough applies node by node.
Scalar chain rule (day-19) and partial derivatives (day-20).
The derivation uses only local rules already proven on Days 19-20.
Compared Candidate Sources & Selection Analysis (2)
Selected as the lecture-depth companion for partial derivatives; OpenStax Volume 3 remains the written primary reference.
Strong visual coverage of gradients, but the OpenStax text better matches the lesson's theorem-plus-hand-check structure.