Course contents 05 / 15

05 / 15 · Bayesian Linear Models

The relevance vector machine

Give every weight its own prior precision, maximize the evidence, and most features switch themselves off: a sparse kernel model with error bars that competes with the support vector machine.

On this page 6

Fit a curve to 100 noisy points of sin⁡(x)/x\sin(x)/x, using a bias and one Gaussian bump centred on each point: 101 features. Bayesian linear regression puts one prior precision α\alpha on all the weights and chooses it by the evidence. Every weight comes out nonzero, so each prediction sums all 100 bumps, much as kernel ridge regression does. A support vector regression is sparse in principle, yet on these data, with its constants CC and ε\varepsilon chosen by cross-validation, it keeps 95 of the 100 points as support vectors.

Now give every weight its own precision αi\alpha_i and maximize the evidence over all 101 of them. Most of the precisions run off to infinity, their weights are pinned at zero, and six bumps remain. The mechanism is called automatic relevance determination (ARD). On kernel features it gives the relevance vector machine (RVM) of Tipping (2001): a sparse kernel model that also reports a predictive variance and has no regularization constant to cross-validate.

Automatic relevance determination: one precision per weight#

The model is that of Bayesian linear regression: targets t∈Rnt \in \mathbb R^n, a design matrix Φ∈Rn×m\Phi \in \mathbb R^{n \times m} whose rows are the feature vectors φ(xi)⊤\varphi(x_i)^\top, and Gaussian noise of precision β\beta. Only the prior changes. Each weight gets an independent Gaussian with a precision of its own:

p(w∣α)=∏i=1mN(wi∣0, αi−1)=N(w∣0, A−1),\begin{aligned} p(w \mid \alpha) &= \prod_{i=1}^m \mathcal N\big(w_i \mid 0,\ \alpha_i^{-1}\big) \\ &= \mathcal N\big(w \mid 0,\ A^{-1}\big), \end{aligned}

where A=diag⁡(α1,…,αm)A = \operatorname{diag}(\alpha_1, \dots, \alpha_m). The derivations of the posterior and of the evidence in the previous note never used the prior covariance being a multiple of II. With AA in place of αI\alpha I they give

Σ=(A+βΦ⊤Φ)−1,μ=β Σ Φ⊤t,p(t∣α,β)=N(t∣0, C),C=β−1I+∑i=1mαi−1 ϕiϕi⊤,\boxed{ \begin{aligned} \Sigma &= \big(A + \beta\Phi^\top\Phi\big)^{-1}, \\ \mu &= \beta\,\Sigma\,\Phi^\top t, \\ p(t \mid \alpha, \beta) &= \mathcal N(t \mid 0,\ C), \\ C &= \beta^{-1} I + \sum_{i=1}^m \alpha_i^{-1}\, \phi_i \phi_i^\top , \end{aligned} }

where N(w∣μ,Σ)\mathcal N(w \mid \mu, \Sigma) is the posterior of the weights and ϕi∈Rn\phi_i \in \mathbb R^n is the ii-th column of Φ\Phi: the values of feature ii on all training inputs, not the feature vector φ(x)\varphi(x) of one input. The sum form of CC is ΦA−1Φ⊤\Phi A^{-1} \Phi^\top written column by column, which a diagonal A−1A^{-1} allows.

The sum form of CC, the covariance of the targets under the prior, shows what a precision does. Each feature adds αi−1ϕiϕi⊤\alpha_i^{-1}\phi_i\phi_i^\top to it. A small αi\alpha_i, a broad prior, lets the feature explain much variation along ϕi\phi_i. With αi=∞\alpha_i = \infty the term vanishes, the prior on wiw_i is a point mass at zero, so is its posterior, and the feature is out of the model. Choosing the αi\alpha_i by the evidence therefore chooses which features to keep.

The idea comes from neural networks, where one precision per group of weights leaving an input lets the data decide which inputs are relevant (MacKay, 1994; Neal, 1996). Why a Gaussian prior should produce exact zeros is clearer one level up. If each αi\alpha_i had a gamma prior and were integrated out, the prior on wiw_i would be a Student-tt, by the same gamma integral as the marginal of the mean: sharply peaked at zero, with heavy tails. With the hyperprior flat on a log scale, p(αi)∝1/αip(\alpha_i) \propto 1/\alpha_i, the integral is ∫0∞αi−1/2e−αiwi2/2 dαi∝1/∣wi∣\int_0^\infty \alpha_i^{-1/2} e^{-\alpha_i w_i^2/2}\, d\alpha_i \propto 1/\lvert w_i\rvert (Tipping, 2001, Section 5.1). Like the Laplace prior behind the lasso, it puts much of its mass near zero and still allows a few large weights. The RVM maximizes over the αi\alpha_i instead of integrating them out, which keeps every step Gaussian.

Type-II maximum likelihood: MacKay’s fixed point#

The log evidence is the boxed formula of the previous note with m2log⁡α\frac m2 \log\alpha replaced by 12∑ilog⁡αi\frac12\sum_i \log\alpha_i and α2∥μ∥2\frac\alpha2\lVert\mu\rVert^2 by 12μ⊤Aμ\frac12\mu^\top A\mu. We differentiate it in one αi\alpha_i. The derivative through μ\mu vanishes, as there, because μ\mu maximizes the exponent. The log-determinant term gives, by fact 2 with ∂αi(A+βΦ⊤Φ)=eiei⊤\partial_{\alpha_i}(A + \beta\Phi^\top\Phi) = e_i e_i^\top, ∂αilog⁡det⁡(A+βΦ⊤Φ)=tr⁡(Σ eiei⊤)=Σii\partial_{\alpha_i}\log\det(A + \beta\Phi^\top\Phi) = \operatorname{tr}(\Sigma\, e_i e_i^\top) = \Sigma_{ii}. So

