Skip to content

Commit 101e584

Browse files
sidd3888HumphreyYangmmcky
authored
PCA section in SVD lecture (#397)
* pca fix * revert (n -1) * fix build error for bayes_nonconj * fix the same issue for MCMC plots * revert bayes_nonconj to main --------- Co-authored-by: Humphrey Yang <[email protected]> Co-authored-by: Matt McKay <[email protected]>
1 parent 681779b commit 101e584

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lectures/svd_intro.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ $$
544544
X = \begin{bmatrix} X_1 \mid X_2 \mid \cdots \mid X_n\end{bmatrix}
545545
$$
546546
547-
where for $j = 1, \ldots, n$ the column vector $X_j = \begin{bmatrix}X_{1j}\\X_{2j}\\\vdots\\X_{mj}\end{bmatrix}$ is a vector of observations on variables $\begin{bmatrix}x_1\\x_2\\\vdots\\x_m\end{bmatrix}$.
547+
where for $j = 1, \ldots, n$ the column vector $X_j = \begin{bmatrix}x_{1j}\\x_{2j}\\\vdots\\x_{mj}\end{bmatrix}$ is a vector of observations on variables $\begin{bmatrix}X_1\\X_2\\\vdots\\X_m\end{bmatrix}$.
548548
549549
In a **time series** setting, we would think of columns $j$ as indexing different __times__ at which random variables are observed, while rows index different random variables.
550550
@@ -561,14 +561,14 @@ Because our data matrix may hold variables of different units and scales, we fir
561561
First by computing the average of each row of $X$.
562562
563563
$$
564-
\bar{X_j}= \frac{1}{m} \sum_{i = 1}^{m} x_{i,j}
564+
\bar{X_i}= \frac{1}{n} \sum_{j = 1}^{n} x_{ij}
565565
$$
566566
567567
We then create an average matrix out of these means:
568568
569569
570570
$$
571-
\bar{X} = \begin{bmatrix}1 \\1 \\\ldots\\1 \end{bmatrix} \begin{bmatrix} \bar{X_1} \mid \bar{X_2} \mid \cdots \mid \bar{X_n}\end{bmatrix}
571+
\bar{X} = \begin{bmatrix} \bar{X_1} \\ \bar{X_2} \\ \ldots \\ \bar{X_m}\end{bmatrix}\begin{bmatrix}1 \mid 1 \mid \cdots \mid 1 \end{bmatrix}
572572
$$
573573
574574
And subtract out of the original matrix to create a mean centered matrix:
@@ -583,27 +583,28 @@ $$
583583
Then because we want to extract the relationships between variables rather than just their magnitude, in other words, we want to know how they can explain each other, we compute the covariance matrix of $B$.
584584
585585
$$
586-
C = \frac{1}{{n}} B^\top B
586+
C = \frac{1}{n} BB^{\top}
587587
$$
588588
589589
**Step 3: Decompose the covariance matrix and arrange the singular values:**
590590
591-
If the matrix $C$ is diagonalizable, we can eigendecompose it, find its eigenvalues and rearrange the eigenvalue and eigenvector matrices in a decreasing other.
591+
Since the matrix $C$ is positive definite, we can eigendecompose it, find its eigenvalues, and rearrange the eigenvalue and eigenvector matrices in a decreasing order.
592592
593-
If $C$ is not diagonalizable, we can perform an SVD of $C$:
593+
The eigendecomposition of $C$ can be found by decomposing $B$ instead. Since $B$ is not a square matrix, we obtain an SVD of $B$:
594594
595595
$$
596596
\begin{aligned}
597-
B^T B &= V \Sigma^\top U^\top U \Sigma V^\top \cr
598-
&= V \Sigma^\top \Sigma V^\top
597+
B B^\top &= U \Sigma V^\top (U \Sigma V^{\top})^{\top}\\
598+
&= U \Sigma V^\top V \Sigma^\top U^\top\\
599+
&= U \Sigma \Sigma^\top U^\top
599600
\end{aligned}
600601
$$
601602
602603
$$
603-
C = \frac{1}{{n}} V \Sigma^\top \Sigma V^\top
604+
C = \frac{1}{n} U \Sigma \Sigma^\top U^\top
604605
$$
605606
606-
We can then rearrange the columns in the matrices $V$ and $\Sigma$ so that the singular values are in decreasing order.
607+
We can then rearrange the columns in the matrices $U$ and $\Sigma$ so that the singular values are in decreasing order.
607608
608609
609610
**Step 4: Select singular values, (optional) truncate the rest:**
@@ -621,7 +622,7 @@ $$
621622
$$
622623
\begin{aligned}
623624
T&= BV \cr
624-
&= U\Sigma V^\top \cr
625+
&= U\Sigma V^\top V \cr
625626
&= U\Sigma
626627
\end{aligned}
627628
$$

0 commit comments

Comments
 (0)