---
title: Problem set 10
heading: "Problem set 10: the SVD, the pseudoinverse and PCA"
eyebrow: A7 · Problem set 10
type: problems
---

::: hook
These problems use lessons 44 to 46: singular values and low-rank approximation, the pseudoinverse with minimum-norm and regularized solutions, and principal component analysis. Singular values are never negative, and eigenvalues of a covariance matrix are variances: two quick checks on every answer.
:::

::: pool
pick: 12

::: check
kind: parts
given: a = 1 | 2; b = 3 | 5

## Take $A = \begin{bmatrix}\given{a} & 0\\0 & -\given{b}\end{bmatrix}$.

::: part
answer: b
tolerance: 0.5%

### What is its largest singular value?

::: misses
- [-b] Singular values are never negative: the sign goes into $U$ or $V$.
- [any] The singular values of a diagonal matrix are the absolute values of its entries.
:::
:::

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

### What is its condition number?

::: misses
- [a/b] Largest over smallest.
- [any] $\sigma_1/\sigma_2$.
:::
:::
:::

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

## Take $A = \begin{bmatrix}\given{a} & 0\\\given{b} & \given{c}\end{bmatrix}$.

::: part
answer: a*c
tolerance: 0.5%

### What is $\sigma_1\sigma_2$?

::: misses
- [any] $|\det A|$.
:::
:::

::: part
answer: a^2 + b^2 + c^2
tolerance: 0.5%

### What is $\sigma_1^2 + \sigma_2^2$?

::: misses
- [a + b + c] Square the entries.
- [any] The sum of the squared entries, the trace of $A^TA$.
:::
:::
:::

::: check
kind: parts
given: s1 = 10 | 8; s2 = 3 | 4; s3 = 1 | 2

## A matrix has singular values {s1}, {s2} and {s3}, and is replaced by its rank-1 approximation.

::: part
answer: s1^2/(s1^2 + s2^2 + s3^2)
tolerance: 0.5%

### What fraction of the sum of squared entries does it keep?

::: misses
- [s1/(s1 + s2 + s3)] Energy goes as the singular values squared.
- [any] $\frac{\sigma_1^2}{\sum\sigma_i^2}$.
:::
:::

::: part
answer: s2
tolerance: 0.5%

### What is the largest singular value of the error?

::: misses
- [sqrt(s2^2 + s3^2)] That's the error's Frobenius norm; its largest singular value is $\sigma_2$.
- [any] The error is the sum of the discarded pieces.
:::
:::
:::

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

## Find the shortest solution of $\given{a}x + \given{b}y + \given{c}z = \given{d}$.

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

### What is $x$?

::: misses
- [d/a] That solution sets $y = z = 0$; it isn't the shortest.
- [any] $\mathbf{x}^+ = \frac{d}{a^2 + b^2 + c^2}(a, b, c)$.
:::
:::

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

### How long is it?

::: misses
- [any] The distance from the origin to the plane.
:::
:::
:::

::: check
kind: parts
given: a1 = 1 | 3; a2 = 2 | 4; b1 = 5 | 2; b2 = 3 | 7

## Solve $x\begin{bmatrix}\given{a1}\\\given{a2}\end{bmatrix} \approx \begin{bmatrix}\given{b1}\\\given{b2}\end{bmatrix}$ by least squares.

::: part
answer: (a1*b1 + a2*b2)/(a1^2 + a2^2)
tolerance: 0.5%

### What is $x$?

::: misses
- [any] $A^+ = \frac{\mathbf{a}^T}{\mathbf{a}^T\mathbf{a}}$.
:::
:::

::: part
answer: abs(a1*b2 - a2*b1)/sqrt(a1^2 + a2^2)
tolerance: 0.5%

### How long is the residual?

::: misses
- [any] The part of $\mathbf{b}$ perpendicular to $\mathbf{a}$.
:::
:::
:::

::: check
kind: parts
given: a = 2 | 5; b1 = 3 | 4; b2 = 1 | 6

## Solve $\begin{bmatrix}\given{a} & 0\\0 & 0\end{bmatrix}\mathbf{x} = (\given{b1}, \given{b2})$ with the pseudoinverse.

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

### What is $x_1$?

::: misses
- [any] Invert the nonzero singular value.
:::
:::

::: part
answer: b2
tolerance: 0.5%

### How long is the residual?

::: misses
- [any] No $\mathbf{x}$ can reach the second entry.
:::
:::
:::

::: check
kind: parts
given: s = 0.01 | 0.001; e = 0.001 | 0.01; l = 0.0001 | 0.001

## A matrix's smallest singular value is {s}, and $\mathbf{b}$ carries noise {e} along its $\mathbf{u}$.

::: part
answer: e/s
tolerance: 0.5%

### How much does that noise move the pseudoinverse solution?

::: misses
- [e*s] $A^+$ divides by $\sigma$.
- [any] $e/\sigma$.
:::
:::

::: part
answer: e*s/(s^2 + l)
tolerance: 0.5%

### With Tikhonov regularization at $\lambda$ = {l}, how much?

::: misses
- [any] Tikhonov replaces $1/\sigma$ with $\frac{\sigma}{\sigma^2 + \lambda}$.
:::
:::
:::

::: check
kind: parts
given: s = 0.1 | 1 | 0.01; l = 0.0001 | 0.04

## Tikhonov regularization with $\lambda$ = {l}.