∂log⁡p(t∣α,β)∂αi=12(1αi−μi2−Σii).\frac{\partial \log p(t \mid \alpha, \beta)}{\partial \alpha_i} = \frac12\Big(\frac{1}{\alpha_i} - \mu_i^2 - \Sigma_{ii}\Big) .

Setting it to zero and multiplying by 2αi2\alpha_i gives 1−αiΣii=αiμi21 - \alpha_i\Sigma_{ii} = \alpha_i \mu_i^2. The noise update is the one of the previous note, with tr⁡(Σ βΦ⊤Φ)\operatorname{tr}(\Sigma\,\beta\Phi^\top\Phi) in place of its γ\gamma; since Σ(A+βΦ⊤Φ)=I\Sigma(A + \beta\Phi^\top\Phi) = I, this trace is tr⁡(I−ΣA)=∑i(1−αiΣii)\operatorname{tr}(I - \Sigma A) = \sum_i (1 - \alpha_i\Sigma_{ii}). Together, the updates of MacKay (1992) used by Tipping (2001):

γi=1−αi Σii,αinew=γiμi2,1βnew=∥t−Φμ∥2n−∑iγi\boxed{ \begin{aligned} \gamma_i &= 1 - \alpha_i\,\Sigma_{ii}, \\ \alpha_i^{\text{new}} &= \frac{\gamma_i}{\mu_i^2}, \\ \frac{1}{\beta^{\text{new}}} &= \frac{\lVert t - \Phi\mu\rVert^2}{n - \sum_i \gamma_i} \end{aligned} }

γi∈[0,1]\gamma_i \in [0, 1] says how well the data determine weight ii. It lies in that range because Σ−1⪰A\Sigma^{-1} \succeq A, so Σ⪯A−1\Sigma \preceq A^{-1} and 0<Σii≤1/αi0 \lt \Sigma_{ii} \le 1/\alpha_i. When αi\alpha_i is large, the prior dominates, Σii≈1/αi\Sigma_{ii} \approx 1/\alpha_i and γi≈0\gamma_i \approx 0. When αi\alpha_i is small, the data dominate and γi≈1\gamma_i \approx 1. If all the αi\alpha_i are equal, the γi\gamma_i add up to the effective number of parameters γ=m−αtr⁡Σ\gamma = m - \alpha\operatorname{tr}\Sigma of the previous note: ARD counts it weight by weight.

Worked example. Take four points, two orthogonal features ϕ1=(1,1,2,2)\phi_1 = (1, 1, 2, 2) and ϕ2=(1,−1,−1,1)\phi_2 = (1, -1, -1, 1), targets t=(1.05,0.92,2.03,2.02)t = (1.05, 0.92, 2.03, 2.02), a known β=100\beta = 100, and both precisions starting at 1. Orthogonal columns make Φ⊤Φ=diag⁡(10,4)\Phi^\top\Phi = \operatorname{diag}(10, 4), so each weight is updated on its own:

QuantityWeight 1Weight 2
β ϕi⊤t\beta\,\phi_i^\top t100710071212
Σii\Sigma_{ii}1/10011/10011/4011/401
μi\mu_i1.0061.0060.02990.0299
γi\gamma_i0.9990.9990.99750.9975
αi\alpha_i after update 10.9870.98711141114
αi\alpha_i after updates 2 and 30.9870.98742054205, 12 79212\,792

The first feature is tt up to small noise, and its precision settles at once. The second only matches the noise. Its precision jumps by three orders of magnitude and keeps growing, by a factor that approaches 2.82.8 per update (derived below), until it passes 10910^9 after 14 updates and ϕ2\phi_2 is pruned.

Figure

Automatic relevance determination: one precision per weight

Automatic relevance determination: one precision per weightTwo orthogonal features, four points, β = 100, starting precisions (1, 1). The posterior covariance is diag(1/1001, 1/401), the mean (1.006, 0.030), γ = (0.999, 0.998), and the new precisions (0.987, 1114). On repetition α₁ stays at 0.987 while α₂ grows by about 2.8 per step and passes 10⁹ after 14 updates: the second feature gets weight zero.1122φ11−1−11φ21.050.922.032.02tα = (1, 1)one per weightΣ = diag(1/1001, 1/401)1.0060.030μ1γᵢ = 1 − αᵢΣᵢᵢ0.9990.998γ2γᵢ / μᵢ²0.9871,114αrepeat31,1144,20512,792…1.0·10⁹α21.0060wφ₂ pruned after 14 updates; α₁ → 0.987 = s₁²/(q₁² − s₁)4Automatic relevance determination: one precision per weightTwo orthogonal features, four points, β = 100, starting precisions (1, 1). The posterior covariance is diag(1/1001, 1/401), the mean (1.006, 0.030), γ = (0.999, 0.998), and the new precisions (0.987, 1114). On repetition α₁ stays at 0.987 while α₂ grows by about 2.8 per step and passes 10⁹ after 14 updates: the second feature gets weight zero.1122φ11−1−11φ21.050.922.032.02tα = (1, 1)one per weightΣ = diag(1/1001, 1/401)1.0060.030μ1γᵢ = 1 − αᵢΣᵢᵢ0.9990.998γ2γᵢ / μᵢ²0.9871,114α31,1144,20512,792…1.0·10⁹α21.0060wφ₂ pruned after 14 updates4
Two orthogonal features, four points, a known β = 100, starting precisions (1, 1). Green: the data; amber: the prior precisions; blue: the posterior; red: the result. The first feature nearly equals t, and its precision settles at once at 0.987 = s₁²/(q₁² − s₁). The second fits only noise, and α₂ grows until its weight is pinned at zero.

