Apply the chain rule through a scalar network
Read a complete operation before typing its result. · 186 words
Consider the scalar network x -> z = 3x + 1 -> y = z^2. A scalar is a single number at each stage. The chain rule multiplies the local rates of change along the path. At x = 2, we have z = 7, dy/dz = 2z = 14, and dz/dx = 3. Therefore, dy/dx = 14 times 3, which equals 42. This can be checked by hand: increasing x by 0.01 increases z by 0.03 and predicts that y rises by 42 times 0.01, or 0.42, to first order.
Now consider a different network: z = 2x + 3 and y = (z - 5)^2. At x = 1, z = 5. The outer derivative is 2(z - 5) = 0, while the inner derivative is 2, so the chain rule gives dy/dx = 0 times 2 = 0. This is a minimum point. Moving x to 1.01 gives z = 5.02 and y = 0.0004; moving x to 0.99 gives z = 4.98 and the same loss. Both changes increase the squared error, confirming that the gradient at x = 1 is zero.
Check your recall
For the first network, y = (3x + 1)^2, what is dy/dx at x = 2?
Check your answer
The gradient is 42: z = 7 gives dy/dz = 14, and dz/dx = 3, so the chain rule gives 14 times 3 = 42.
Sources and credits
Original KeyTouch lesson. Background reading · Google · Neural networks.