---
title: "Problem set 6: kernels, SVMs, Gaussian processes and mixtures"
heading: "Problem set 6: kernel values and feature counts, kernel ridge regression, margins, hinge losses and SVM outputs, Gaussian process posteriors, and EM for Gaussian mixtures"
eyebrow: S14 · Problem set 6
type: problems
---

::: hook
These problems cover lessons 32 to 36: Gaussian and polynomial kernels, feature-space distances, kernel ridge regression on two points, SVM margins, biases, hinge losses and kernel outputs, Gaussian process covariances, posteriors and marginal likelihoods, and the E and M steps of a mixture model.
:::

::: pool
pick: 12

::: check
kind: parts
given: d = 0.5 | 2; s = 0.7 | 1.5; D = 8 | 30; M = 2 | 3

## Inputs {d} apart under a Gaussian kernel of width {s}; a polynomial kernel of degree {M} on {D} inputs.

::: part
answer: exp(-d^2/(2*s^2))
tolerance: 0.5%

### Gaussian kernel value?

::: misses
- [any] $e^{-d^2/2s^2}$.
:::
:::

::: part
answer: 2 - 2*exp(-d^2/(2*s^2))
tolerance: 0.5%

### Squared feature-space distance?

::: misses
- [any] $k(x, x) + k(z, z) - 2k(x, z)$.
:::
:::

::: part
answer: (D + M)!/(D!*M!)
tolerance: 0.5%

### Polynomial feature count?

::: misses
- [any] $\binom{D + M}{M}$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 2; b = 0.5 | 1.5; c = 1 | 2.5; d = 0.5 | 1; M = 2 | 3; N = 2e4 | 6e4

## x = ({a}, {b}) and z = ({c}, {d}); a Gram matrix for {N} examples.

::: part
answer: (a*c + b*d + 1)^M
tolerance: 0.5%

### $(\mathbf{x}^T\mathbf{z} + 1)^{\given{M}}$?

::: misses
- [any] Inner product, plus 1, to the power.
:::
:::

::: part
answer: 8*N^2/1e9
tolerance: 0.5%

### Gram matrix size in gigabytes (doubles)?

::: misses
- [any] $8N^2$ bytes.
:::
:::
:::

::: check
kind: parts
given: t = 1 | 2.5; u = -1 | 0.5; k = 0.4 | 0.8; l = 0.1 | 0.4

## Kernel ridge regression on two points: targets {t} and {u}, off-diagonal kernel {k}, unit diagonal, λ = {l}.

::: part
answer: ((1 + l)*t - k*u)/((1 + l)^2 - k^2)
tolerance: 0.5%

### Coefficient $a_1$?

::: misses
- [any] Solve $(K + \lambda I)\mathbf{a} = \mathbf{t}$.
:::
:::

::: part
answer: ((1 + l)*u - k*t)/((1 + l)^2 - k^2)
tolerance: 0.5%

### Coefficient $a_2$?

::: misses
- [any] The second row of the inverse.
:::
:::

::: part
answer: k*((1 + l)*t - k*u)/((1 + l)^2 - k^2) + ((1 + l)*u - k*t)/((1 + l)^2 - k^2)
tolerance: 0.5%

### Prediction at the second training point?

::: misses
- [any] $ka_1 + a_2$.
:::
:::
:::

::: check
kind: parts
given: a = 0.5 | 2; b = 1.3 | 2.6; x = 1 | 2; y = -1 | 0.3; t = 1 | -1

## A linear SVM with w = ({a}, {b}); ({x}, {y}) is a support vector labeled {t}.

::: part
answer: 1/sqrt(a^2 + b^2)
tolerance: 0.5%

### Margin?

::: misses
- [any] $1/\|\mathbf{w}\|$.
:::
:::

::: part
answer: t - (a*x + b*y)
tolerance: 0.5%

### Bias?

::: misses
- [any] $t_s - \mathbf{w}^T\mathbf{x}_s$.
:::
:::
:::

::: check
kind: parts
given: t = 1 | -1; y = -0.6 | 0.2 | 0.5; w = 6 | 30; C = 0.5 | 5; s = 1.5 | 4

## A point with target {t} and output {y}; a soft-margin SVM with $\|\mathbf{w}\|^2$ = {w}, C = {C}, total slack {s}.

