Quiz: kernel functions and the kernel trick
Before this unit: Maximum margin and support vectors (previous unit); Day 33: Random forests.
See also: Day 36: Neural networks; Day 35: Gaussian mixtures.
Short questions to test your understanding. Try each on paper first, then open the answer. A kernel function is k(\mathbf x, \mathbf z) = \varphi(\mathbf x)\cdot\varphi(\mathbf z); the SVM’s decision function is f(\mathbf x) = \sum_i\alpha_iy_i\,k(\mathbf x_i, \mathbf x) + b.
Q1. Points inside a circle of radius 1 belong to one class, points in a ring around it to the other. Which single extra feature makes them linearly separable, and what is the separating plane?
What distinguishes the two classes?
The squared distance from the centre, x_3 = x_1^2 + x_2^2. The plane x_3 = r^2, with r between the inner radius and the ring, separates them; in the original plane it is the circle of radius r.
Q2. What is the “kernel trick”, in one sentence? Why is it needed?
What does the SVM need from the data?
The SVM needs the data only through dot products, so every dot product \mathbf x_i\cdot\mathbf x_j can be replaced by a kernel function k(\mathbf x_i, \mathbf x_j) that equals a dot product in a lifted space, without ever computing the lifted features. It is needed because those spaces are huge (hundreds of coordinates for quadratic features of 20 inputs) or infinite (RBF).
Q3. Compute k(\mathbf x, \mathbf z) = (\mathbf x\cdot\mathbf z + 1)^2 for \mathbf x = (1, 0), \mathbf z = (2, 3).
One dot product, then add 1 and square.
\mathbf x\cdot\mathbf z = 2, so k = 3^2 = 9.
Q4. An RBF SVM has \gamma = 4. What is its length scale? Two points 1 apart: what is their similarity?
Length scale 1/\sqrt\gamma; similarity e^{-\gamma d^2}.
1/\sqrt4 = 0.5. Similarity e^{-4} = 0.018: almost none.
Q5. An RBF SVM has zero training errors and every training point is a support vector. What is probably wrong, and what do you change?
How far does one point’s bump reach?
\gamma is too large (and C large): each bump reaches only its own point, so the SVM memorises the training set with an island around every point: overfitting. Lower \gamma (and possibly C), and choose both by cross-validation.
Q6. What does an RBF SVM predict far away from all training points?
What happens to every bump e^{-\gamma\|\mathbf x_i - \mathbf x\|^2}?
All bumps vanish, so f(\mathbf x) \to b: the class given by the sign of b, with |f| small (low confidence). The SVM has no information there; it does not extrapolate a trend.
Q7. Why is the RBF kernel function related to the contrast weights of graph cuts?
Compare e^{-\gamma\|\mathbf x - \mathbf z\|^2} with e^{-(I_p - I_q)^2/2\sigma^2}.
They are the same function of a distance: the graph-cut n-link weight is the RBF kernel function of the two grey levels with \gamma = 1/(2\sigma^2). Both measure similarity; the matrix of all pairwise values is the SVM’s kernel matrix and the affinity matrix of normalized cuts.
Q8. (math) Which points have \alpha_i > 0 in the dual solution, and why?
Complementary slackness: \alpha_i\,(y_if(\mathbf x_i) - 1 + \xi_i) = 0.
Only points whose margin constraint is tight: on the edge of the street (y_if = 1, 0 < \alpha_i \le C) or, with a soft margin, inside it or on the wrong side (\alpha_i = C). For every point safely outside the street the constraint is slack, so its multiplier is 0: these are not support vectors and do not appear in f.