The algorithm alternates four steps, numbered as in the figure:

  1. compute Σ\Sigma and μ\mu for the current α\alpha and β\beta;
  2. compute every γi\gamma_i;
  3. compute the new αi\alpha_i and β\beta, and repeat until the precisions stop changing;
  4. remove every feature whose αi\alpha_i passes a large threshold, here 10910^9: its weight is zero to machine precision, and removing it shrinks the matrices of step 1.

Why most precisions go to infinity#

The fixed point says where the precisions end up. It does not say why so many of them end at infinity. Start with two targets and one feature. The evidence is then a Gaussian over tt with covariance β−1I+α−1ϕϕ⊤\beta^{-1} I + \alpha^{-1}\phi\phi^\top: a circle of noise, stretched along ϕ\phi by 1/α1/\alpha. If ϕ\phi points towards the observed tt, the stretch moves probability onto it. If ϕ\phi is poorly aligned with tt, the stretch spreads the same unit of probability along a direction with no data, and the density at tt falls; the best α\alpha is then infinite (Bishop, 2006, Section 7.2.2).

Faul and Tipping (2002) made this exact for any number of features, by looking at the evidence as a function of one αi\alpha_i with the others fixed. Split the covariance into the part without feature ii and its own term, C=C−i+αi−1ϕiϕi⊤C = C_{-i} + \alpha_i^{-1}\phi_i\phi_i^\top, and define

si=ϕi⊤C−i−1ϕi,qi=ϕi⊤C−i−1t.\begin{aligned} s_i &= \phi_i^\top C_{-i}^{-1}\phi_i, \\ q_i &= \phi_i^\top C_{-i}^{-1} t . \end{aligned}

The determinant lemma and Woodbury’s identity for a rank-one update, the m=1m = 1 case of the identities of the previous note, give

det⁡C=det⁡C−i (1+si/αi),t⊤C−1t=t⊤C−i−1t−qi2αi+si.\begin{aligned} \det C &= \det C_{-i}\,\big(1 + s_i/\alpha_i\big), \\ t^\top C^{-1} t &= t^\top C_{-i}^{-1} t - \frac{q_i^2}{\alpha_i + s_i} . \end{aligned}

Substituting both into log⁡N(t∣0,C)=−12(nlog⁡2π+log⁡det⁡C+t⊤C−1t)\log\mathcal N(t \mid 0, C) = -\frac12\big(n\log 2\pi + \log\det C + t^\top C^{-1}t\big) separates the dependence on αi\alpha_i:

log⁡p(t∣α,β)=log⁡p(t∣α−i,β)+ℓ(αi),ℓ(αi)=12(log⁡αiαi+si+qi2αi+si).\begin{aligned} \log p(t \mid \alpha, \beta) &= \log p(t \mid \alpha_{-i}, \beta) + \ell(\alpha_i), \\ \ell(\alpha_i) &= \frac12\Big(\log\frac{\alpha_i}{\alpha_i + s_i} + \frac{q_i^2}{\alpha_i + s_i}\Big) . \end{aligned}

The first term of ℓ\ell is negative and rises to 0 as αi→∞\alpha_i \to \infty: it is the Occam penalty for the spread the feature adds to CC. The second is the gain in fit, largest for small αi\alpha_i. Differentiating,

ℓ′(αi)=si2αi(αi+si)−qi22(αi+si)2=si2−αi (qi2−si)2 αi (αi+si)2.\begin{aligned} \ell'(\alpha_i) &= \frac{s_i}{2\alpha_i(\alpha_i + s_i)} - \frac{q_i^2}{2(\alpha_i + s_i)^2} \\ &= \frac{s_i^2 - \alpha_i\,(q_i^2 - s_i)}{2\,\alpha_i\,(\alpha_i + s_i)^2} . \end{aligned}

