Docsity

Principal components analysis, Lecture notes of Computer Science

Toggle sidebar
bg1
Chapter 12
Principal components analysis
In this set of notes, we will develop a method, Principal Components Analysis
(PCA), that tries to identify the subspace in which the data approximately
lies. PCA is computationally efficient: it will require only an eigenvector
calculation (easily done with the eig function in Matlab).
Suppose we are given a dataset {x(i);i= 1, . . . , n}of attributes of ndif-
ferent types of automobiles, such as their maximum speed, turn radius, and
so on. Let x(i)∈Rdfor each i(dn). But unknown to us, two different
attributes—some xiand xj—respectively give a car’s maximum speed mea-
sured in miles per hour, and the maximum speed measured in kilometers per
hour. These two attributes are therefore almost linearly dependent, up to
only small differences introduced by rounding off to the nearest mph or kph.
Thus, the data really lies approximately on an n−1 dimensional subspace.
How can we automatically detect, and perhaps remove, this redundancy?
For a less contrived example, consider a dataset resulting from a survey of
pilots for radio-controlled helicopters, where x(i)
1is a measure of the piloting
skill of pilot i, and x(i)
2captures how much he/she enjoys flying. Because RC
helicopters are very difficult to fly, only the most committed students, ones
that truly enjoy flying, become good pilots. So, the two attributes x1and
x2are strongly correlated. Indeed, we might posit that the data actually lies
along some diagonal axis (the u1direction) capturing the intrinsic piloting
“karma” of a person, with only a small amount of noise lying off this axis.
(See figure.) How can we automatically compute this u1direction?
167
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Principal components analysis and more Lecture notes Computer Science in PDF only on Docsity!

Chapter 12

Principal components analysis

In this set of notes, we will develop a method, Principal Components Analysis (PCA), that tries to identify the subspace in which the data approximately lies. PCA is computationally efficient: it will require only an eigenvector calculation (easily done with the eig function in Matlab). Suppose we are given a dataset {x(i); i = 1,... , n} of attributes of n dif- ferent types of automobiles, such as their maximum speed, turn radius, and so on. Let x(i)^ ∈ Rd^ for each i (d  n). But unknown to us, two different attributes—some xi and xj —respectively give a car’s maximum speed mea- sured in miles per hour, and the maximum speed measured in kilometers per hour. These two attributes are therefore almost linearly dependent, up to only small differences introduced by rounding off to the nearest mph or kph. Thus, the data really lies approximately on an n − 1 dimensional subspace. How can we automatically detect, and perhaps remove, this redundancy? For a less contrived example, consider a dataset resulting from a survey of pilots for radio-controlled helicopters, where x( 1 i )is a measure of the piloting

skill of pilot i, and x( 2 i )captures how much he/she enjoys flying. Because RC helicopters are very difficult to fly, only the most committed students, ones that truly enjoy flying, become good pilots. So, the two attributes x 1 and x 2 are strongly correlated. Indeed, we might posit that the data actually lies along some diagonal axis (the u 1 direction) capturing the intrinsic piloting “karma” of a person, with only a small amount of noise lying off this axis. (See figure.) How can we automatically compute this u 1 direction?

x 1

x^2

(enjoyment)

(skill)

1

u

u

2

We will shortly develop the PCA algorithm. But prior to running PCA per se, typically we first preprocess the data by normalizing each feature to have mean 0 and variance 1. We do this by subtracting the mean and dividing by the empirical standard deviation:

x( ji )←

x( ji )− μj σj

where μj = (^1) n

∑n i=1 x

(i) j and^ σ

2 j =^

1 n

∑n i=1(x

(i) j −^ μj^ )

(^2) are the mean variance of

feature j, respectively. Subtracting μj zeros out the mean and may be omitted for data known to have zero mean (for instance, time series corresponding to speech or other acoustic signals). Dividing by the standard deviation σj rescales each coor- dinate to have unit variance, which ensures that different attributes are all treated on the same “scale.” For instance, if x 1 was cars’ maximum speed in mph (taking values in the high tens or low hundreds) and x 2 were the num- ber of seats (taking values around 2-4), then this renormalization rescales the different attributes to make them more comparable. This rescaling may be omitted if we had a priori knowledge that the different attributes are all on the same scale. One example of this is if each data point represented a grayscale image, and each x( ji )took a value in { 0 , 1 ,... , 255 } corresponding to the intensity value of pixel j in image i. Now, having normalized our data, how do we compute the “major axis of variation” u—that is, the direction on which the data approximately lies? One way is to pose this problem as finding the unit vector u so that when



 



 ^

























We see that the projected data still has a fairly large variance, and the points tend to be far from zero. In contrast, suppose we had instead picked the following direction:

 

 







































































Here, the projections have a significantly smaller variance, and are much closer to the origin. We would like to automatically select the direction u corresponding to the first of the two figures shown above. To formalize this, note that given a

