Algorithm Search⌘K

Problemadvanced

Dictionary learning

Also called sparse dictionary learning.

Find a dictionary of atoms and sparse codes such that every training signal is close to a sparse combination of the atoms.

Dictionary learning is the problem of finding, from many training signals, a set of atoms such that every signal is close to a combination of a few of them. It is the inverse of sparse signal recovery: there the matrix is given and only the sparse vector is unknown, here both are unknown and only the signals are given. It generalizes k-means, where each signal uses one atom with coefficient 1, and principal component analysis, where all signals share one subspace. This page states the problem and what is known about it. K-SVD is one algorithm for it, and convolutional sparse coding is the model in which the atoms are small filters shifted over a whole image.

In plain words

Think of a box of stamps. Every picture in a large collection should be made by pressing only a few stamps, each with its own strength. You do not have the stamps yet. Dictionary learning asks for the box of stamps that does this best for the collection, together with the recipe for each picture. Two things are unknown at once, the stamps and the recipes, and this makes the problem hard. The usual methods fix one, improve the other, and repeat.

Definition

Input. Training signals y1,…,yN∈Rny_1, \dots, y_N \in \mathbb{R}^n, the columns of Y∈Rn×NY \in \mathbb{R}^{n \times N}, a number of atoms KK and a sparsity level s≤Ks \le K.

Output. A dictionary D=[d1,…,dK]∈Rn×KD = [d_1, \dots, d_K] \in \mathbb{R}^{n \times K} with ∥dk∥2=1\|d_k\|_2 = 1 and codes X=[x1,…,xN]∈RK×NX = [x_1, \dots, x_N] \in \mathbb{R}^{K \times N} that solve

min⁡D,X ∥Y−DX∥F2=∑i=1N∥yi−Dxi∥22subject to∥xi∥0≤s for all i.\min_{D, X}\ \|Y - DX\|_F^2 = \sum_{i=1}^N\|y_i - Dx_i\|_2^2 \quad\text{subject to}\quad \|x_i\|_0 \le s \text{ for all } i.

Here ∥x∥0\|x\|_0 counts the nonzero entries. The dictionary is overcomplete when K>nK > n, complete when K=nK = n.

Forward model. The usual generative model behind the problem is yi=D⋆xi⋆+wiy_i = D^\star x_i^\star + w_i with an unknown dictionary D⋆D^\star, codes xi⋆x_i^\star with at most ss nonzeros, and noise wiw_i, often Gaussian. The fit above is the maximum likelihood estimate under Gaussian noise when the codes are only known to be ss-sparse.

Ambiguities. Permuting the atoms and permuting the rows of XX in the same way, or changing the sign of an atom and of its row of XX, does not change DXDX. So a solution is at best unique up to these 2KK!2^K K! signed permutations. The norm constraint removes the scale ambiguity: without it, D→cDD \to cD and X→X/cX \to X/c would make any penalty on the size of XX meaningless.

Uniqueness and stability. Aharon, Elad and Bruckstein showed in 2006 that if the signals are exactly ss-sparse in D⋆D^\star with ss below half the spark of D⋆D^\star, and the training set contains enough signals in general position on each ss-dimensional span, then D⋆D^\star is unique up to the ambiguities. The number of signals their argument needs is large. With noise, results on stability are local: they say that D⋆D^\star is a local minimum of the objective, or of its ℓ1\ell_1 form, for many random sparse codes.

Variants

  • Penalized form. min⁡D,X∑i12∥yi−Dxi∥22+λ∥xi∥1\min_{D, X}\sum_i \tfrac12\|y_i - Dx_i\|_2^2 + \lambda\|x_i\|_1 with ∥dk∥2≤1\|d_k\|_2 \le 1, as in online dictionary learning (Mairal, Bach, Ponce and Sapiro 2010). Olshausen and Field used a penalty of the same kind, a smooth function that favors sparse codes. For fixed DD it is a LASSO problem per signal, which is convex.
  • Error target. min⁡∑i∥xi∥0\min\sum_i\|x_i\|_0 subject to ∥yi−Dxi∥2≤ε\|y_i - Dx_i\|_2 \le \varepsilon for all ii. This form is used for denoising, with ε\varepsilon set by the noise level.
  • Complete and orthogonal dictionaries. With K=nK = n and DD orthogonal, the codes are DTYD^TY thresholded, and the update of DD is an orthogonal Procrustes problem solved by one singular value decomposition. With an invertible DD and independent sparse codes the problem is close to independent component analysis.
  • Analysis form. Learn an operator Ω\Omega such that Ωy\Omega y is sparse, instead of atoms that synthesize yy. The two forms differ when Ω\Omega is redundant; see analysis and synthesis sparsity.
  • Convolutional form. The atoms are filters shifted to all positions of a signal. The dictionary is then a union of convolution matrices, and the problem is solved in the Fourier domain. See convolutional sparse coding.
  • Structured dictionaries. D=BAD = BA with a fixed fast transform BB, for example a wavelet basis, and a sparse matrix AA. The product is fast to apply and needs fewer training signals.

