---
title: "Problem set 1: fitting, likelihood, decisions and information"
heading: "Problem set 1: least squares and generalization, maximum likelihood and Bayes' theorem, decision rules and Bayes error, and entropy, cross-entropy and divergence"
eyebrow: S14 · Problem set 1
type: problems
---

::: hook
These problems cover lessons 1 to 4: least-squares lines and RMS error, the expected gap between training and test error, regularized weights, maximum-likelihood estimates and their bias, censored life tests, posteriors and MAP, decision thresholds, reject options and Bayes errors, and the information measures behind classification losses, mutual information included.
:::

::: pool
pick: 12

::: check
kind: parts
given: a = 1 | 2; b = 3 | 4; c = 6 | 9; d = 7 | 11

## Points (0, {a}), (1, {b}), (2, {c}), (3, {d}).

::: part
answer: (4*(b + 2*c + 3*d) - 6*(a + b + c + d))/(4*14 - 36)
tolerance: 0.5%

### Least-squares slope?

::: misses
- [any] $(N\sum xt - \sum x\sum t)/(N\sum x^2 - (\sum x)^2)$.
:::
:::

::: part
answer: (a + b + c + d)/4 - (4*(b + 2*c + 3*d) - 6*(a + b + c + d))/(4*14 - 36)*1.5
tolerance: 0.5%

### Intercept?

::: misses
- [any] $\bar{t} - w_1\bar{x}$.
:::
:::
:::

::: check
kind: parts
given: s = 0.02 | 0.1; p = 4 | 12; N = 30 | 120

## A correct linear model with {p} parameters, {N} examples, noise variance {s}.

::: part
answer: s*(1 - p/N)
tolerance: 0.5%

### Expected training error?

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

::: part
answer: s*(1 + p/N)
tolerance: 0.5%

### Expected test error?

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

::: part
answer: sqrt(s*(1 + p/N))
tolerance: 0.5%

### Expected test RMS error?

::: misses
- [any] Square root.
:::
:::
:::

::: check
kind: parts
given: S = 4 | 25; T = 3 | 20; l = 1 | 10; E = 1 | 6; N = 20 | 80

## A single weight with Σx² = {S}, Σxt = {T}; separately, a fit with E = {E} on {N} examples.

::: part
answer: T/S
tolerance: 0.5%

### Least-squares weight?

::: misses
- [any] $\sum xt/\sum x^2$.
:::
:::

::: part
answer: T/(S + l)
tolerance: 0.5%

### With λ = {l}?

::: misses
- [any] $\sum xt/(\sum x^2 + \lambda)$.
:::
:::

::: part
answer: sqrt(2*E/N)
tolerance: 0.5%

### RMS error of the other fit?

::: misses
- [any] $\sqrt{2E/N}$.
:::
:::
:::

::: check
kind: parts
given: a = 1 | 4; b = 3 | 8; c = 2 | 9

## Three samples: {a}, {b}, {c}.

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

### ML mean?

::: misses
- [any] Average.
:::
:::

::: part
answer: ((a - (a + b + c)/3)^2 + (b - (a + b + c)/3)^2 + (c - (a + b + c)/3)^2)/3
tolerance: 0.5%

### ML variance?

::: misses
- [any] Divide by N.
:::
:::

::: part
answer: ((a - (a + b + c)/3)^2 + (b - (a + b + c)/3)^2 + (c - (a + b + c)/3)^2)/2
tolerance: 0.5%

### Unbiased variance?

::: misses
- [any] Divide by N − 1.
:::
:::
:::

::: check
kind: parts
given: p = 0.002 | 0.02; s = 0.95 | 0.999; f = 0.005 | 0.05; n = 0.05 | 1; w = 0.5 | 3

## A detector: prevalence {p}, detection {s}, false alarms {f}; separately, regression noise variance {n} with a weight prior of standard deviation {w}.

::: part
answer: s*p/(s*p + f*(1 - p))
tolerance: 0.5%

### Posterior after a positive?

::: misses
- [any] Bayes.
:::
:::

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

### Equivalent ridge λ?

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

::: check
kind: parts
given: N = 5 | 20; v = 1 | 3; S = 6 | 40

## {N} Gaussian samples with squared deviations from μ totaling {S}; σ² = {v}.

::: part
answer: -N/2*ln(2*pi*v) - S/(2*v)
tolerance: 0.5%

### Log-likelihood?

::: misses
- [any] $-\frac{N}{2}\ln 2\pi\sigma^2 - S/2\sigma^2$.
:::
:::

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

### σ² that would maximize it (given μ)?

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

::: check
kind: parts
given: d = 1 | 2.5; P = 0.5 | 0.75 | 0.9

## Unit-variance Gaussian classes at 0 and {d}, with class 1's prior {P}.

::: part
answer: d/2 + ln(P/(1 - P))/d
tolerance: 0.5%

### Boundary?

::: misses
- [any] Midpoint + $\ln(P_1/P_2)/d$.
:::
:::

::: part
answer: P*Q(d/2 + ln(P/(1 - P))/d) + (1 - P)*Q(d/2 - ln(P/(1 - P))/d)
tolerance: 1%

### Bayes error?

::: misses
- [any] Both tails.
:::
:::
:::

::: check
kind: parts
given: c = 1 | 10; m = 20 | 500; p = 0.02 | 0.1 | 0.4

## Costs: false alarm {c}, miss {m}; the posterior of the positive class is {p}.

::: part
answer: c/(c + m)
tolerance: 0.5%

### Threshold?

::: misses
- [any] $c_F/(c_F + c_M)$.
:::
:::