If qi2≤siq_i^2 \le s_i, the numerator is positive for every αi\alpha_i, ℓ\ell increases all the way, and the best value is infinity. If qi2>siq_i^2 \gt s_i, the numerator changes sign once, at the unique maximum:

  αi⋆={si2qi2−siif qi2>si,∞if qi2≤si.  \boxed{\; \alpha_i^{\star} = \begin{cases} \dfrac{s_i^2}{q_i^2 - s_i} & \text{if } q_i^2 \gt s_i , \\[2ex] \infty & \text{if } q_i^2 \le s_i . \end{cases} \;}

Tipping and Faul (2003) call sis_i the sparsity and qiq_i the quality of feature ii. qiq_i measures how well the feature lines up with what the model without it leaves unexplained; sis_i measures how much of ϕi\phi_i that model could already produce. A feature stays only if its quality, squared, beats its sparsity. In a kernel model with one bump per training point, neighbouring bumps are nearly the same vector. Once a few of them are in the model, the rest add little that is new: their qi2q_i^2 falls below sis_i, and they are pruned.

In the worked example the features are orthogonal. Then C−i=β−1I+αj−1ϕjϕj⊤C_{-i} = \beta^{-1} I + \alpha_j^{-1}\phi_j\phi_j^\top with ϕj⊥ϕi\phi_j \perp \phi_i maps ϕi\phi_i to β−1ϕi\beta^{-1}\phi_i, so C−i−1C_{-i}^{-1} acts on ϕi\phi_i as multiplication by β\beta, and si=β∥ϕi∥2s_i = \beta\lVert\phi_i\rVert^2, qi=β ϕi⊤tq_i = \beta\,\phi_i^\top t:

q22/s2=122/400=0.36,α1⋆=1000210072−1000=0.987.\begin{aligned} q_2^2 / s_2 &= 12^2 / 400 = 0.36, \\ \alpha_1^\star &= \frac{1000^2}{1007^2 - 1000} = 0.987 . \end{aligned}

The second feature fails the test, and the first one’s optimum is the value the iteration reached.

Figure

The evidence as a function of one precision

The evidence as a function of one precisionThree curves: for q²/s = 8 and q²/s = 2 the evidence has a maximum at a finite α; for q²/s = 0.36 it rises towards zero as α → ∞, and the feature is pruned.−2−101210⁻²10⁻¹11010²10³α / s (log scale)α = ∞q²/s = 8: maximum at α = s/7q²/s = 2: maximum at α = sq²/s = 0.36: best at α = ∞The evidence as a function of one precisionThree curves: for q²/s = 8 and q²/s = 2 the evidence has a maximum at a finite α; for q²/s = 0.36 it rises towards zero as α → ∞, and the feature is pruned.−2−101210⁻²10⁻¹11010²10³α / s (log scale)α = ∞q²/s = 8: maximum at α = s/7q²/s = 2: maximum at α = sq²/s = 0.36: best at α = ∞
The part of the log evidence that depends on one precision αᵢ, the others held fixed, measured from its value at αᵢ = ∞ (dashed). When q² > s (green, blue) the maximum is at αᵢ = s²/(q² − s), marked with a dot. When q² ≤ s (red, the second feature of the toy) the curve rises all the way, and the weight is pruned.

In the variables u=αi/siu = \alpha_i/s_i and r=qi2/sir = q_i^2/s_i the function is ℓ=12(log⁡u1+u+r1+u)\ell = \frac12\big(\log\frac{u}{1+u} + \frac{r}{1+u}\big), one curve per rr, with its maximum at u=1/(r−1)u = 1/(r - 1) when r>1r \gt 1. At a maximum of the evidence every coordinate is at its own optimum. The kept features therefore satisfy qi2>siq_i^2 \gt s_i with αi=si2/(qi2−si)\alpha_i = s_i^2/(q_i^2 - s_i), and the pruned ones qi2≤siq_i^2 \le s_i; the Code section checks both on the sinc data. The analysis also gives a much faster algorithm. Start from an empty model and repeatedly add, re-estimate or delete one feature, each time setting its αi\alpha_i to αi⋆\alpha_i^\star in closed form, so that the matrices never grow beyond the features in the model (Tipping and Faul, 2003).

Why MacKay’s update converges faster than EM#

The evidence can also be maximized by the EM algorithm, with the weights ww as the latent variable. The E-step is the posterior N(μ,Σ)\mathcal N(\mu, \Sigma). The M-step maximizes the expected complete-data log-likelihood, the expectation of log⁡p(t∣w,β)+log⁡p(w∣α)\log p(t \mid w, \beta) + \log p(w \mid \alpha) over that posterior:

Q(α,β)=n2log⁡β−β2 E∥t−Φw∥2+12∑i=1m(log⁡αi−αi E[wi2])+const.\begin{aligned} Q(\alpha, \beta) ={}& \frac n2 \log\beta - \frac\beta2\, \mathbb E\lVert t - \Phi w\rVert^2 \\ &+ \frac12 \sum_{i=1}^m \big(\log\alpha_i - \alpha_i\, \mathbb E[w_i^2]\big) + \text{const} . \end{aligned}

Only the prior depends on αi\alpha_i, and with E[wi2]=μi2+Σii\mathbb E[w_i^2] = \mu_i^2 + \Sigma_{ii}, setting ∂Q/∂αi=0\partial Q/\partial\alpha_i = 0 gives αi=1/(μi2+Σii)\alpha_i = 1/(\mu_i^2 + \Sigma_{ii}). For β\beta, write w=μ+δw = \mu + \delta with Eδ=0\mathbb E\delta = 0 and Cov⁡δ=Σ\operatorname{Cov}\delta = \Sigma. The cross term vanishes because Eδ=0\mathbb E\delta = 0, and E[δ⊤Mδ]=tr⁡(MΣ)\mathbb E[\delta^\top M \delta] = \operatorname{tr}(M\Sigma) for a fixed matrix MM, by the cyclic property of the trace:

E∥t−Φw∥2=E∥(t−Φμ)−Φδ∥2=∥t−Φμ∥2+E[δ⊤Φ⊤Φ δ]=∥t−Φμ∥2+tr⁡(ΦΣΦ⊤).\begin{aligned} \mathbb E\lVert t - \Phi w\rVert^2 &= \mathbb E\lVert (t - \Phi\mu) - \Phi\delta\rVert^2 \\ &= \lVert t - \Phi\mu\rVert^2 + \mathbb E[\delta^\top \Phi^\top\Phi\, \delta] \\ &= \lVert t - \Phi\mu\rVert^2 + \operatorname{tr}(\Phi\Sigma\Phi^\top) . \end{aligned}

Setting ∂Q/∂β=n/(2β)−12 E∥t−Φw∥2\partial Q/\partial\beta = n/(2\beta) - \frac12\, \mathbb E\lVert t - \Phi w\rVert^2 to zero,

1βEM=∥t−Φμ∥2+tr⁡(ΦΣΦ⊤)n.\frac{1}{\beta^{\text{EM}}} = \frac{\lVert t - \Phi\mu\rVert^2 + \operatorname{tr}(\Phi\Sigma\Phi^\top)}{n} .

The trace is the residual variance added by the posterior spread of the weights. Since βtr⁡(ΦΣΦ⊤)=tr⁡(Σ βΦ⊤Φ)=∑iγi\beta\operatorname{tr}(\Phi\Sigma\Phi^\top) = \operatorname{tr}(\Sigma\,\beta\Phi^\top\Phi) = \sum_i \gamma_i, as for MacKay’s update above, a fixed point satisfies n/β=∥t−Φμ∥2+∑iγi/βn/\beta = \lVert t - \Phi\mu\rVert^2 + \sum_i\gamma_i/\beta, which rearranges to MacKay’s 1/β=∥t−Φμ∥2/(n−∑iγi)1/\beta = \lVert t - \Phi\mu\rVert^2/(n - \sum_i\gamma_i). The two noise updates share their fixed points.

EM never decreases the evidence, because it is coordinate ascent on a lower bound that touches the evidence after each E-step. MacKay’s update has no such guarantee, yet Tipping found it much faster and never saw it take a downhill step (Tipping, 2001, Appendix A).

The sparsity and quality show why. With the other precisions fixed, Σii=1/(αi+si)\Sigma_{ii} = 1/(\alpha_i + s_i) and μi=qi/(αi+si)\mu_i = q_i/(\alpha_i + s_i).

Derivation

The last section writes the posterior through CC: Σ=A−1−A−1Φ⊤C−1ΦA−1\Sigma = A^{-1} - A^{-1}\Phi^\top C^{-1}\Phi A^{-1} and μ=A−1Φ⊤C−1t\mu = A^{-1}\Phi^\top C^{-1} t. Their ii-th entries are Σii=1/αi−ϕi⊤C−1ϕi/αi2\Sigma_{ii} = 1/\alpha_i - \phi_i^\top C^{-1}\phi_i/\alpha_i^2 and μi=ϕi⊤C−1t/αi\mu_i = \phi_i^\top C^{-1} t/\alpha_i. The rank-one Woodbury identity for C=C−i+αi−1ϕiϕi⊤C = C_{-i} + \alpha_i^{-1}\phi_i\phi_i^\top gives

ϕi⊤C−1ϕi=si−si2αi+si=αisiαi+si,ϕi⊤C−1t=qi−siqiαi+si=αiqiαi+si.\begin{aligned} \phi_i^\top C^{-1}\phi_i &= s_i - \frac{s_i^2}{\alpha_i + s_i} = \frac{\alpha_i s_i}{\alpha_i + s_i}, \\ \phi_i^\top C^{-1} t &= q_i - \frac{s_i q_i}{\alpha_i + s_i} = \frac{\alpha_i q_i}{\alpha_i + s_i} . \end{aligned}

Substituting, Σii=1/αi−si/(αi(αi+si))=1/(αi+si)\Sigma_{ii} = 1/\alpha_i - s_i/\big(\alpha_i(\alpha_i + s_i)\big) = 1/(\alpha_i + s_i) and μi=qi/(αi+si)\mu_i = q_i/(\alpha_i + s_i).

Then γi=1−αiΣii=si/(αi+si)\gamma_i = 1 - \alpha_i\Sigma_{ii} = s_i/(\alpha_i + s_i), and the two updates of αi\alpha_i, γi/μi2\gamma_i/\mu_i^2 and 1/(μi2+Σii)1/(\mu_i^2 + \Sigma_{ii}), become

αiMacKay=si (αi+si)qi2,αiEM=(αi+si)2αi+si+qi2.\begin{aligned} \alpha_i^{\text{MacKay}} &= \frac{s_i\,(\alpha_i + s_i)}{q_i^2}, \\ \alpha_i^{\text{EM}} &= \frac{(\alpha_i + s_i)^2}{\alpha_i + s_i + q_i^2} . \end{aligned}

Both have the fixed point si2/(qi2−si)s_i^2/(q_i^2 - s_i). They differ for a feature that should leave, with qi2<siq_i^2 \lt s_i. For large αi\alpha_i, MacKay’s update multiplies αi\alpha_i by about si/qi2s_i/q_i^2: a geometric climb. EM is (αi+si)/(1+qi2/(αi+si))≈(αi+si)(1−qi2/(αi+si))(\alpha_i + s_i)\big/\big(1 + q_i^2/(\alpha_i + s_i)\big) \approx (\alpha_i + s_i)\big(1 - q_i^2/(\alpha_i + s_i)\big), so it adds about si−qi2s_i - q_i^2: a linear climb. In the worked example the factor is 400/144=2.8400/144 = 2.8 and the step 256, so α2\alpha_2 passes 10910^9 after 14 MacKay updates and after 3,906,246 EM updates. On the sinc data below, 5,000 EM iterations reach a log evidence of 81.94481.944, against 81.95481.954 for MacKay’s 378, and have not pruned a single feature.

The RVM on kernel features, and the SVM#

With kernel features φ(x)=(1,K(x,x1),…,K(x,xn))\varphi(x) = (1, K(x, x_1), \dots, K(x, x_n)), so m=n+1m = n + 1, the training inputs whose kernels survive are the relevance vectors. The RVM predicts with them alone:

p(t∗∣x∗,t)=N(t∗∣μ⊤φ∗, σ∗2),σ∗2=β−1+φ∗⊤Σ φ∗,\begin{aligned} p(t_* \mid x_*, t) &= \mathcal N\big(t_* \mid \mu^\top\varphi_*,\ \sigma_*^2\big), \\ \sigma_*^2 &= \beta^{-1} + \varphi_*^\top\Sigma\,\varphi_* , \end{aligned}

with μ\mu, Σ\Sigma and the features φ∗=φ(x∗)\varphi_* = \varphi(x_*) restricted to the kept ones. KK only defines a set of basis functions, so it does not have to be a positive semidefinite kernel: ΦA−1Φ⊤\Phi A^{-1}\Phi^\top is a valid covariance for any Φ\Phi, since v⊤ΦA−1Φ⊤v=∥A−1/2Φ⊤v∥2≥0v^\top \Phi A^{-1}\Phi^\top v = \lVert A^{-1/2}\Phi^\top v\rVert^2 \ge 0.

ε\varepsilon-insensitive SVRRVM regression
Sparse insupport vectors, on or outside the ε\varepsilon-tuberelevance vectors, with qi2>siq_i^2 \gt s_i
Number of themtypically grows linearly with nn (Tipping, 2001, Section 1)usually far fewer
RegularizationCC and ε\varepsilon by cross-validationαi\alpha_i and β\beta by the evidence
Kernelpositive semidefiniteany basis functions
Outputa point estimatea Gaussian predictive distribution
Traininga convex quadratic programnon-convex; O(m3)O(m^3) per iteration, m=n+1m = n + 1 at the start

Tipping’s own comparison uses 100 evenly spaced points of sin⁡(x)/x\sin(x)/x on [−10,10][-10, 10] and a linear-spline kernel (Tipping, 2001, Section 4.1). In the noise-free case the SVR has ε=0.01\varepsilon = 0.01 and the RVM a noise level fixed at 0.010.01; in the noisy case the noise is uniform on [−0.2,0.2][-0.2, 0.2] and the SVR’s CC and ε\varepsilon come from 5-fold cross-validation.

Sinc, 100 pointsSVRRVM
no noise: vectors kept369
no noise: largest error0.01000.01000.00700.0070
noise: vectors kept296
noise: RMS deviation from the true function0.02910.02910.02450.0245

Worked example. Our own run is the one of the opening: the same 100 inputs, Gaussian noise of standard deviation 0.10.1, a bias and one Gaussian kernel K(x,x′)=exp⁡(−(x−x′)2/(2⋅22))K(x, x') = \exp\big(-(x - x')^2/(2 \cdot 2^2)\big) per point. All 101 precisions start at 1, and β\beta is estimated too. The SVR uses the same kernel and picks CC and ε\varepsilon by 5-fold cross-validation from a grid of 16 pairs.