unit vector u and a point x, the length of the projection of x onto u is given by xT^ u. I.e., if x(i)^ is a point in our dataset (one of the crosses in the plot), then its projection onto u (the corresponding circle in the figure) is distance xT^ u from the origin. Hence, to maximize the variance of the projections, we would like to choose a unit-length u so as to maximize:

1 n

∑^ n

i=

(x(i) T u)^2 =

n

∑^ n

i=

uT^ x(i)x(i) T u

= uT

n

∑^ n

i=

x(i)x(i) T

u.

We can recognize that maximizing this subject to ‖u‖ 2 = 1 gives the principal

eigenvector of Σ = (^) n^1

∑n i=1 x (i)x(i)T^ , which is just the empirical covariance

matrix of the data (assuming it has zero mean).^1 To summarize, we have found that if we wish to find a 1-dimensional subspace with which to approximate the data, we should choose u to be the principal eigenvector of Σ. More generally, if we wish to project our data into a k-dimensional subspace (k < d), we should choose u 1 ,... , uk to be the top k eigenvectors of Σ. The ui’s now form a new, orthogonal basis for the data.^2 Then, to represent x(i)^ in this basis, we need only compute the corre- sponding vector

y(i)^ =

uT 1 x(i) uT 2 x(i) .. . uTk x(i)

∈ Rk.

Thus, whereas x(i)^ ∈ Rd, the vector y(i)^ now gives a lower, k-dimensional, approximation/representation for x(i). PCA is therefore also referred to as a dimensionality reduction algorithm. The vectors u 1 ,... , uk are called the first k principal components of the data.

Remark. Although we have shown it formally only for the case of k = 1, using well-known properties of eigenvectors it is straightforward to show that

(^1) If you haven’t seen this before, try using the method of Lagrange multipliers to max- imize uT^ Σu subject to that uT^ u = 1. You should be able to show that Σu = λu, for some λ, which implies u is an eigenvector of Σ, with eigenvalue λ. (^2) Because Σ is symmetric, the ui’s will (or always can be chosen to be) orthogonal to

each other.

Chapter 13

Independent components

analysis

Our next topic is Independent Components Analysis (ICA). Similar to PCA, this will find a new basis in which to represent our data. However, the goal is very different. As a motivating example, consider the “cocktail party problem.” Here, d speakers are speaking simultaneously at a party, and any microphone placed in the room records only an overlapping combination of the d speakers’ voices. But lets say we have d different microphones placed in the room, and because each microphone is a different distance from each of the speakers, it records a different combination of the speakers’ voices. Using these microphone record- ings, can we separate out the original d speakers’ speech signals? To formalize this problem, we imagine that there is some data s ∈ Rd that is generated via d independent sources. What we observe is

x = As,

where A is an unknown square matrix called the mixing matrix. Repeated observations gives us a dataset {x(i); i = 1,... , n}, and our goal is to recover the sources s(i)^ that had generated our data (x(i)^ = As(i)).

In our cocktail party problem, s(i)^ is an d-dimensional vector, and s( ji )is

the sound that speaker j was uttering at time i. Also, x(i)^ in an d-dimensional vector, and x( ji )is the acoustic reading recorded by microphone j at time i. Let W = A−^1 be the unmixing matrix. Our goal is to find W , so that given our microphone recordings x(i), we can recover the sources by computing s(i)^ = W x(i). For notational convenience, we also let wiT denote

the i-th row of W , so that

W =

— w 1 T — .. . — wdT —

Thus, wi ∈ Rd, and the j-th source can be recovered as s( ji )= wTj x(i).

13.1 ICA ambiguities

To what degree can W = A−^1 be recovered? If we have no prior knowledge about the sources and the mixing matrix, it is easy to see that there are some inherent ambiguities in A that are impossible to recover, given only the x(i)’s. Specifically, let P be any d-by-d permutation matrix. This means that each row and each column of P has exactly one “1.” Here are some examples of permutation matrices:

P =

 ; P =

[

]

; P =

[

]

If z is a vector, then P z is another vector that contains a permuted version of z’s coordinates. Given only the x(i)’s, there will be no way to distinguish between W and P W. Specifically, the permutation of the original sources is ambiguous, which should be no surprise. Fortunately, this does not matter for most applications. Further, there is no way to recover the correct scaling of the wi’s. For in- stance, if A were replaced with 2A, and every s(i)^ were replaced with (0.5)s(i), then our observed x(i)^ = 2A · (0.5)s(i)^ would still be the same. More broadly, if a single column of A were scaled by a factor of α, and the corresponding source were scaled by a factor of 1/α, then there is again no way to determine that this had happened given only the x(i)’s. Thus, we cannot recover the “correct” scaling of the sources. However, for the applications that we are concerned with—including the cocktail party problem—this ambiguity also does not matter. Specifically, scaling a speaker’s speech signal s( ji )by some positive factor α affects only the volume of that speaker’s speech. Also, sign changes do not matter, and s( ji )and −s( ji )sound identical when played on a speaker. Thus, if the wi found by an algorithm is scaled by any non-zero real number, the corresponding recovered source si = wiT x will be scaled by the