Examples

Three signals in the plane. Let n=2n = 2, s=1s = 1 and

Y=(24112−2),∥Y∥F2=5+20+5=30.Y = \begin{pmatrix}2 & 4 & 1\\ 1 & 2 & -2\end{pmatrix}, \qquad \|Y\|_F^2 = 5 + 20 + 5 = 30.

With K=2K = 2 the signals lie on the two lines through (2,1)(2, 1) and (1,−2)(1, -2). The dictionary d1=(2,1)/5d_1 = (2, 1)/\sqrt5, d2=(1,−2)/5d_2 = (1, -2)/\sqrt5 with codes x1=(5,0)x_1 = (\sqrt5, 0), x2=(25,0)x_2 = (2\sqrt5, 0), x3=(0,5)x_3 = (0, \sqrt5) gives the error 0, so it is optimal. Swapping the two atoms and changing their signs gives the other 22⋅2!=82^2 \cdot 2! = 8 optimal pairs, and there are no more: each atom must be parallel to a signal, and both lines must be used.

With K=1K = 1 every signal uses the same atom dd, the best code is xi=⟨d,yi⟩x_i = \langle d, y_i\rangle, and the error is ∥Y∥F2−dTYYTd\|Y\|_F^2 - d^TYY^Td. So dd is the top eigenvector of

YYT=(21889),YY^T = \begin{pmatrix}21 & 8\\ 8 & 9\end{pmatrix},

with eigenvalues 15±225−125=2515 \pm \sqrt{225 - 125} = 25 and 55. The top eigenvector is (2,1)/5(2, 1)/\sqrt5, and the least error is 30−25=530 - 25 = 5, which is ∥(1,−2)∥2\|(1, -2)\|^2: the third signal is lost.

k-means. If s=1s = 1 and the coefficient of the one chosen atom must be 1, with no normalization of the atoms, the problem is exactly k-means clustering: each signal picks the nearest atom, and each atom is the mean of its signals. Without the coefficient rule, s=1s = 1 is gain-shape vector quantization: each signal picks the atom with the largest ∣⟨dk,yi⟩∣|\langle d_k, y_i\rangle|.

Image patches. In the denoising method of Elad and Aharon, the signals are the overlapping 8×88 \times 8 patches of an image, so n=64n = 64, and the dictionary has K=256K = 256 atoms. Learned atoms look like localized, oriented edges and textures. Olshausen and Field found the same kind of atoms in 1996 from natural image patches and compared them with the receptive fields of simple cells in the visual cortex.

Known algorithms

Method Dictionary update What is known
Alternating minimization (Olshausen and Field 1996) gradient step on DD after sparse inference for each signal the objective decreases with small steps; no global guarantee
MOD, method of optimal directions (Engan, Aase and Husoy 1999) D=YXT(XXT)−1D = YX^T(XX^T)^{-1}, then normalize the atoms the exact least squares update for fixed XX; normalization can increase the error slightly
K-SVD (Aharon, Elad and Bruckstein 2006) one atom at a time, with its coefficients, by the top singular pair of the residual on the signals that use it the objective does not increase with an exact sparse coder; with OMP it can
Online dictionary learning (Mairal, Bach, Ponce and Sapiro 2010) block coordinate descent on accumulated statistics, one signal or batch at a time for the ℓ1\ell_1 form; scales to millions of signals
Methods with guarantees (Spielman, Wang and Wright 2012; Arora, Ge and Moitra 2014; Agarwal and coauthors 2014) spectral or combinatorial starts, then alternating steps recover D⋆D^\star in polynomial time under random models of the codes, with incoherent atoms and sparsity of order at most about n\sqrt n

All the practical methods alternate between two steps: a sparse coding step with DD fixed, which is a sparse signal recovery problem per signal, solved by OMP, basis pursuit or ISTA, and a dictionary update with XX or its support fixed. Each step can only decrease the objective when it is solved exactly, but the coding step in the ℓ0\ell_0 form is not solved exactly in practice, and the objective is not convex in (D,X)(D, X) together. The result depends on the start, often random signals or a DCT basis.