RVMSVR
vectors kept6 of 101 features95 of 100 points
RMS distance from sin⁡(x)/x\sin(x)/x0.0400.0400.0500.050
settings378 iterations, noise level 0.0900.090ε=0.01\varepsilon = 0.01, the smallest offered

The six kernels sit at −5.96-5.96, −3.13-3.13, −0.71-0.71, 5.155.15, 8.188.18 and 1010, and the bias is pruned. At the optimum every kept feature has qi2/si>1q_i^2/s_i \gt 1 and every pruned one qi2/si≤0.944q_i^2/s_i \le 0.944. One dataset and one grid do not rank the two methods; the contrast in the number of vectors is the typical one.

Figure

The relevance vector machine on the sinc function

The relevance vector machine on the sinc functionOne hundred noisy points of sin x / x on −10 to 10, the predictive mean of the relevance vector machine and its band of ± 2 standard deviations. Six points whose kernels stayed in the model are circled. Beyond the data the mean decays to zero and the band does not widen.00.51−10−50510predictive meanmean ± 2 sdsin x / xdatarelevance vectorsThe relevance vector machine on the sinc functionOne hundred noisy points of sin x / x on −10 to 10, the predictive mean of the relevance vector machine and its band of ± 2 standard deviations. Six points whose kernels stayed in the model are circled. Beyond the data the mean decays to zero and the band does not widen.00.51−10−50510predictive meanmean ± 2 sdsin x / xdatarelevance vectors
One hundred noisy points of sin x / x, a bias and one Gaussian kernel of width 2 per point. The evidence keeps 6 kernels (circled) and prunes the bias; the band is the mean ± 2 predictive standard deviations. Beyond the data (dashed verticals) the band does not widen: at x = 15 the standard deviation is 0.090, the estimated noise level.

