#177Backprop — the output deltaEasyNeural NetworksCalculus
Backprop — the output delta
Background
With a sigmoid output and MSE loss, the first backprop quantity is the output delta — the gradient of the loss w.r.t. the output pre-activation :
The first factor is "how wrong, and in which direction"; the second is the local sigmoid slope . Their elementwise product is the error signal that flows back into the output layer.
Problem statement
Implement output_delta(a2, y) returning .
Input
a2— array-like prediction (sigmoid output), each in .y— array-like true labels, same length.
Output
Returns an np.ndarray (same length): the output delta.
Examples
Example 1
Input: a2 = [0.8], y = [1]
Output: [-0.032]
Explanation: .
Example 2
Input: a2 = [0.5, 0.5], y = [1, 0]
Output: [-0.125 0.125]
Explanation: error times slope .
Constraints
- Compute
(a2 - y) * a2 * (1 - a2)elementwise. - Return an
np.ndarray.
Notes
- A perfectly correct, saturated prediction gives on both factors — no error and no slope — so it stops learning, which is exactly right.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example — single output
- •Reference formula on three outputs
- •Sample opposite labels