Frobenius norm
The Frobenius norm is the square root of the sum of squared real matrix entries.
On this page 10 sections
01Turn a matrix of errors into one size#
A model can make several predictions for each example in a batch. Subtract the targets and you get a matrix of errors. To compare two predictions, we often need one number that measures the size of that whole matrix.
Simply adding the entries would let positive and negative errors cancel. A residual of is still an error of size four. The Frobenius norm counts every entry by squaring it before adding.
Start with a familiar vector. The length of is . The Frobenius norm uses the same operation on all the coordinates of a matrix.
You can imagine laying the entries out in one long vector. Their arrangement into rows and columns does not change this length. We are measuring entry sizes, rather than how the matrix transforms a vector.
02Compute the norm entry by entry#
Consider this matrix. There are four entries to include, including the negative one.
The first row contributes . The second contributes . Add those contributions, then take the square root: .
For a matrix with rows and columns, the definition is
Here means the entry in row , column . The two sums visit every column in every row. The double bars mean a norm, and the subscript specifies the Frobenius norm. The result is one nonnegative number.
Matrix rows ; . Give its Frobenius norm.
Show answer and explanation
Squared entries total ; norm .
03Keep the norm and its square distinct#
Our example has two useful quantities: and . The squared norm is just the sum of squared entries. Taking a square root when a formula asks for the squared norm changes the quantity.
If the entries measure errors in meters, the norm has units of meters; the squared norm has units of square meters. The outer exponent in matters.
For entries and , adding absolute values gives , while the square-root-of-squares calculation gives . These are different ways to measure size.
Also include entries away from the diagonal. The Frobenius norm is not a determinant, a trace, or the square of a matrix product. Its definition is an entry-by-entry calculation.
Matrix rows ; . Claimed Frobenius norm . Repair.
Show answer and explanation
Squared entries total ; norm .
Nothing in the definition requires a square matrix. For the rectangular matrix below, the zero entries contribute zero, and all six positions are included.
The squared entries total , so . Different matrices can have the same norm; the single size does not identify the individual entries.
04Measure the difference between two matrices#
To measure the distance between two equally shaped matrices, first subtract corresponding entries. For example,
Subtracting corresponding entries gives
The distance is . Entries where the matrices agree contribute nothing.
The order of operations matters: form the residual matrix, then measure it. In general, is not .
For instance, matrices containing the single entries and each have norm . Their norms differ by zero, but their entries differ by . Measuring each matrix separately loses the information needed for distance.
Rows : ; . Rows : ; . Give .
Show answer and explanation
Residual rows ; ; norm .
05Read a matrix loss#
In a prediction problem, write for the residual matrix. A commonly chosen loss is
Read this in stages: square every residual, add the squares, then divide by . Here is the number of examples. The norm notation itself does not perform any averaging.
For two examples with two outputs each, suppose all four residuals equal . The squared Frobenius norm is , and this loss is .
This choice averages the summed output errors over examples, with an extra factor of one half. Averaging over every entry would use a different divisor. Always read the normalization around the norm, as well as the norm itself.
This size treats entries equally in their current units. If one output is measured in thousands and another in fractions, their squared contributions may be very different. Choosing units or weights is part of designing a loss; the Frobenius norm tells you exactly what the chosen formula counts.
Square every entry, add all the squares, and take the nonnegative square root. For an error norm, subtract the matrices first.
- Compute a matrix's Frobenius norm.
Further questions
Can an SVD give approximation error without rebuilding every entry?
Sources & further reading
- [1]Jay Gopalakrishnan, The Singular Value Decomposition ↗Textbook · Book