#190Backprop — the weight gradient is an outer productEasyNeural NetworksCalculus
Backprop — the weight gradient is an outer product
Background
Once you have a layer's delta, its weight gradient is an outer product: the activation that fed the layer times the error that arrived at it. For with shaped (n_in, n_out),
so comes out the same shape as — the sanity check to run every time.
Problem statement
Implement weight_gradient(a_prev, delta) returning the outer product .
Input
a_prev— array-like activation feeding the layer, lengthn_in.delta— array-like error signal at the layer, lengthn_out.
Output
Returns an np.ndarray of shape (n_in, n_out).
Examples
Example 1
Input: a_prev = [1, 2], delta = [0.5]
Output: [[0.5], [1.0]]
Explanation: outer product of a -vector and a -vector → shape (2, 1).
Example 2
Input: a_prev = [1, 0, 2], delta = [1, -1]
Output: [[ 1, -1], [ 0, 0], [ 2, -2]]
Constraints
- Return
np.outer(a_prev, delta)(shape(n_in, n_out)).
Notes
- Each entry — how much input fed neuron , times the error arriving at neuron .
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: 2x1 outer product
- •Reference: 3x2 outer product
- •Sample: 2x2 outer product