::: part
answer: (1 - t*y + abs(1 - t*y))/2
tolerance: 0.5%

### Hinge loss?

::: misses
- [any] max(0, 1 − ty).
:::
:::

::: part
answer: ln(1 + exp(-t*y))/ln(2)
tolerance: 0.5%

### Logistic loss in bits?

::: misses
- [any] $\log_2(1 + e^{-ty})$.
:::
:::

::: part
answer: w/2 + C*s
tolerance: 0.5%

### Soft-margin objective?

::: misses
- [any] $\frac{1}{2}\|\mathbf{w}\|^2 + C\sum\xi$.
:::
:::
:::

::: check
kind: parts
given: a = 0.4 | 1.5; c = 0.3 | 0.9; d = 0.5 | 1.8; k = 0.2 | 0.7; b = -0.2 | 0.6; p = 1 | 2.5; q = 0.5 | 2

## A kernel SVM with support vectors (+1, multiplier {a}, kernel {c}) and (−1, multiplier {d}, kernel {k}), bias {b}; a two-point training set ({p}, {q}) labeled +1 and (−{p}, −{q}) labeled −1.

::: part
answer: a*c - d*k + b
tolerance: 0.5%

### Kernel SVM output?

::: misses
- [any] $\sum a_nt_nk_n + b$.
:::
:::

::: part
answer: sqrt(p^2 + q^2)
tolerance: 0.5%

### Margin of the two-point SVM?

::: misses
- [any] Half the distance between the points.
:::
:::
:::

::: check
kind: parts
given: s = 0.5 | 2; l = 0.5 | 2; d = 0.4 | 1.5; r = 0.2 | 0.6

## A squared-exponential process with $\sigma_f$ = {s} and ℓ = {l}.

::: part
answer: s^2*exp(-d^2/(2*l^2))
tolerance: 0.5%

### Covariance at separation {d}?

::: misses
- [any] $\sigma_f^2e^{-d^2/2\ell^2}$.
:::
:::

::: part
answer: l*sqrt(-2*ln(r))
tolerance: 0.5%

### Separation where the correlation falls to {r}?

::: misses
- [any] $\ell\sqrt{-2\ln r}$.
:::
:::
:::

::: check
kind: parts
given: t = 0.8 | 2; d = 0.3 | 1.2; l = 0.8 | 2; n = 0.05 | 0.3

## A process with $\sigma_f$ = 1, ℓ = {l} and noise variance {n} observes {t} at one point.

::: part
answer: exp(-d^2/(2*l^2))*t/(1 + n)
tolerance: 0.5%

### Posterior mean {d} away?

::: misses
- [any] $kt/(1 + \sigma_n^2)$.
:::
:::

::: part
answer: 1 - exp(-d^2/l^2)/(1 + n)
tolerance: 0.5%

### Posterior variance there?

::: misses
- [any] $1 - k^2/(1 + \sigma_n^2)$.
:::
:::

::: part
answer: n/(1 + n)
tolerance: 0.5%

### Posterior variance at the observed point?

::: misses
- [any] $\sigma_f^2\sigma_n^2/(\sigma_f^2 + \sigma_n^2)$.
:::
:::
:::

::: check
kind: parts
given: t = 0.4 | 1.8; C = 0.6 | 2.5; D = 0.9 | 5

## One observation {t}; two candidate models give it total variance {C} and {D}.

::: part
answer: -t^2/(2*C) - ln(C)/2 - ln(2*pi)/2
tolerance: 0.5%

### Log marginal likelihood under the first?

::: misses
- [any] Log of a Gaussian density.
:::
:::

::: part
answer: (-t^2/(2*C) - ln(C)/2) - (-t^2/(2*D) - ln(D)/2)
tolerance: 0.5%

### How much higher is it than under the second?

::: misses
- [any] The constants cancel.
:::
:::
:::

::: check
kind: parts
given: a = -1 | 0; b = 1.5 | 3; P = 0.25 | 0.7; x = 0.5 | 1

## A mixture of unit-variance components at {a} and {b} with weights {P} and 1 − {P}; a point at {x}.

::: part
answer: P*exp(-(x - a)^2/2)/(P*exp(-(x - a)^2/2) + (1 - P)*exp(-(x - b)^2/2))
tolerance: 0.5%

### Responsibility of the first component?

::: misses
- [any] Bayes' theorem over components.
:::
:::

