Least-Squares Gradients
Consider the scalar objective L(x)=\tfrac12\|Ax-b\|_2^2, with fixed A and b.
On this page 7 sections
01Send residuals back to the parameters#
Consider the scalar objective , with fixed and . The prediction is and the residual is . The residual has one entry per output; the gradient needs one entry per parameter.
The half-squared norm is , so its gradient with respect to is . The derivative of the residual map is . Reverse-mode differentiation sends the output sensitivity back through its transpose.
02Follow the intermediate values#
Let have rows , , and . Predictions are and residuals are .
The first gradient entry is . The second is . Thus the gradient is , while the loss is .
A has rows (1,2),(0,1), x=(1,0), b=(0,2). For L=||Ax−b||²/2, find ∇L.
Show answer and explanation
Ax−b=(1,−2); Aᵀ times that residual is (1,0).
03Interpret the transpose#
For of shape , the residual is an -vector. Multiplying by , of shape , collects residual contributions into a -vector. Each parameter receives contributions from every output it affects.
If the objective is the mean half-squared loss, divide both loss and gradient by . The gradient above is for the stated sum. A different reduction changes its scale.
A draft differentiates ||Ax−b||²/2 as 2Aᵀ(Ax−b). What factor should be removed?
Show answer and explanation
The half in the objective cancels the square derivative factor.
A zero gradient does not require a zero residual. It means the residual is perpendicular to every column of . This connects the derivative calculation to the earlier geometry of the closest attainable output.
Compute the gradient of one-half the squared Euclidean residual norm ||Ax − b||² as Aᵀ(Ax − b) for fixed A and b.
- Compute the gradient of one-half the squared Euclidean residual norm ||Ax − b||² as Aᵀ(Ax − b) for fixed A and b.
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