vrishank

← Blog

Lecture 15: PCA and ICA

Stanford CS229 lecture 15 notes: PCA and ICA.

· 2 min read

  • cs229
  • machine-learning
  • course-notes
On this page

Principal Component Analysis (PCA)#

Problem: your data has nn dimensions, but a lot of them are redundant. Maybe two features are almost the same thing (a length in cm and in inches, with some noise). We want to find the main directions along which the data actually varies, and project onto them.

Preprocessing#

  1. Subtract the mean of each feature, so the data is centered at the origin.
  2. (Optional) Divide each feature by its standard deviation, so all features are on the same scale. This matters if the features have wildly different units.

The idea#

Find the unit vector uu such that when you project the data onto uu, the variance of the projections is maximized.

The projection of x(i)x^{(i)} onto uu has length x(i)Tux^{(i)T}u, so we maximize:

1m∑i=1m(x(i)Tu)2=uT(1m∑ix(i)x(i)T)u=uTΣus.t. ∥u∥=1\frac{1}{m}\sum_{i=1}^{m}\left(x^{(i)T}u\right)^2 = u^T\left(\frac{1}{m}\sum_i x^{(i)}x^{(i)T}\right)u = u^T \Sigma u \quad \text{s.t. } \|u\|=1

where Σ\Sigma is the empirical covariance matrix.

The answer: uu is the top eigenvector of Σ\Sigma. Likewise, the top kk eigenvectors u1,...,uku_1, ..., u_k are the kk best directions.

The algorithm#

  1. Compute the covariance matrix Σ\Sigma.
  2. Find its top kk eigenvectors u1,...,uku_1, ..., u_k.
  3. Represent each point by its coordinates in this new basis:
y(i)=[u1Tx(i)⋮ukTx(i)]∈Rky^{(i)} = \begin{bmatrix} u_1^T x^{(i)} \\ \vdots \\ u_k^T x^{(i)} \end{bmatrix} \in \mathbb{R}^k
text
Before:               After projecting on u1:
   .   .  /               . . . . . . . . . 
 .  . . /  .             (all the info in
  . . ./ .                1 dimension)
   . /.
    /

How many components?#

Look at the eigenvalues. Each eigenvalue is the variance captured by that direction. Pick kk so that you keep, say, 95 or 99% of the total variance.

Uses#

  • Compression and speeding up other algorithms
  • Visualization (reduce to 2D or 3D)
  • Noise reduction
  • Removing correlated features, which can also help a learning algorithm that's overfitting

Independent Component Analysis (ICA)#

PCA finds directions of maximum variance, which are orthogonal. ICA has a different goal: find directions along which the data is independent.

The cocktail party problem#

There are nn speakers, and nn microphones. Each microphone records a mix of all the speakers. The sources are s∈Rns \in \mathbb{R}^n (unknown) and what we observe is:

x=Asx = As

where AA is an unknown mixing matrix. Our goal is to find the unmixing matrix W=A−1W = A^{-1} so that we can recover s(i)=Wx(i)s^{(i)} = Wx^{(i)}.

Why is this possible?#

Because we assume the sources are independent of each other and non-Gaussian. (The speakers are talking independently.)

Why non-Gaussian? Because a Gaussian is rotationally symmetric. If the sources were Gaussian, then any rotation of them would look statistically identical, and there'd be no way to tell the right WW from a rotated one. The non-Gaussianity breaks this symmetry.

The algorithm#

Assume each source has a density psp_s (for example, a sigmoid-based CDF g(s)=11+e−sg(s) = \frac{1}{1+e^{-s}}, whose derivative is the density). Because the sources are independent, p(s)=∏jps(sj)p(s) = \prod_j p_s(s_j), and with s=Wxs = Wx:

p(x)=(∏j=1nps(wjTx))∣W∣p(x) = \left(\prod_{j=1}^{n} p_s(w_j^T x)\right)|W|

We maximize the log likelihood using stochastic gradient ascent:

W:=W+α([1−2g(w1Tx(i))⋮1−2g(wnTx(i))]x(i)T+(WT)−1)W := W + \alpha\left(\begin{bmatrix} 1 - 2g(w_1^T x^{(i)}) \\ \vdots \\ 1 - 2g(w_n^T x^{(i)}) \end{bmatrix} x^{(i)T} + (W^T)^{-1}\right)

After it converges, recover the sources with s=Wxs = Wx.

Ambiguities#

ICA can't recover everything:

  • The ordering of the sources (which output is speaker 1?)
  • The scale and sign (a source's volume and polarity are unknown)

For audio, these don't matter at all.