Skip to content
Glacius
CalculusConcept reference

Local Change from a Matrix Gradient

A scalar-loss gradient has one sensitivity per matrix entry.

On this page 7 sections
  1. Overview
  2. Predict a scalar change from a matrix change
  3. Combine signed contributions
  4. An approximation to finite changes
  5. Key takeaway
  6. Sources & further reading
  7. Concept connections

01Predict a scalar change from a matrix change#

A scalar-loss gradient has one sensitivity per matrix entry. To estimate the effect of a small matrix perturbation, multiply matching sensitivities and changes, then add them all.

ΔLWL,ΔWF\begin{gathered}\Delta L\\\approx\langle\nabla_WL,\Delta W\rangle_F\end{gathered}

This is the same first-order reasoning as a gradient dot product for a vector. Keeping the matrix layout makes corresponding parameter positions visible.

02Combine signed contributions#

Suppose a gradient has rows (2,1),(0,3)(2,-1),(0,3) and a proposed perturbation has rows (0.1,0.2),(0.1,0.1)(0.1,0.2),(-0.1,-0.1). The four contributions are 0.2,0.2,0,0.30.2,-0.2,0,-0.3.

Their sum is 0.3-0.3, so the first-order model predicts a loss decrease of about 0.30.3. If the original loss is 55, its estimated new value is 4.74.7. The change and the new value are different answers.

Check your reasoning

Gradient rows: (1,2),(−1,0). Perturbation rows: (0.1,−0.2),(0.3,1). Estimate ΔL.

  1. A−0.6
  2. B0
  3. C0.8
Show answer and explanation
−0.6

Sum 0.1−0.4−0.3+0=−0.6.

03An approximation to finite changes#

A zero inner product means no first-order change; higher-order change may remain. For L(W)=WF2/2L(W)=\|W\|_F^2/2 at the zero matrix, the gradient is zero. A nonzero finite perturbation still increases the loss by half its squared norm.

For an affine scalar function of the entries, this calculation is exact. For a nonlinear function, smaller perturbations make the local interpretation more useful, but a large step needs its own evaluation.

Check your reasoning

A draft reports the array G ⊙ H as a scalar loss change. What final operation is missing?

  1. ATake a matrix inverse
  2. BSum every entry
  3. CKeep only the diagonal
Show answer and explanation
Sum every entry

The scalar estimate is the sum of matching products.

An entrywise product alone is an array of contributions. The final sum is necessary because the loss change is a scalar. A row-by-column matrix product generally has the wrong shape and meaning here.

Key takeaway

Estimate the first-order change of a scalar objective under a small matrix perturbation using the Frobenius inner product of its gradient and that perturbation.

  • Estimate the first-order change of a scalar objective under a small matrix perturbation using the Frobenius inner product of its gradient and that perturbation.

Sources & further reading

  1. [1]
  2. [2]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Local Change from a Matrix Gradient.” Math behind ML. /learn/c-matrix-differential