Have a go at it. The editor and the docs panel are open, and your code is saved as you type. Running it needs a free account — you’ll come back to exactly what you wrote.
The Chain Rule
The chain rule is the single most important fact in this curriculum. Backpropagation is nothing else.
If y=f(g(x)), then
In words: the outer derivative evaluated at the inner value, times the inner derivative. Rates multiply along a chain. If y moves 3× as fast as u, and u moves 2× as fast as x, then y moves 6× as fast as x.
Take y=(3x+1)2 at x=2:
inner u = 3x + 1 = 7 du/dx = 3
outer y = u^2 dy/du = 2u = 14
dy/dx = 14 * 3 = 42That two-step structure — evaluate forward, then multiply derivatives backward — is exactly the forward and backward pass of a neural network. A three-layer network is this rule applied three times.
Your task:
Implement chain_rule_derivative(a, b, x) for
returning dy/dx at x, computed as outer times inner rather than by expanding the square first. The answer is .
Example Tests
(3x + 1)^2 at x = 2: inner is 7, outer derivative 14, times 3
Input: {"a":3,"b":1,"x":2}
Expected: 42
At the point where the inner function is zero the whole derivative vanishes
Input: {"a":2,"b":-4,"x":2}
Expected: 0
A negative inner slope flips the sign
Input: {"a":-1,"b":5,"x":1}
Expected: -8
def chain_rule_derivative(a, b, x):
"""
dy/dx for y = (a*x + b)^2, via the chain rule.
Args:
a: inner slope
b: inner offset
x: the point to differentiate at
Returns:
float: 2*(a*x + b) * a
"""
# YOUR CODE HERE
pass