optional · interactive figures
30
Explore: automatic differentiation
Dual numbers flowing forward and adjoints flowing back through the graph of xy + sin x, one node at a time.
optional: nothing in the lab depends on it back to the slides
These figures support the slides; they don't replace them, and the unit is complete
without them. Each one is computed from the unit's own data or reference solution, so
what you see agrees with the numbers on the slides.
Inside a figure, the arrow keys and drags belong to the figure; click outside it (or
press Esc) to use them for the slides again.
30 · explore
Forward and reverse, on one graph
Try: step each forward pass, then the reverse run; count how many passes each needs for both derivatives. Static versions: forward mode , the tape and its adjoints .
What it shows. $f(x, y) = xy + \sin x$ at $(1, 2)$ as a computational graph. The two forward runs
evaluate the reference Dual class node by node, seeding $x$ or $y$; the reverse run builds the
graph from the reference Var and vsin, takes its visiting order from the reference
backward, and replays the adjoint loop one node at a time. All recorded by
slides/viz/traces/u30.py, which also checks the final adjoints against
reverse_gradient.
Forward, seed $x$: the $\varepsilon$ parts end at $2.5403 = y + \cos x$. Seed $y$: they end at $1 = x$. Two passes for two derivatives.
Reverse: one recording pass, then one sweep gives both. The red arrows show which local derivative multiplies the adjoint on each visit.
$v_0$ feeds both $v_2$ and $v_3$, so its adjoint is added to twice: $2 + 0.5403$.
The reference visits $v_2$ before $v_3$; the slide's table lists $v_3$ first. Either order works, because both come after $v_4$ and before the inputs.