AlgorithmTimeSpacePropertiesCode
K-SVDO(J N s n (K + n)) worstO(n (K + N)) extranot convexdeterministiciterative1 language

Bounds

  • Complexity. The sparse coding step alone, finding the best ss-sparse code for one signal and a fixed dictionary, is NP-hard (Natarajan 1995). Tillmann (2015) proved that dictionary learning itself is NP-hard: deciding whether YY has an exact factorization Y=DXY = DX with KK atoms and ss-sparse columns of XX is NP-hard, and so is approximating the problem within certain factors. These are worst case results over all inputs.
  • Rank bound. DXDX has rank at most KK, so by the Eckart-Young theorem every solution has error at least ∑j>Kσj(Y)2\sum_{j > K}\sigma_j(Y)^2, the sum of the squared singular values of YY beyond the KK-th. For K≥nK \ge n this bound is 0 and says nothing.
  • Sample size (a count, not a theorem). The data hold nNnN numbers, and the unknowns are nKnK dictionary entries plus sNsN code values. For the data to have a chance to determine them, nN≥nK+sNnN \ge nK + sN, that is N≥nK/(n−s)N \ge nK/(n - s). The known guarantees for polynomial time methods need many more signals than this count.
  • Local behavior. The alternating methods have no bound on the number of iterations needed to reach a global minimum, and they can stop at local minima with atoms that are never used.

Reductions

  • To k-means. With s=1s = 1, unit coefficients and no normalization, dictionary learning is k-means, and the alternating method is Lloyd's algorithm. K-SVD was designed as its generalization.
  • To principal component analysis. With s=K≤ns = K \le n, the sparsity constraint is empty and the problem is the best rank KK approximation of YY, solved by the truncated SVD. The atoms span the top KK left singular vectors.
  • From sparse coding. With DD fixed, each column of XX is a separate sparse approximation problem. So every method for dictionary learning contains a sparse recovery solver, and its hardness carries over.
  • Union of subspaces. An ss-sparse code places each signal in one of the (Ks)\binom{K}{s} subspaces spanned by ss atoms. Dictionary learning is fitting a union of subspaces with a shared set of spanning vectors, a constrained form of subspace clustering.

Applications

  • Denoising. Learn the dictionary from the noisy image's own patches, code each patch with an error target set by the noise, and average the overlapping patches (Elad and Aharon 2006). See image denoising.
  • Inpainting. Code each patch from its known pixels only, then fill the missing pixels from the code. See image inpainting.
  • Compressed sensing with learned sparsity. A dictionary learned from similar images replaces a fixed wavelet basis in the reconstruction, for example in MRI.
  • Compression. Codes with few nonzeros, stored with the indices of their atoms, for classes of signals such as faces.
  • Neuroscience. The sparse coding model of Olshausen and Field explains the shape of receptive fields in the primary visual cortex.

References

  1. Bruno A. Olshausen and David J. Field, Emergence of simple-cell receptive field properties by learning a sparse code for natural images, Nature 381(6583), 1996, pages 607 to 609 (the sparse coding objective, learning by alternating inference and gradient steps, and the localized oriented atoms learned from image patches)
  2. Kjersti Engan, Sven Ole Aase and John Hakon Husoy, Method of optimal directions for frame design, Proceedings of ICASSP 1999, the whole paper (the least squares dictionary update D = Y X^T (X X^T)^-1)
  3. Michal Aharon, Michael Elad and Alfred Bruckstein, K-SVD, an algorithm for designing overcomplete dictionaries for sparse representation, IEEE Transactions on Signal Processing 54(11), 2006, pages 4311 to 4322 (the problem with a sparsity constraint, the relation to k-means, and the atom by atom update)
  4. Michael Elad and Michal Aharon, Image denoising via sparse and redundant representations over learned dictionaries, IEEE Transactions on Image Processing 15(12), 2006, pages 3736 to 3745 (dictionaries learned from the noisy image itself and patch averaging)
  5. Andreas M. Tillmann, On the computational intractability of exact and approximate dictionary learning, IEEE Signal Processing Letters 22(1), 2015, pages 45 to 49 (NP-hardness of exact dictionary learning and of approximating it)
  6. B. K. Natarajan, Sparse approximate solutions to linear systems, SIAM Journal on Computing 24(2), 1995, pages 227 to 234 (sparse approximation with a fixed matrix is NP-hard)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a contract.yaml