Quiz: sparse coding and dictionary learning
Before this unit: Fast MRI with compressed sensing (previous unit); Day 7: Wavelets; Day 5: Deconvolution.
See also: Transform coding, the DCT and the KLT (day 8); Day 8: Image compression; Day 9: Radon transform and tomography; Day 28: Ising model and Markov random fields.
Short questions to test your understanding. Try each on paper first, then open the answer.
Q1. What is a dictionary, and what does sparse coding of a patch mean?
A patch is a vector.
A dictionary is a set of atoms: vectors of the same size as the patch (64 for 8 × 8). Sparse coding writes a patch as a weighted sum of only a few atoms, chosen per patch (for example by OMP).
Q2. Why use more atoms than pixels (an overcomplete dictionary)? What does it cost?
More choice.
More atoms give more choice, so each patch can be written with fewer of them (sparser codes, smaller error for a given number of atoms). The cost: the representation is no longer unique and coding becomes an optimisation (OMP or ℓ1) per patch instead of a matrix product.
Q3. Describe the two alternating steps of dictionary learning.
Fix one, improve the other.
- Sparse coding: with the atoms fixed, code every training patch with a few atoms (OMP). (2) Atom update: with the supports fixed, change the atoms (and their coefficients) to fit the patches better: K-SVD updates each atom as the best rank-1 fit to the residuals of the patches that use it; MOD solves for all atoms at once by least squares.
Q4. In what sense is k-means a special case of dictionary learning? Why does it give “blurry averages” as atoms?
How many atoms per patch, with which coefficient?
Each patch uses exactly one atom with coefficient 1: assignment to the nearest centre is the coding, the cluster mean is the atom update. The atoms are averages of many different patches (an edge in different positions and contrasts), so they are blurry; K-SVD allows any coefficient and a few atoms, so atoms can be sharp patterns that are scaled and combined.
Q5. PCA gives orthogonal atoms ordered by variance. Why can a learned dictionary represent patches better with the same number K of coefficients?
Linear vs sparse approximation.
PCA uses the same first K components for every patch (linear approximation, optimal among those). A learned, overcomplete dictionary lets each patch choose its own K atoms out of many (non-linear, sparse approximation): an edge patch picks edge atoms at the right position and orientation. On the micrograph at K = 4: error 639 for PCA, 330 for the learned dictionary.
Q6. In K-SVD denoising, when does OMP stop coding a patch, and why does that remove noise?
How large is the noise in a patch?
When the residual energy drops to about the noise energy of the patch, 64\cdot(1.15σ)^2 for 8 × 8. The structure is captured by a few atoms; the noise is not sparse in any atom and would need many more, so stopping at the noise level leaves it in the residual.
Q7. Why can patch inpainting fill thin scratches but put invented structure into a large hole?
How many known pixels does a patch inside the hole have?
Around a thin scratch each patch has many known pixels, which determine its code well. Inside a hole larger than a patch, no patch sees any known pixel; the hole is filled from the border inwards, and each step extrapolates from previous guesses: the atoms continue whatever pattern fits the border, which can be wrong (a dark blob in the lecture’s example).
Q8. (math) Show that the K-SVD update of one atom is a rank-1 approximation problem and how it is solved.
Isolate the term of atom k in DC.
\|Y - DC\|_F^2 = \|E_k - \mathbf d_k\mathbf c^k\|_F^2 with E_k = Y - \sum_{j\ne k}\mathbf d_j\mathbf c^j. Restricted to the patches that use atom k, we minimise over a unit vector \mathbf d_k and a free row \mathbf c^k: the best rank-1 approximation of E_k^R, given by its leading singular pair (\mathbf d_k = \mathbf u_1, \mathbf c^k = σ_1\mathbf v_1^\top), i.e. the top eigenvector of E_k^RE_k^{R\top}.