Where it breaks#

The figure shows the weak point of the RVM’s error bars. Over the data the predictive standard deviation stays between 0.0900.090 and 0.0990.099. At x=15x = 15, far outside the data, it is 0.0900.090, the noise level itself. The kept kernels are localized, so far from all of them φ∗→0\varphi_* \to 0, the term φ∗⊤Σφ∗\varphi_*^\top\Sigma\varphi_* vanishes, and only β−1\beta^{-1} is left. The model is as confident where it has no data as where it has the most (Rasmussen and Quiñonero-Candela, 2005). The prior over functions that the RVM implies is a degenerate Gaussian process, with six basis functions placed by the training inputs themselves (Rasmussen and Williams, 2006, Section 6.6); Gaussian processes with a stationary kernel do not have this flaw.

The other failures are of cost and of approximation. The evidence is not concave in the precisions: already along one coordinate, ℓ(αi)\ell(\alpha_i) falls after its maximum towards the horizontal asymptote 0, and a concave function that starts to fall can never level off. So different starting values, pruning thresholds or stopping rules can end at different sets of relevance vectors. The first iterations invert an (n+1)×(n+1)(n + 1) \times (n + 1) matrix, O(n3)O(n^3) time and O(n2)O(n^2) memory, which Tipping notes becomes impractical when the training examples number several thousand; the sequential algorithm avoids most of it. The evidence sets the αi\alpha_i and β\beta but not, in the basic algorithm, the width of the kernel, which is still cross-validated. And with one hyperparameter per weight, maximizing the evidence instead of integrating over the precisions is a cruder approximation than in the previous note. The exact zeros belong to that approximation: with proper gamma hyperpriors the precisions grow large but stay finite (Tipping, 2001, Section 2).

Redundant features are pruned, but an exact copy is not. If two columns are equal, ϕ1=ϕ2=ϕ\phi_1 = \phi_2 = \phi, then by the sum form of CC the two terms α1−1ϕϕ⊤\alpha_1^{-1}\phi\phi^\top and α2−1ϕϕ⊤\alpha_2^{-1}\phi\phi^\top merge, CC depends only on α1−1+α2−1\alpha_1^{-1} + \alpha_2^{-1}, and the evidence cannot tell how the prior variance is split between the two weights. MacKay’s update does not choose either.

To see it, write the posterior through CC. Woodbury’s identity of fact 6, with βI\beta I as the middle matrix, and the push-through identity (A+βΦ⊤Φ)−1βΦ⊤=A−1Φ⊤C−1(A + \beta\Phi^\top\Phi)^{-1}\beta\Phi^\top = A^{-1}\Phi^\top C^{-1}, checked by multiplying both sides by A+βΦ⊤ΦA + \beta\Phi^\top\Phi on the left and by CC on the right, give