conclude that “px(x) = ps(W x).” However, this is incorrect. For example, let s ∼ Uniform[0, 1], so ps(s) = 1{ 0 ≤ s ≤ 1 }. Now, let A = 2, so x = 2s. Clearly, x is distributed uniformly in the interval [0, 2]. Thus, its density is given by px(x) = (0.5)1{ 0 ≤ x ≤ 2 }. This does not equal ps(W x), where W = 0.5 = A−^1. Instead, the correct formula is px(x) = ps(W x)|W |. More generally, if s is a vector-valued distribution with density ps, and x = As for a square, invertible matrix A, then the density of x is given by

px(x) = ps(W x) · |W |,

where W = A−^1.

Remark. If you’re seen the result that A maps [0, 1]d^ to a set of volume |A|, then here’s another way to remember the formula for px given above, that also generalizes our previous 1-dimensional example. Specifically, let A ∈ Rd×d^ be given, and let W = A−^1 as usual. Also let C 1 = [0, 1]d^ be the d-dimensional hypercube, and define C 2 = {As : s ∈ C 1 } ⊆ Rd^ to be the image of C 1 under the mapping given by A. Then it is a standard result in linear algebra (and, indeed, one of the ways of defining determinants) that the volume of C 2 is given by |A|. Now, suppose s is uniformly distributed in [0, 1]d, so its density is ps(s) = 1{s ∈ C 1 }. Then clearly x will be uniformly distributed in C 2. Its density is therefore found to be px(x) = 1{x ∈ C 2 }/vol(C 2 ) (since it must integrate over C 2 to 1). But using the fact that the determinant of the inverse of a matrix is just the inverse of the determinant, we have 1 /vol(C 2 ) = 1/|A| = |A−^1 | = |W |. Thus, px(x) = 1{x ∈ C 2 }|W | = 1{W x ∈ C 1 }|W | = ps(W x)|W |.

13.3 ICA algorithm

We are now ready to derive an ICA algorithm. We describe an algorithm by Bell and Sejnowski, and we give an interpretation of their algorithm as a method for maximum likelihood estimation. (This is different from their orig- inal interpretation involving a complicated idea called the infomax principal which is no longer necessary given the modern understanding of ICA.) We suppose that the distribution of each source sj is given by a density ps, and that the joint distribution of the sources s is given by

p(s) =

∏^ d

j=

ps(sj ).

Note that by modeling the joint distribution as a product of marginals, we capture the assumption that the sources are independent. Using our formulas from the previous section, this implies the following density on x = As = W −^1 s:

p(x) =

∏^ d

j=

ps(wjT x) · |W |.

All that remains is to specify a density for the individual sources ps. Recall that, given a real-valued random variable z, its cumulative distri- bution function (cdf) F is defined by F (z 0 ) = P (z ≤ z 0 ) =

∫ (^) z 0 −∞ pz^ (z)dz^ and the density is the derivative of the cdf: pz (z) = F ′(z). Thus, to specify a density for the si’s, all we need to do is to specify some cdf for it. A cdf has to be a monotonic function that increases from zero to one. Following our previous discussion, we cannot choose the Gaussian cdf, as ICA doesn’t work on Gaussian data. What we’ll choose instead as a reasonable “default” cdf that slowly increases from 0 to 1, is the sigmoid function g(s) = 1/(1 + e−s). Hence, ps(s) = g′(s).^1 The square matrix W is the parameter in our model. Given a training set {x(i); i = 1,... , n}, the log likelihood is given by

`(W ) =

∑^ n

i=

( (^) d ∑

j=

log g′(wTj x(i)) + log |W |

We would like to maximize this in terms W. By taking derivatives and using the fact (from the first set of notes) that ∇W |W | = |W |(W −^1 )T^ , we easily derive a stochastic gradient ascent learning rule. For a training example x(i), the update rule is:

W := W + α

1 − 2 g(wT 1 x(i)) 1 − 2 g(wT 2 x(i)) .. . 1 − 2 g(wTd x(i))

x(i)T^ + (W T^ )−^1

(^1) If you have prior knowledge that the sources’ densities take a certain form, then it is a good idea to substitute that in here. But in the absence of such knowledge, the sigmoid function can be thought of as a reasonable default that seems to work well for many problems. Also, the presentation here assumes that either the data x(i)^ has been preprocessed to have zero mean, or that it can naturally be expected to have zero mean (such as acoustic signals). This is necessary because our assumption that ps(s) = g′(s) implies E[s] = 0 (the derivative of the logistic function is a symmetric function, and hence gives a density corresponding to a random variable with zero mean), which implies E[x] = E[As] = 0.