::: part
answer: s^2/(s^2 + l)
tolerance: 0.5%

### What factor scales the contribution of $\sigma$ = {s}?

::: misses
- [any] $\frac{\sigma^2}{\sigma^2 + \lambda}$.
:::
:::

::: part
answer: sqrt(l)
tolerance: 0.5%

### At which $\sigma$ is the factor exactly one half?

::: misses
- [l] $\sigma^2 = \lambda$, so $\sigma = \sqrt\lambda$.
- [any] Solve $\frac{\sigma^2}{\sigma^2 + \lambda} = \frac12$.
:::
:::
:::

::: check
kind: parts
given: I = 3 | 6; R1 = 1 | 2; R2 = 2 | 3; R3 = 4 | 6

## {I} mA divides among {R1}, {R2} and {R3} kΩ in parallel, dissipating the least power.

::: part
answer: I*(1/R1)/(1/R1 + 1/R2 + 1/R3)
unit: mA
tolerance: 0.5%

### How much flows in the {R1} kΩ resistor?

::: misses
- [I/3] An equal split dissipates more unless the resistors are equal.
- [any] Each branch takes its share of the total conductance.
:::
:::

::: part
answer: I^2/(1/R1 + 1/R2 + 1/R3)
unit: mW
tolerance: 0.5%

### What is the total power?

::: misses
- [any] $I^2$ times the parallel resistance.
:::
:::
:::

::: check
kind: parts
given: l1 = 6 | 9; l2 = 3 | 2; l3 = 1 | 0.5

## A covariance matrix has eigenvalues {l1}, {l2} and {l3}.

::: part
answer: l1/(l1 + l2 + l3)
tolerance: 0.5%

### What fraction of the variance does the first component explain?

::: misses
- [any] $\lambda_1$ over the trace.
:::
:::

::: part
answer: (l1 + l2)/(l1 + l2 + l3)
tolerance: 0.5%

### And the first two together?

::: misses
- [any] $\frac{\lambda_1 + \lambda_2}{\sum\lambda_i}$.
:::
:::
:::

::: check
kind: parts
given: v = 2 | 5; c = 1 | 1.5

## Two readings each have variance {v} and covariance {c}.

::: part
answer: v - c
tolerance: 0.5%

### What is the variance along the second principal component?

::: misses
- [v + c] That's the first.
- [any] The eigenvalues of $\begin{bmatrix}v & c\\c & v\end{bmatrix}$ are $v \pm c$.
:::
:::

::: part
answer: (v + c)/(2*v)
tolerance: 0.5%

### What fraction does the first explain?

::: misses
- [any] $\frac{v + c}{2v}$.
:::
:::
:::

::: check
kind: parts
given: s = 1 | 3; n = 0.5 | 1

## Two sensors share a signal of standard deviation {s} and add independent noise of standard deviation {n} each.

::: part
answer: 2*s^2 + n^2
tolerance: 0.5%

### What is the variance along the first principal component?

::: misses
- [s^2 + n^2] One sensor's variance; the shared part adds along $(1, 1)$.
- [any] The larger eigenvalue of $\begin{bmatrix}s^2 + n^2 & s^2\\s^2 & s^2 + n^2\end{bmatrix}$.
:::
:::

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

### What is the noise variance in the average of the two sensors?

::: misses
- [n^2] Averaging two independent noises halves the variance.
- [any] $\text{Var}\frac{x_1 + x_2}{2}$ for the noise parts.
:::
:::
:::

::: check
kind: parts
given: s1 = 20 | 40; s2 = 5 | 10; N = 21 | 51

## The centered data matrix of {N} samples of two readings has singular values {s1} and {s2}.

::: part
answer: s1^2/(N - 1)
tolerance: 0.5%

### What is the variance along the first principal component?

::: misses
- [s1/(N - 1)] Square the singular value.
- [any] $\lambda = \frac{\sigma^2}{N - 1}$.
:::
:::

::: part
answer: (s1^2 + s2^2)/(N - 1)
tolerance: 0.5%

### What is the total variance?

::: misses
- [any] The trace of the covariance matrix.
:::
:::
:::

::: check
kind: parts
given: s1 = 100 | 1000; sn = 0.01 | 0.1

## A square matrix's largest and smallest singular values are {s1} and {sn}.

::: part
answer: s1/sn
tolerance: 0.5%

### What is its condition number?

::: misses
- [sn/s1] Largest over smallest.
- [any] $\sigma_1/\sigma_n$.
:::
:::

::: part
answer: log(s1/sn)
tolerance: 1%

### About how many digits does solving with it lose?

::: misses
- [any] $\log_{10}\kappa$.
:::
:::
:::

::: check
kind: parts
given: x = 3 | 5; y = 1 | 2

## Data in two readings has its first principal component along $\frac{1}{\sqrt2}(1, 1)$. A centered sample is $(\given{x}, \given{y})$.

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

### What is its score on the first component?

::: misses
- [x + y] Use the unit vector.
- [any] $\mathbf{q}_1\cdot\mathbf{x}$.
:::
:::

::: part
answer: (x - y)/sqrt(2)
tolerance: 0.5%

### How far is the sample from its reconstruction with that component alone?

::: misses
- [any] The leftover is the score on the second component, $\frac{1}{\sqrt2}(1, -1)$.
:::
:::
:::
:::