Σ=A−1−A−1Φ⊤C−1ΦA−1,μ=β Σ Φ⊤t=A−1Φ⊤C−1t.\begin{aligned} \Sigma &= A^{-1} - A^{-1}\Phi^\top C^{-1}\Phi A^{-1}, \\ \mu &= \beta\,\Sigma\,\Phi^\top t = A^{-1}\Phi^\top C^{-1} t . \end{aligned}

With two equal columns, the entries for i=1,2i = 1, 2 involve only S=ϕ⊤C−1ϕS = \phi^\top C^{-1}\phi and Q=ϕ⊤C−1tQ = \phi^\top C^{-1} t: μi=Q/αi\mu_i = Q/\alpha_i and Σii=1/αi−S/αi2\Sigma_{ii} = 1/\alpha_i - S/\alpha_i^2, so γi=1−αiΣii=S/αi\gamma_i = 1 - \alpha_i\Sigma_{ii} = S/\alpha_i. MacKay’s update gives αinew=γi/μi2=αiS/Q2\alpha_i^{\text{new}} = \gamma_i/\mu_i^2 = \alpha_i S/Q^2 for both: the same factor, so their ratio never changes. In the Code section, precisions started at 1 and 2 end at 1.661.66 and 3.323.32, and both features stay. A copy perturbed by noise of standard deviation 0.050.05 is pruned within 20 updates.

What you should remember#

  • ARD: prior N(0,A−1)\mathcal N(0, A^{-1}), A=diag⁡(αi)A = \operatorname{diag}(\alpha_i); posterior and evidence as in Bayesian linear regression with AA for αI\alpha I.
  • MacKay’s update: γi=1−αiΣii\gamma_i = 1 - \alpha_i\Sigma_{ii}, αi←γi/μi2\alpha_i \leftarrow \gamma_i/\mu_i^2; features with huge αi\alpha_i are pruned.
  • One precision at a time: αi⋆=si2/(qi2−si)\alpha_i^\star = s_i^2/(q_i^2 - s_i) if qi2>siq_i^2 \gt s_i, else ∞\infty; redundant features fail the test.
  • MacKay’s update drives a useless αi\alpha_i up geometrically, EM only linearly.
  • RVM = ARD on kernel features: far fewer vectors than the SVM, error bars, any basis functions.
  • Its error bars shrink to the noise level far from the data.

Code#

ARD by MacKay’s fixed point, the toy example and its qq and ss, the number of updates each rule needs to prune, the RVM on noisy sinc data with the sparsity condition checked at the optimum, EM on the same data, an SVR, and an exact copy of a feature that is never pruned. The script runs in about four seconds; exact numbers, and in rare cases the set of relevance vectors, can differ across platforms and library versions.

import numpy as np
from sklearn.svm import SVR
from sklearn.model_selection import GridSearchCV
np.set_printoptions(suppress=True)

def rvm(Phi, t, rule='mackay', iters=5000, prune=1e9, tol=1e-6):
    """Type-II maximum likelihood with one precision per weight and an estimated noise precision.
    rule='mackay' uses the fixed point, rule='em' the EM updates; weights whose precision passes `prune` are removed."""
    n, m = Phi.shape
    alpha, keep, b = np.ones(m), np.arange(m), 1 / np.var(t)
    for it in range(1, iters + 1):
        P = Phi[:, keep]
        S = np.linalg.inv(np.diag(alpha[keep]) + b * P.T @ P)     # posterior covariance of the kept weights
        mu = b * S @ P.T @ t                                       # posterior mean
        gamma = 1 - alpha[keep] * np.diag(S)                       # how well each weight is determined
        if rule == 'mackay':
            new = gamma / mu ** 2
            b = (n - gamma.sum()) / np.sum((t - P @ mu) ** 2)
        else:                                                      # EM with w as the latent variable
            new = 1 / (mu ** 2 + np.diag(S))
            b = n / (np.sum((t - P @ mu) ** 2) + np.trace(P @ S @ P.T))
        change = np.max(np.abs(np.log(new / alpha[keep])))
        alpha[keep] = new
        alpha[keep[new >= prune]] = np.inf                         # the weight is pinned at zero: prune it
        keep = keep[new < prune]
        if change < tol: break
    P = Phi[:, keep]
    S = np.linalg.inv(np.diag(alpha[keep]) + b * P.T @ P)
    C = np.eye(n) / b + P @ np.diag(1 / alpha[keep]) @ P.T
    logev = -0.5 * (n * np.log(2 * np.pi) + np.linalg.slogdet(C)[1] + t @ np.linalg.solve(C, t))
    return keep, b * S @ P.T @ t, S, alpha, b, it, logev

# the toy: two orthogonal features, the noise precision beta = 100 known, alpha starts at (1, 1)
Phi = np.array([[1, 1], [1, -1], [2, -1], [2, 1.0]])
t = np.array([1.05, 0.92, 2.03, 2.02])
alpha = np.ones(2)
for k in range(1, 15):
    S = np.linalg.inv(np.diag(alpha) + 100 * Phi.T @ Phi)
    mu = 100 * S @ Phi.T @ t
    gamma = 1 - alpha * np.diag(S)
    alpha = gamma / mu ** 2
    if k <= 3 or k == 14: print(k, mu.round(4), gamma.round(4), alpha.round(3).tolist())
# 1 [1.006  0.0299] [0.999  0.9975] [0.987, 1113.889]
# 2 [1.006  0.0079] [0.999  0.2642] [0.987, 4205.247]
# 3 [1.006  0.0026] [0.999  0.0869] [0.987, 12792.353]
# 14 [1.006 0.   ] [0.999 0.   ] [0.987, 1019386918.681]: alpha_2 passes 1e9 after 14 updates
s, q = 100 * (Phi ** 2).sum(axis=0), 100 * Phi.T @ t            # for orthogonal features s_i = beta |phi_i|^2, q_i = beta phi_i . t
print(s, q, (q ** 2 / s).round(2), round(s[0] ** 2 / (q[0] ** 2 - s[0]), 4), round(alpha[0], 4))
# [1000.  400.] [1007.   12.] [1014.05    0.36] 0.9871 0.9871: q^2 > s for phi_1 only, and alpha_1 = s^2/(q^2 - s)

