Squared Frobenius-Loss Gradients
Let Z contain model outputs and Y contain fixed targets of the same shape.
On this page 7 sections
01A mean squared loss for matrix outputs#
Let contain model outputs and contain fixed targets of the same shape. The loss squares every entrywise error, sums them, and divides by a fixed positive scalar .
In a batch, often counts examples. It need not count all scalar output entries. Read the stated loss reduction before differentiating.
02One entry at a time#
Entry appears in the term . The power and chain rules give . Placing these partials into their original positions gives
Suppose has rows and has rows , with . The residual rows are . The loss is .
The gradient rows are . Each entry indicates the local sensitivity to its matching prediction. A prediction already equal to its target contributes a zero gradient entry.
Z−Y has rows (2,−4),(0,6), and m=2. For L=||Z−Y||F²/(2m), gradient rows?
Show answer and explanation
Divide every residual by m=2.
03Average exactly once#
Dividing by four output entries instead of two examples would give a different objective and gradient. Both conventions can be useful, but they cannot be mixed halfway through a calculation.
Which function is differentiated by the residual-over-m rule?
Show answer and explanation
Differentiating each squared error cancels the factor two.
The norm is squared. Differentiating the unsquared Frobenius norm would be a different operation. This gradient is with respect to predictions ; reaching an earlier weight matrix requires another chain-rule step.
Compute ∇_Z [||Z − Y||_F²/(2m)] = (Z − Y)/m for fixed real Y and a fixed positive scalar m.
- Compute ∇_Z [||Z − Y||_F²/(2m)] = (Z − Y)/m for fixed real Y and a fixed positive scalar m.
Sources & further reading
- [1]MIT 6.390, Appendix A: Matrix Calculus ↗introml.mit.edu · Article
- [2]Boyd and Vandenberghe, Introduction to Applied Linear Algebra ↗stanford.edu · Article