Computational Graphs and Forward Scalar Evaluation
Agent-Assisted Engineering Check
Prerequisites
Day 30 mathematics, basic object-oriented programming in Python, and understanding of variables as memory references.
Learning Objective
Understand how scalar arithmetic expressions are mapped into a Directed Acyclic Graph (DAG) of `Value` objects, and trace the forward pass.
Instructions
In automatic differentiation, a computation graph represents each mathematical operation as an interior node, with operands as input edges. Run the graph inspection command:
python3 projects/autograd/cli.py graph --preset neuron --format ascii
Observe how $x_1 w_1 + x_2 w_2 + b$ flows into activation $o = \tanh(n)$. Inspect the forward values.
Practice & Prediction Log
Consider the expression $f(x, y) = (x \cdot y + 2)^2$. At $x = 1.5, y = -2.0$:
1. Construct the step-by-step forward nodes: let $u = x \cdot y$, $v = u + 2$, $f = v^2$.
2. Calculate the numerical value of $u$, $v$, and $f$.
3. Write your predicted forward values in the editor below before running any script.
Calculate intermediate values sequentially: $u = 1.5 \times (-2.0) = -3.0$; then $v = -3.0 + 2 = -1.0$; finally $f = (-1.0)^2 = 1.0$.
Reference Solution:
- $u = 1.5 \times (-2.0) = -3.0$
- $v = -3.0 + 2 = -1.0$
- $f = (-1.0)^2 = 1.0$
The computation graph has 2 leaf nodes ($x, y$), one constant ($2$), and 3 operation nodes ($*, +, **2$).
The learner accurately represents scalar operations as DAG nodes with tracked child dependencies (`_prev`) and forward data floats.
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: commit a9a9f94 (Verified: 2026-10-30)
Clear, minimal scalar DAG implementation demonstrating fundamental autograd data structures.
Basic Python and calculus fundamentals
Local engine implementation in projects/autograd/engine.py and offline documentation.
Compared Candidate Sources & Selection Analysis (2)
Production scale, but too large and complex for tracing by hand in introductory lessons.
Vectorized autograd; micrograd's pure scalar model is pedagogical for hand backprop.