# the two updates of alpha_2 written in s and q: MacKay multiplies, EM adds
def updates_to_prune(update, a=1.0, k=0):
    while a < 1e9: a, k = update(a), k + 1
    return k
print(updates_to_prune(lambda a: s[1] * (a + s[1]) / q[1] ** 2), updates_to_prune(lambda a: (a + s[1]) ** 2 / (a + s[1] + q[1] ** 2)))
# 14 3906246

# 100 noisy points of sinc(x) = sin(x)/x, a bias and one Gaussian kernel of width 2 per point: m = 101 features
rng = np.random.default_rng(0)
x = np.linspace(-10, 10, 100)
sinc = lambda x: np.sinc(x / np.pi)
t = sinc(x) + 0.1 * rng.normal(size=100)
K = lambda a, b: np.exp(-(a[:, None] - b[None, :]) ** 2 / (2 * 2.0 ** 2))
feat = lambda z: np.hstack([np.ones((len(z), 1)), K(z, x)])
Phi = feat(x)
keep, mu, S, alpha, beta, it, logev = rvm(Phi, t)
xg = np.linspace(-10, 10, 1000)
Pg = feat(xg)[:, keep]
print(it, len(keep), 0 in keep, x[keep - 1].round(2), round(1 / np.sqrt(beta), 4))   # 378 6 False [-5.96 -3.13 -0.71 5.15 8.18 10.  ] 0.0902
print(round(np.sqrt(np.mean((Pg @ mu - sinc(xg)) ** 2)), 4))              # 0.0403: RMS distance to the true sinc on a fine grid
sd = lambda P: np.sqrt(1 / beta + np.einsum('ij,jk,ik->i', P, S, P))
print(sd(Pg).min().round(4), sd(Pg).max().round(4), sd(feat(np.array([15.0]))[:, keep]).round(4))   # 0.0903 0.0993 [0.0903]: as confident at x = 15 as anywhere

# the sparsity condition at the optimum: q_i^2 > s_i exactly for the kept features, alpha_i = s_i^2/(q_i^2 - s_i)
C = np.eye(100) / beta + Phi[:, keep] @ np.diag(1 / alpha[keep]) @ Phi[:, keep].T
r, ok = [], True
for i in range(101):
    phi = Phi[:, i]
    Cm = C - np.outer(phi, phi) / alpha[i] if i in keep else C           # C without feature i
    s_i, q_i = phi @ np.linalg.solve(Cm, phi), phi @ np.linalg.solve(Cm, t)
    r.append(q_i ** 2 / s_i)
    if i in keep: ok &= bool(np.isclose(alpha[i], s_i ** 2 / (q_i ** 2 - s_i), rtol=1e-3))
r = np.array(r)
print(bool(np.all(r[keep] > 1)), bool(np.all(np.delete(r, keep) <= 1 + 1e-6)), ok, np.delete(r, keep).max().round(3))   # True True True 0.944

# EM on the same data: almost the same evidence after 5000 iterations, and nothing pruned yet
keep_em, *_, it_em, logev_em = rvm(Phi, t, rule='em')
print(round(logev, 3), it_em, len(keep_em), round(logev_em, 3))         # 81.954 5000 101 81.944

# a support vector regression with the same kernel, C and epsilon chosen by 5-fold cross-validation
svr = GridSearchCV(SVR(kernel='rbf', gamma=1 / (2 * 2.0 ** 2)), {'C': [0.1, 1, 10, 100], 'epsilon': [0.01, 0.05, 0.1, 0.2]}, cv=5).fit(x[:, None], t)
best = svr.best_estimator_
print(svr.best_params_, len(best.support_), round(np.sqrt(np.mean((best.predict(xg[:, None]) - sinc(xg)) ** 2)), 4))
# {'C': 1, 'epsilon': 0.01} 95 0.0497: 95 of the 100 points are support vectors

# an exact copy of a feature is never pruned: MacKay's update multiplies both precisions by the same factor
rng = np.random.default_rng(1)
f1, f2 = rng.normal(size=50), rng.normal(size=50)
t = f1 + 0.5 * f2 + 0.3 * rng.normal(size=50)                          # noise precision beta = 1 / 0.09, known
for eps in (0.0, 0.05):
    Phi = np.column_stack([f1, f1 + eps * rng.normal(size=50), f2])    # the second column copies the first, exactly or with noise
    alpha = np.array([1.0, 2.0, 1.0])
    for _ in range(3000):
        k = alpha < 1e9
        S = np.linalg.inv(np.diag(alpha[k]) + Phi[:, k].T @ Phi[:, k] / 0.09)
        mu = S @ Phi[:, k].T @ t / 0.09
        alpha[k] = (1 - alpha[k] * np.diag(S)) / mu ** 2
    print(eps, np.where(alpha < 1e9, alpha, np.inf).round(2))
# 0.0 [1.66 3.32 3.88]: both copies kept, precisions still in the ratio 1 : 2
# 0.05 [1.11  inf 3.88]: the noisy copy is pruned

Next#

The RVM’s evidence was available in closed form because the likelihood was Gaussian. For classification it is not: the targets are 0 or 1, the likelihood is a product of sigmoids, and neither the posterior over the weights nor the evidence has a formula. The next note replaces the posterior by a Gaussian centred at its mode, with the curvature there as its precision. This Laplace approximation gives Bayesian logistic regression, its moderated predictions, and the classification version of the RVM.

References#