ContentsThe library

How a Filter Reads a Picture

It Was a Matrix Multiply All Along

Last timeBuying Reach and Width More Cheaply

Write a convolution as an ordinary matrix and the constraint becomes visible: nearly every entry is zero, and the ones that are not are the same few numbers repeated.

A convolution is linear. That was noted in the first lesson and nothing since has

changed it: every operation in this course scales when the input scales and adds

when inputs add. Every linear operation from one list of numbers to another is a

matrix. So there is a matrix which, multiplied by the input laid out flat, gives

the output of a convolution, and writing it down is the most direct way to see

what the whole arrangement assumes.

FIG 1The operation as a single matrix
the input written as one long column, all positions in order
a matrix with one row per output position and one column per input position
the filter, the only numbers the matrix actually contains
the offset of the input from the output, which is the only thing the entry depends on
The whole content of the structure is in the last line: the entry depends on the difference between its indices and not on the indices themselves. A matrix with that property is exactly a convolution, which is the algebraic version of the shift argument from the second lesson.
FIG 2The matrix for a three-wide filter on seven inputs
x1x2x3x4x5x6x7
first output1-210000
second output01-21000
third output001-2100
fourth output0001-210
fifth output00001-21
Thirty five entries, of which twenty are zero and the remaining fifteen are three distinct numbers used five times each. A general matrix of this shape would hold thirty five independent weights. This one holds three. Everything this course has discussed is in that sentence.

Read the picture twice. The first reading is the zeros. An entry is zero exactly

when that input position falls outside the window of that output position, so the

band of non-zeros is the locality constraint and its width is the window width.

Widening the window widens the band; spacing the taps apart puts holes inside the

band; a stride of two deletes alternate rows.

The second reading is the repetition. Follow any diagonal and the same number

appears all the way down. That is the sharing constraint. A matrix with the same

band but independent entries would be a local layer without sharing, the

intermediate case named in the second lesson, and it would have as many weights

as there are entries in the band.

FIG 3Independent numbers against entries
a general matrix, one weight per pair of positions
local but unshared, one weight per entry in the band
local and shared, the filter and nothing else, with no mention of how many positions there are
Three counts for matrices of identical shape. The leftmost and the rightmost differ by a factor of the position count squared over the window width, which on a photograph is several hundred million. The middle column is the useful one for seeing that the two constraints are separate, since dropping either one lands there.

How it is actually computed

Nobody builds that matrix. It is mostly zeros, and multiplying by zeros is work

that produces nothing. What is done instead is a rearrangement in the other

direction: extract the patch under each window position and write it out as a

column, so that an input of one picture becomes a dense matrix with one column

per output position and one row per weight in a filter.

The lesson stops here

4 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01The Same Few Numbers, Everywhere
  2. 02The Constraint That Pays for Itselfopening only
  3. 03Where the Window Fits, and How Often It Stopsopening only
  4. 04One Filter Is Never Enoughopening only
  5. 05The Slow Widening of the Viewopening only
  6. 06Throwing Away Where, to Keep Whatopening only
  7. 07Two Discounts, Each With a Conditionopening only
  8. 08It Was a Matrix Multiply All Alongyou are here

Read alongside