::: part
answer: ln(P*exp(-(x - a)^2/2)/sqrt(2*pi) + (1 - P)*exp(-(x - b)^2/2)/sqrt(2*pi))
tolerance: 0.5%

### Log-likelihood of the point?

::: misses
- [any] Log of the weighted sum of densities.
:::
:::
:::

::: check
kind: parts
given: g = 0.3 | 0.9; h = 0.2 | 0.7; k = 0.1 | 0.5; x = 0 | 1; y = 2 | 3; z = 6 | 8; N = 5 | 12

## A component's responsibilities are {g}, {h} and {k} for the points {x}, {y} and {z}, and zero for the other points of {N}.

::: part
answer: (g*x + h*y + k*z)/(g + h + k)
tolerance: 0.5%

### New mean?

::: misses
- [any] $\sum\gamma x/N_k$.
:::
:::

::: part
answer: (g*(x - (g*x + h*y + k*z)/(g + h + k))^2 + h*(y - (g*x + h*y + k*z)/(g + h + k))^2 + k*(z - (g*x + h*y + k*z)/(g + h + k))^2)/(g + h + k)
tolerance: 0.5%

### New variance?

::: misses
- [any] $\sum\gamma(x - \mu)^2/N_k$.
:::
:::

::: part
answer: (g + h + k)/N
tolerance: 0.5%

### New mixing weight?

::: misses
- [any] $N_k/N$.
:::
:::
:::

::: check
kind: parts
given: K = 3 | 8; D = 3 | 12

## Gaussian mixtures with {K} components in {D} dimensions.

::: part
answer: K*(D + D*(D + 1)/2) + K - 1
tolerance: 0.5%

### Parameters with full covariances?

::: misses
- [any] $K(D + D(D + 1)/2) + K - 1$.
:::
:::

::: part
answer: K*(2*D) + K - 1
tolerance: 0.5%

### Parameters with diagonal covariances?

::: misses
- [any] D means and D variances per component, plus weights.
:::
:::
:::

::: check
kind: parts
given: d = 0.2 | 1 | 3; s = 0.5 | 2

## Two training inputs are {d} apart under a Gaussian kernel of width {s}.

::: part
answer: 1 - exp(-d^2/(2*s^2))
tolerance: 0.5%

### What is the Gram matrix's smaller eigenvalue?

::: misses
- [any] $1 - k$.
:::
:::

::: part
answer: (1 + exp(-d^2/(2*s^2)))/(1 - exp(-d^2/(2*s^2)))
tolerance: 0.5%

### What is its condition number?

::: misses
- [any] $(1 + k)/(1 - k)$.
:::
:::
:::

::: check
kind: parts
given: D = 2 | 4; l = 1 | 2; n = 0.01 | 0.2; t = 1 | -2

## A Gaussian process ($\sigma_f$ = 1, ℓ = {l}, noise variance {n}) observes {t} at both x = 0 and x = {D}.

::: part
answer: 2*exp(-D^2/(8*l^2))*t/(1 + n + exp(-D^2/(2*l^2)))
tolerance: 0.5%

### What does it predict halfway between?

::: misses
- [any] $2k_*t/(1 + \sigma^2 + k_{12})$.
:::
:::

::: part
answer: 1 - 2*exp(-D^2/(4*l^2))/(1 + n + exp(-D^2/(2*l^2)))
tolerance: 0.5%

### What predictive variance does the function have there?

::: misses
- [any] $1 - 2k_*^2/(1 + \sigma^2 + k_{12})$.
:::
:::
:::

::: check
kind: parts
given: K = 2 | 4 | 8; D = 3 | 10; N = 1000 | 100000

## Gaussian mixtures with diagonal covariances, {K} components in {D} dimensions, are compared by BIC on {N} points.

::: part
answer: K*(2*D + 1) - 1
unit: parameters
tolerance: 0

### How many free parameters does the mixture have?

::: misses
- [K*(2*D + 1)] The weights sum to 1.
- [any] Means, variances and weights.
:::
:::

::: part
answer: (2*D + 1)/2*ln(N)
tolerance: 0.5%

### How much more log-likelihood must one more component buy to be worth adding under BIC?

::: misses
- [(2*D + 1)*ln(N)] BIC charges half of ln N per parameter.
- [any] $\frac{2D + 1}2\ln N$.
:::
:::
:::
:::