::: part
answer: (c*(1 - p) + m*p - abs(c*(1 - p) - m*p))/2
tolerance: 0.5%

### Expected cost of the best decision?

::: misses
- [any] The smaller of $c_F(1 - p)$ and $c_Mp$.
:::
:::
:::

::: check
kind: parts
given: p = 0.7 | 0.95; q = 0.6 | 0.85

## A binary event with true probability {p}, predicted as {q}.

::: part
answer: -(p*log(p) + (1 - p)*log(1 - p))/log(2)
unit: bits
tolerance: 0.5%

### Entropy?

::: misses
- [any] $H(p)$.
:::
:::

::: part
answer: -(p*log(q) + (1 - p)*log(1 - q))/log(2)
unit: bits
tolerance: 0.5%

### Cross-entropy?

::: misses
- [any] $H(p, q)$.
:::
:::

::: part
answer: (p*log(p/q) + (1 - p)*log((1 - p)/(1 - q)))/log(2)
unit: bits
tolerance: 0.5%

### KL divergence?

::: misses
- [any] Their difference.
:::
:::
:::

::: check
kind: parts
given: a = 0.8 | 0.4; b = 0.95 | 0.2; K = 4 | 100

## A classifier gives correct-class probabilities {a} and {b} on two examples; a uniform {K}-way guess.

::: part
answer: -(ln(a) + ln(b))/2
unit: nats
tolerance: 0.5%

### Average loss?

::: misses
- [any] Mean of $-\ln q$.
:::
:::

::: part
answer: ln(K)
unit: nats
tolerance: 0.5%

### Loss of the uniform guess?

::: misses
- [any] $\ln K$.
:::
:::
:::

::: check
kind: parts
given: e = 0.02 | 0.15; d = 2 | 3

## A binary symmetric channel with error rate {e}; equal-prior unit-variance classes {d} apart.

::: part
answer: 1 + (e*log(e) + (1 - e)*log(1 - e))/log(2)
unit: bits
tolerance: 0.5%

### Mutual information (uniform input)?

::: misses
- [any] $1 - H(\epsilon)$.
:::
:::

::: part
answer: Q(d/2)
tolerance: 1%

### Bayes error?

::: misses
- [any] $Q(d/2)$.
:::
:::
:::

::: check
kind: parts
given: s = 0.05 | 0.2; p = 5 | 25; g = 0.002 | 0.01; v = 2 | 9; N = 4 | 25

## Noise variance {s}, {p} parameters, a target gap of {g}; separately, an ML variance of {v} from {N} samples.

::: part
answer: 2*s*p/g
tolerance: 0.5%

### Examples needed?

::: misses
- [any] $2\sigma^2p/\text{gap}$.
:::
:::

::: part
answer: v*N/(N - 1)
tolerance: 0.5%

### Unbiased variance?

::: misses
- [any] $\times N/(N - 1)$.
:::
:::
:::

::: check
kind: parts
given: n = 6 | 10; F = 2 | 4; t = 300 | 600; T = 1000 | 2000

## {n} units start a {T}-hour life test. {F} fail, at an average of {t} hours; the rest survive to the end.

::: part
answer: F/(F*t + (n - F)*T)
tolerance: 0.5%

### What is the maximum-likelihood failure rate per hour?

::: misses
- [1/t] That ignores the survivors' time on test.
- [any] Failures over total time on test.
:::
:::

::: part
answer: (F*t + (n - F)*T)/F
unit: h
tolerance: 0.5%

### What mean time to failure does it imply?

::: misses
- [any] The reciprocal of the rate.
:::
:::
:::

::: check
kind: parts
given: p = 0.3 | 0.5; a = 0.7 | 0.9; b = 0.1 | 0.3

## A class has prior {p}. A binary feature is on with probability {a} in that class and {b} otherwise.

::: part
answer: -(p*a + (1 - p)*b)*log(p*a + (1 - p)*b)/log(2) - (1 - p*a - (1 - p)*b)*log(1 - p*a - (1 - p)*b)/log(2)
unit: bits
tolerance: 0.5%

### What is the feature's entropy?

::: misses
- [any] Binary entropy of $P(F = 1) = pa + (1 - p)b$.
:::
:::

::: part
answer: -(p*a + (1 - p)*b)*log(p*a + (1 - p)*b)/log(2) - (1 - p*a - (1 - p)*b)*log(1 - p*a - (1 - p)*b)/log(2) - p*(-a*log(a)/log(2) - (1 - a)*log(1 - a)/log(2)) - (1 - p)*(-b*log(b)/log(2) - (1 - b)*log(1 - b)/log(2))
unit: bits
tolerance: 0.5%

### What is the mutual information between feature and class?

::: misses
- [any] $H(F) - pH(a) - (1 - p)H(b)$.
:::
:::
:::

::: check
kind: parts
given: d = 1.5 | 2 | 3; h = 0.75 | 0.9 | 0.99

## Two equally likely unit-variance classes have means {d} apart; a classifier abstains unless its larger posterior is at least {h}.

::: part
answer: 2*ln(h/(1 - h))/d
tolerance: 0.5%

### How wide is the band of inputs it rejects?

::: misses
- [ln(h/(1 - h))/d] That's half the band.
- [any] Twice $\ln[\theta/(1 - \theta)]/d$.
:::
:::

::: part
answer: 0.5*erfc((d/2 + ln(h/(1 - h))/d)/sqrt(2))
tolerance: 0.5%

### What fraction of all inputs does it then get wrong?

::: misses
- [0.5*erfc(d/2/sqrt(2))] That's the error without rejection.
- [any] The tail beyond the far edge of the band: $1 - \Phi(d/2 + h)$.
:::
:::
:::
:::
