---
title: "Problem set 2: conjugate priors, Gaussians and regression"
heading: "Problem set 2: beta and Dirichlet updating, Gaussian conditioning and inference for the mean, ridge regression and the bias–variance trade, and Bayesian linear regression"
eyebrow: S14 · Problem set 2
type: problems
---

::: hook
These problems cover lessons 7 to 10: posterior means, modes and variances of beta distributions, Dirichlet smoothing, gamma priors on failure rates, precision-weighted Gaussian posteriors and sensors with gain, conditional distributions and Mahalanobis distances, ridge bias, variance and effective parameters, and predictive distributions with their error bars.
:::

::: pool
pick: 12

::: check
kind: parts
given: a = 1 | 3; b = 1 | 4; m = 3 | 8; N = 10 | 25

## A beta({a}, {b}) prior updated with {m} successes in {N} trials.

::: part
answer: (a + m)/(a + b + N)
tolerance: 0.5%

### Posterior mean?

::: misses
- [any] $(a + m)/(a + b + N)$.
:::
:::

::: part
answer: (a + m - 1)/(a + b + N - 2)
tolerance: 0.5%

### MAP?

::: misses
- [any] Mode.
:::
:::

::: part
answer: (a + m)*(b + N - m)/((a + b + N)^2*(a + b + N + 1))
tolerance: 0.5%

### Posterior variance?

::: misses
- [any] $AB/((A + B)^2(A + B + 1))$.
:::
:::
:::

::: check
kind: parts
given: x = 0 | 4; y = 2 | 7; z = 1 | 10; c = 0.5 | 1; m = 0 | 5; N = 12 | 40

## A three-outcome source with counts {x}, {y}, {z} and a Dirichlet prior of {c} each; separately, {m} successes in {N}.

::: part
answer: (x + c)/(x + y + z + 3*c)
tolerance: 0.5%

### Predictive probability of outcome 1?

::: misses
- [any] Add α to the counts.
:::
:::

::: part
answer: (m + 1)/(N + 2)
tolerance: 0.5%

### Laplace's estimate for the second source?

::: misses
- [any] $(m + 1)/(N + 2)$.
:::
:::
:::

::: check
kind: parts
given: u = 0 | 2; s = 1 | 3; v = 0.5 | 2; N = 3 | 15; x = 1 | 5

## Prior on a mean N({u}, {s}²); {N} observations averaging {x} with noise variance {v}.

::: part
answer: 1/(1/s^2 + N/v)
tolerance: 0.5%

### Posterior variance?

::: misses
- [any] Precisions add.
:::
:::

::: part
answer: (u/s^2 + N*x/v)/(1/s^2 + N/v)
tolerance: 0.5%

### Posterior mean?

::: misses
- [any] Precision-weighted average.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 2; b = 1.5 | 4; r = 0.4 | 0.7 | 0.9; x = -1 | 2

## Zero-mean jointly Gaussian x, y: $\sigma_x$ = {a}, $\sigma_y$ = {b}, ρ = {r}; observed x = {x}.

::: part
answer: r*b/a*x
tolerance: 0.5%

### E[y|x]?

::: misses
- [any] $\rho(\sigma_y/\sigma_x)x$.
:::
:::

::: part
answer: b*sqrt(1 - r^2)
tolerance: 0.5%

### Conditional standard deviation?

::: misses
- [any] $\sigma_y\sqrt{1 - \rho^2}$.
:::
:::
:::

::: check
kind: parts
given: x = 1 | 2.5; y = 1 | 3; a = 0.5 | 2; b = 1 | 4; m = 3 | 8; n = 4 | 20; z = 2 | 12

## A point ({x}, {y}) against a zero-mean Gaussian with standard deviations {a} and {b}; a running mean of {m} over {n} − 1 samples when sample {n} = {z} arrives.

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

### Mahalanobis distance?

::: misses
- [any] $\sqrt{\sum x_i^2/\sigma_i^2}$.
:::
:::

::: part
answer: m + (z - m)/n
tolerance: 0.5%

### Updated mean?

::: misses
- [any] $\mu + (x_N - \mu)/N$.
:::
:::
:::

::: check
kind: parts
given: S = 5 | 20; w = 0.5 | 2; v = 1 | 6; l = 0.5 | 5

## Ridge on one weight: Σx² = {S}, true w = {w}, noise variance {v}, λ = {l}.

::: part
answer: (l*w/(S + l))^2
tolerance: 0.5%

### Squared bias?

::: misses
- [any] $(\lambda w/(S + \lambda))^2$.
:::
:::

::: part
answer: v*S/(S + l)^2
tolerance: 0.5%

### Variance?

::: misses
- [any] $\sigma^2S/(S + \lambda)^2$.
:::
:::

::: part
answer: v/w^2
tolerance: 0.5%

### Best λ?

::: misses
- [any] $\sigma^2/w^2$.
:::
:::
:::

::: check
kind: parts
given: a = 3 | 30; b = 0.5 | 3; c = 0.02 | 0.3; l = 0.2 | 2; M = 2 | 4; D = 3 | 6

## $\Phi^T\Phi$ eigenvalues {a}, {b}, {c} with λ = {l}; a polynomial basis of degree {M} in {D} inputs.

::: part
answer: a/(a + l) + b/(b + l) + c/(c + l)
tolerance: 0.5%

### Effective parameters?

::: misses
- [any] $\sum d/(d + \lambda)$.
:::
:::

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

### Basis size?

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

::: check
kind: parts
given: a = 0.5 | 2; b = 2 | 10; S = 4 | 20; T = 3 | 15; x = 1 | 5

## Bayesian regression of one weight: α = {a}, β = {b}, Σx² = {S}, Σxt = {T}.

::: part
answer: b*T/(a + b*S)
tolerance: 0.5%

### Posterior mean?

::: misses
- [any] $\beta T/(\alpha + \beta S)$.
:::
:::

::: part
answer: 1/sqrt(a + b*S)
tolerance: 0.5%

### Posterior standard deviation?

::: misses
- [any] $1/\sqrt{\alpha + \beta S}$.
:::
:::

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

### Predictive standard deviation at x = {x}?

::: misses
- [any] $\sqrt{1/\beta + x^2/(\alpha + \beta S)}$.
:::
:::
:::

::: check
kind: parts
given: a = 0.2 | 2; b = 1 | 9; s = 0.05 | 0.15

## A prior precision {a}, noise precision {b}, and a target posterior standard deviation {s} for one weight.

::: part
answer: a/b
tolerance: 0.5%

### Equivalent ridge λ?

::: misses
- [any] $\alpha/\beta$.
:::
:::

::: part
answer: (1/s^2 - a)/b
tolerance: 0.5%

### Σx² needed?

::: misses
- [any] $(1/s^2 - \alpha)/\beta$.
:::
:::
:::

::: check
kind: parts
given: a = 2 | 6; b = 2 | 6; v = 1 | 5; S = 10 | 40

## A beta({a}, {b}) prior; separately, the best-λ ridge error for Σx² = {S}, noise variance {v}, w = 1.

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

### Prior variance?

::: misses
- [any] Beta variance.
:::
:::

::: part
answer: v/(S + v)
tolerance: 0.5%

### Best ridge mean squared error?

::: misses
- [any] $\sigma^2/(S + \lambda^*)$ with $\lambda^* = \sigma^2$.
:::
:::
:::

::: check
kind: parts
given: s = 0.5 | 4; v = 1 | 4; N = 1 | 10 | 100

## A prior standard deviation {s} on a mean, noise variance {v}, {N} observations.

::: part
answer: 1/(1/s^2 + N/v)
tolerance: 0.5%

### Posterior variance?

::: misses
- [any] $1/(1/\sigma_0^2 + N/\sigma^2)$.
:::
:::

::: part
answer: (N/v)/(1/s^2 + N/v)
tolerance: 0.5%

### Weight given to the data in the posterior mean?

::: misses
- [any] Data precision over total precision.
:::
:::
:::

::: check
kind: parts
given: m = 1 | 2; N = 3 | 8; a = 1 | 2

## {m} successes in {N} trials with a beta({a}, {a}) prior.

::: part
answer: m/N
tolerance: 0.5%

### Maximum likelihood?

::: misses
- [any] m/N.
:::
:::

::: part
answer: (a + m)/(2*a + N)
tolerance: 0.5%

### Posterior mean?

::: misses
- [any] $(a + m)/(2a + N)$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 3; b = 2000 | 8000; k = 1 | 5; T = 5000 | 20000

## A failure rate has a gamma({a}, {b} h) prior, and {k} failures occur in {T} hours.

::: part
answer: (a + k)/(b + T)*1e4
tolerance: 0.5%

### What is the posterior mean, per 10,000 hours?

::: misses
- [k/T*1e4] Include the prior's pseudo-counts.
- [any] $(\alpha + k)/(\beta + T)$.
:::
:::

::: part
answer: sqrt(a + k)/(a + k)
tolerance: 0.5%

### What is the posterior's standard deviation as a fraction of its mean?

::: misses
- [any] $1/\sqrt{\alpha'}$ for a gamma distribution.
:::
:::
:::

::: check
kind: parts
given: s = 0.5 | 2; g = 0.25 | 4; v = 0.2 | 1; y = -1 | 3

## A quantity has prior N(0, {s}²). A sensor with gain {g} and noise variance {v} reads y = {y}.

::: part
answer: 1/sqrt(1/s^2 + g^2/v)
tolerance: 0.5%

### What is the posterior standard deviation?

::: misses
- [1/(1/s^2 + g^2/v)] That's the variance.
- [any] $1/\sqrt{1/\sigma_0^2 + g^2/\sigma^2}$.
:::
:::

::: part
answer: (g*y/v)/(1/s^2 + g^2/v)
tolerance: 0.5%

### What is the posterior mean?

::: misses
- [any] $gy/\sigma^2$ times the posterior variance.
:::
:::
:::

::: check
kind: parts
given: a = 6 | 9; b = 3 | 5; c = 2 | -2; u = 4 | 10; v = 1 | 6; l = 0 | 3

## A two-weight fit has $\Phi^T\Phi = \begin{bmatrix}a & c \\ c & b\end{bmatrix}$ with a = {a}, b = {b}, c = {c}, and $\Phi^T\mathbf t$ = ({u}, {v}); ridge uses λ = {l}.

::: part
answer: ((b + l)*u - c*v)/((a + l)*(b + l) - c^2)
tolerance: 0.5%

### What is $w_1$?

::: misses
- [any] Invert $\Phi^T\Phi + \lambda I$.
:::
:::

::: part
answer: ((a + l)*v - c*u)/((a + l)*(b + l) - c^2)
tolerance: 0.5%

### What is $w_2$?

::: misses
- [any] Invert $\Phi^T\Phi + \lambda I$.
:::
:::
:::
:::
