Dimension Reduction
Dimension Reduction
Principal components analysis (PCA) finds low dimensional approximations to the data by
projecting the data onto linear subspaces.
Let X ∈ Rd and let Lk denote all k-dimensional linear subspaces. The k th principal subspace
is !
e − yk2
`k = argmin E min kX
`∈Lk y∈`
Let Σ = E((X − µ)(X − µ)T ) denote the covariance matrix, where µ = E(X). Let λ1 ≥ λ2 ≥
· · · ≥ λd be the ordered eigenvalues of Σ and let e1 , . . . , ed be the corresponding eigenvectors.
Let Λ be the diagonal matrix with Λjj = λj and let E = [e1 · · · ed ]. Then the spectral
decomposition of Σ is X
Σ = EΛE T = λj ej eTj .
j
1
Let Y = (Y1 , . . . , Yd ) where Yi = eTi (X − µ). Then Y is the PCA-transformation applied to
X. The random variable Y has the following properties:
Lemma 2 We have:
Hence, Pm
j=1 λj
Pd
j=1 λj
is the percentage of variance explained by the first m principal components.
The data version of PCA is obtained by replacing Σ with the sample covariance matrix
n
b= 1
X
Σ (Xi − X n )(Xi − X n )T .
n i=1
3. Choose a dimension k.
Pk
4. Define the dimension reduced data Zi = Tk (Xi ) = X + j=1 βij ej where βij =
hXi − X, ej i.
Example 3 Figure 1 shows a synthetic two-dimensional data set together with the first
principal component.
Example 4 Figure 2 shows some handwritten digits. The eigenvalues and the first few
eigenfunctions are shown in Figures 3 and 4. A few digits and their low-dimensional recon-
structions are shown in Figure 5.
2
1.0
0.8
0.6
0.4
0.2
0.0
3
Variance
Dimension
How well does the sample version approximate the population version? For now, assume
the dimensions d is fixed and that n is large. We will study the high-dimensional case later
where we will use some random matrix theory.
and hence, the estimated eigenvalues are consistent. We can also say that the eigenvectors
are consistent. We have
23/2 ||Σ
b − Σ||
||b
ej − ej || ≤ .
min(λj−1 − λj , λj − λj+1 )
(See Yu, Wang and Samworth, arXiv:1405.0680.) There is a also a central limit theorem
for the eigenvalues and eigenvectors which also leads to a proof that the bootstrap is valid.
However, these limiting results depend on the distinctness of the eigenvalues.
There is a strong connection between PCA and the singular value decomposition (SVD). Let
X be an n × d matrix. The SVD is
X = U DV T
4
Figure 4: Digits: mean and eigenvectors
5
where U is an n × n matrix with orthonormal columns, V is a d × d matrix with orthonormal
columns, and D is an n × d diagonal matrix with non-negative real numbers on the diagonal
(called singular values). Then
X T X = (V DU T )(U DV T ) = V D2 V T
and hence the singular values are the square root of the eigenvalues.
2 Multidimensional Scaling
which measures how well the map T preserves pairwise distances. Multidimensional scal-
ing find the linear map T to minimize L.
Theorem 5 The linear map T : Rd → Rk that minimizes L is the projection onto Span{e1 , . . . , ek }
where e1 , . . . , ek are the first k principal components.
We could use other measures of distortion. In that case, the MDS solution and the PCA
solution will not coincide.
3 Kernel PCA
To get a ninlinear version of PCA, we can use a kernel. Suppose we have a “feature map”
x 7→ Φ(x) and want to carry out PCA in this new feature space. For the moment, assume
that the feature vectors are centered (we return to this point shortly). Define the empirical
covariance matrix n
1X
CΦ = Φ(xi )Φ(xi )T .
n i=1
We can define eigenvalues λ1 , λ2 , . . . and eigenvectors v1 , v2 , . . . of this matrix.
6
It turns out that the eigenvectors are linear combinations of the feature vectors Φ(x1 ), . . . , Φ(xn ).
To see this, note that
n
1X
λv = CΦ v = Φ(xi )Φ(xi )T v
n i=1
n n
1X X
= h Φ(xi ), v i Φ(xi ) = αi Φ(xi )
n i=1 i=1
where
1 1
αi = h Φ(xi ), v i = h Φ(xi ), CΦ v i .
n nλ
Now
n
X
λ αi h Φ(xk ), Φ(xi ) i = λ h Φ(xk ), Cv i
i=1
n
1X
= λ h Φ(xk ), Φ(xj )Φ(xj )T v i
n j=1
n n
1X T
X
= h Φ(xk ), Φ(xj )Φ(xj ) αi Φ(xi ) i
n j=1 i=1
n n
1X X
= αi h Φ(xk ), h Φ(xj ), Φ(xi ) i Φ(xj ) i .
n i=1 j=1
Define the kernel matrix K by Kij = h Φ(xi ), Φ(xj ) i . Then we can write the above equation
as
λnKα = K 2 α
Kα = nλα
In order to compute the kernel PCA projection of a new test point x, it is necessary to
project the feature vector Φ(x) onto the principal direction vm . This requires the evaluation
n
X
h v, Φ(x) i = αi h Φ(xi ), Φ(x) i
i=1
n
X
= αi K(xi , x)
i=1
7
Thus, the entire procedure uses only the kernel evaluations K(x, xi ) and never requires actual
manipulation of feature vectors, which could be infinite dimensional. This is an instance of
the kernel trick. An arbitrary data point x can then be approximated by projecting Φ(x)
onto the first k vectors. This defines an approximation in the feature space. We then need
to find x
e that corresponds to this projection. There is an iterative algorithm for doing this
(Mika et al 1998) which turns out to be a weighed version of the mean shift algorithm.
To complete the description of the algorithm, it is necessary to explain how to center the
data in feature space using only kernel operations. This is accomplished by transforming the
kernel according to
e ij = (K − 1n K − K1n + 1n K1n )
K ij
where
1 1 ··· 1
1 1
1 ··· 1 1 T
1n = . .. .. = 11
n .. . ··· . n
1 1 ··· 1
where 1 denotes the vector of all ones.
Just as for standard PCA, this selects components of high variance, but in the feature space
of the kernel. In addition, the “feature functions”
X n
(m)
fm (x) = αi K(Xi , x)
i=1
are orthogonal and act as representative feature functions in the reproducing kernel Hilbert
space of the kernel, with respect to the given data. Intuitively, these functions are smooth
respect to the RKHS norm k · kK among all those supported on the data.
Another perspective on kernel PCA is that it is doing MDS on the kernel distances dij =
p
2(1 − K(Xi , Xj )); see Williams (2002).
8
4 Local Linear Embedding
Local Linear Embedding (LLE) (Roweis et al) is another nonlinear dimension rediction
method. The LLE algorithm is comprised of three steps. First, nearest neighbors are com-
puted for each point Xi ∈P Rd . Second, each point is regressed onto its neighbors, giving
weights wij so that Xi = j wij Xj . Third, the Xi ∈ Rd are replaced by Yi ∈ Rm where
typically m d by solving a sparse eigenvector problem. The result is a highly nonlinear
embedding, but one that is carried out by optimizations that are not prone to local minima.
Underlying the procedure, as for many “manifold” methods, is a weighted sparse graph that
represents the data.
Step 1: Nearest Neighbors. Here the set of the K nearest neighbors in standard Euclidean
space is constructed for each data point. Using brute-force search, this requires O(n2 d) oper-
ations; more efficient algorithms are possible, in particular if approximate nearest neighbors
are calculated. The number of neighbors K is a parameter to the algorithm, but this is the
only parameter needed by LLE.
Step 2: Local weights. In this step, the local geometry of each point is characterized by a
set of weights wij . The weights are computed by reconstructing each input Xi as a linear
combination of its neighbors, as tabulated in Step 1. This is done by solving the least squares
problem
n
X X
min kXi − wij Xj k22 (1)
w
i=1 j
where the weights wij are calculated in Step 2. To obtain a unique solution, the vectors are
“centered” to have mean zero and unit covariance:
X 1X
Yi = 0 Yi YiT = Im (3)
i
n i
9
Carrying out this optimization is equivalent to finding eigenvectors by minimizing the quadratic
form
Ψ(y) = y T Gy (4)
= y T (I − W )T (I − W )y (5)
(6)
Note that the last step assumes that the underlying graph encoded by the nearest neighbor
graph is connected. Otherwise, there may be more than one eigenvector with eigenvalue
zero. If the graph is disconnected, then the LLE algorithm can be run separately on each
connected component. However, the recommended procedure is to choose K so that the
graph is connected.
Using the simplest algorithms, the first step has time complexity O(dn2 ), the second step
requires O(nK 3 ) operations, and the third step, using routines for computing eigenvalues
for sparse matrices, requires O(mn2 ) operations (and O(n3 ) operations in the worse case if
sparsity is not exploited and the full spectrum is computed). Thus, for high dimensional
problems, the first step is the most expensive. Since the third step computes eigenvectors,
it shares the property with PCA that as more dimensions are added to the embedding, the
previously computed coordinates do not change.
10
Figure 6: Each data set has n = 1, 000 points in d = 3 dimensions, and LLE was run with
K = 8 neighbors.
11
Figure 7: Faces example. n = 1, 965 images with d = 560, with LLE run for K = 12
neighbors.
Figure 8: Lips example. n = 15, 960 images in d = 65, 664 dimensions, with LLE run for
K = 24 neighbors.
12
5 Isomap
Isomap is a technique that is similar to LLE, intended to provide a low dimensional “mani-
fold” representation of a high dimensional data set. Isomap differs in how it assesses similarity
between objects, and in how the low dimensional mapping is constructed.
The first step in Isomap is to constructed a graph with the nodes representing instances
Xi ∈ Rd to be embedded in a low dimensional space. Standard choices are a k-nearest
neighbors, and -neighborhoods. In the k-nearest neighborhood graph, each point Xi is
connected to its closest k neighbors Nk (Xi ), where distance is measured using Euclidean
distance in the ambient space Rd . In the -neighborhood graph, each point Xi is connected
to all points N (Xi ) within a Euclidean ball of radius centered at Xi . The graph G = (V, E)
by taking edge set V = {x1 , . . . , xn } and edge set
(u, v) ∈ E if v ∈ N (u) or u ∈ N (v) (9)
Note that the node degree in these graphs may be highly variable. For simplicity, assume
that the graph is connected; the parameters k or may need to be carefully selected for this
to be the case.
The next step is to form a distance between points by taking path distance in the graph. That
is d(Xi , Xj ) is the shortest path between node Xi and Xj . This distance can be computed
for sparse graphs in time O(|E| + |V | log |V |). The final step is to embed the points into a
low dimensional space using metric multi-dimensional scaling.
1. Compute k nearest neighbors for each point, forming the nearest neighbor graph G =
(V, E) with vertices {Xi }.
2. Compute graph distances d(Xi , Xj ) using Dijkstra’s algorithm
3. Embed the points into low dimensions using metric multidimensional scaling
Isomap and LLE both obtain nonlinear dimensionality reduction by mapping points into a
low dimensional space, in a manner that preserves the local geometry. This local geometry
will not be preserved by classical PCA or MDS, since far away points on the manifold will
be, typically, be mapped to nearby points in the lower dimensional space.
6 Laplacian Eigenmaps
A similar
approach is based on the use of the graph Laplacian. Recall that if wij =
Xi −Xj
Kh h
is a weighting between pairs of points determined by a kernel K, the graph
13
Laplacian associated W is given by
L=D−W (10)
P
where D = diag(di ) with di = j wij the sum of the weights for edges emanating from node
i. In Laplacian eigenmaps, the embedding is obtained using the spectral decomposition of
L.
into k − 1 dimensions.
The intuition behind this approach can be seen from the basic properties of Rayleigh quo-
tients and Laplacians. In particular, we have that the first nonzero eigenvector satisfies
X
y1 = arg min y1T Ly1 = arg min wij (y1i − y1j )2 (12)
i,j
Thus, the eigenvector minimizes the weighted graph L2 norm; the intuition is that the
vector changes very slowly with respect to the intrinsic geometry of the graph. This analogy
is strengthened by consistency properties of the graph Laplacian. In particular, if the data
lie on a Riemannian manifold M , and f : M → R is a function on the manifold,
Z
T
f Lf ≈ k∇f (x)k2 dM (x) (14)
M
where on the left hand side we have evaluated the function on n points sampled uniformly
from the manifold.
14
Figure 9: A portion of the similarity graph for actual scanned digits (1s and 2s), projected
to two dimensions using Laplacian eigenmaps. Each image is a point in R256 , as a 16 × 16
pixel image; the graph suggests the data has lower dimensional “manifold” structure
15
7 Diffusion Distances
As we saw when we discussed spectral clustering, there are other versions of graph Laplacians
such as D−1/2 W D−1/2 and D−1 W that can have better behavior. In fact, let us consider the
matrix L = D−1 W which, as we shall now see, has a nice interpretation. We can view L as
the transition matrix for a Markov chain on the data. This has a population analogue: we
define the diffusion (continuous Markov chain) with transition density
K(x, y)
`(y|x) =
s(x)
R R
where s(x) = K(x, y)dP (y). The stationary distribution has density π(y) = s(y)/ s(u)dP (u).
Then L is just the discrete version of this transition probability. Suppose we run the chain
for t steps. The transition matrix is Lt . The properties of this matrix give information on
the larger scale structure of the data. We define the diffusion distance by
Z
p(u)
Dt (x, y) = (qt (u|x) − qt (u|y))2
π(u)
which is a measure of how har it is to get from x to y in t steps (Coifman and Lafon, 2006).
It can be shown that sX
Dt (x, y) = λ2t
j (ψj (x) − ψj (y))
2
where λj and ψj are the eigenvalues and eigenvectors of q. We can now reduce the dimension
of the data by applying MDS to Dt (x, y). Alternatively, they suggest maping a point x to
Let X ∈ Rd and let F be a set of functions from [0, 1]k to Rd . The principal manifold (or
principal curve) is the function f ∈ F that minimizes
!
R(f ) = E min kX − f (z)k2 . (15)
z∈[0,1]k
16
2
●
●
● ●● ● ●● ●
● ● ●
● ●● ● ●
●●
● ●●● ●
● ●●●● ●
●●● ●● ● ●
●
●
●
● ●●
● ●
●
●●●
●
● ●
●
●
●●●
●●●
●
●
●●●
●
●●● ● ●
● ●●
● ●
●
●●
●●●●
●
●●
●
●
●
●●●
●
●
●
●
●●
●●●●
●●
●●
●●●●●●
1
● ●●
● ●●●
●●●
●●
●
●●
●●●●●
●
●
● ●●
●●●
●
●●
●● ●
●
●●
●
●●● ●
● ●●● ●
●●●
● ●●●●
●
● ●●● ● ●●● ●
● ●●● ● ● ●
● ●●●●●●●
● ●●● ●●
● ● ● ●●
●●●● ●●●
●●
●●●●
●
●
●●● ●●
●●
●●
●● ●
●●●
● ● ●● ● ● ●●
● ●
●●●●●
●●●
●
●●●●
● ●
●
●
●
●
●
●●
●
●
●
●
●● ● ●● ● ●
●
●
●●
●
●●●●
●
●●●
●●●
●●
●●
●
●
●●● ●●
●●●
● ●
● ●
●
●●●●
●
●● ●
●●●● ● ●
y
● ●●
●● ●●●
● ●
●
●●
●●
●●
●
● ● ●● ●
0
●● ●● ●
●●
●●● ●
●●●●●
●
●
●●
●●●●●
●
●
●●
●●
●●
●●
●
●
●●● ●
●●●
● ● ●●●●●
●● ●
●●
● ●●
●● ● ● ● ●●
●●●●
●
●●●
●●
●●
●
●●
●●
●
●● ●●●●
●
●●● ● ●● ● ●●●
● ●
●●●
● ●● ● ●
●●●●●●● ● ● ●● ● ● ●●
● ● ●● ●● ●●
●●●
●●●
●●●●●
● ●● ● ● ● ●●●
●
●
●●
●
●●
●
●
●●●
●
●
●
● ●●
●
●
●●●
●
● ●●●
●
●● ●●●
● ●●●●●
●●●
● ●●
●●
●●●
●●●
●● ● ●●●
●
−1
● ● ● ●
● ●
● ●●●●
●●
●●
●●
●●
●●●
●●
●
●
●
●●
●●●
●
●●
●
●
●●
●
●
●
●
●●●●●
●
●●
● ●●●●
●●
●
●●●
●●●
●●●
●●
●● ●●●● ●
●●●●● ●● ●
●
●
●●
●
●●
●●● ●● ●
●
● ●
● ●
●●
●
●●●● ● ●
● ● ● ●
● ●
●● ● ●●
● ● ●
−2 −1 0 1 2
Figure 10: Diffusion maps. Top left: data. Top right: Transition matrix for t = 1. Botom
left: Transition matrix for t = 3. Bottom right: Transition matrix for t = 64.
17
To see how general this is, note that we recover principal components as a special case by
taking F to be linear mappings. We recover k-means by taking F to be all mappings from
{1, . . . , k} to Rd . In fact we could construct F to map to k-lines (or k-planes), also called
local principal components; see Bradley and Mangasarian (1998) and Kambhatla and Leen
(1994, 1997). But our focus in this section is on smooth curves.
We will take ( )
F= f : kf k2k ≤ C 2
where kf kK is the norm for a reproducing kernel Hilbert space (RKHS) with kernel K. A
common choice is the Gaussian kernel
kz − uk2
K(z, u) = exp − .
2h2
For fixed α we find each ξi by any standard nonlinear function minimizer. Given ξ we then
find α by minimizing
n M M M
1X X λ XX
kXi − αj K(zj , ξi )k2 + αi αj K(zi , zj ).
n i=1 j=1
2 i=1 j=1
Example 6 Figure 11 shows some data and four principal curves based on increasing degrees
of regularization.
18
Figure 11: Principal curve with increasing amounts of regularization.
Theoretical results are due to Kégl et al. (2000) and Smola, Mika, Schölkopf, Williamson
(2001). For example, we may proceed as follows. Define a norm
kf k# ≡ sup kf (z)k2 .
z∈[0,1]k
Theorem 7 Let f∗ minimize R(f ) over F. Assume that the distribution of Xi is supported
on a compact set S and let C = supx,x0 ∈S kx − x0 k2 . For every > 0
2
P |R(f ) − R(f∗ )| > 2 ≤ 2N
b , F, k · k# e−n /(2C)
4L
for some constant L.
Proof. As with any of our previous risk minimization proofs, it suffices to show that
2
P sup |R(f ) − R(f )| > ≤ 2N
b , F, k · k# e−n /(2C) .
f ∈F 4L
19
Let G be the set of functions of the form gf (x, z) = kx − f (z)k2 . Define a metric on G by
Let δ = /2 and let f1 , . . . , fN be an δ/2 of F. Let gj = gfj , j = 1, . . . , N . It follows from (16)
that g1 , . . . , gN is an δ/(2L) cover of G. For any f there exists fj such that d(gf , gj ) ≤ δ/2.
So
|R(f ) − R(fj )| = E inf kX − f (z)k2 − inf kX − fj (z)k2
z z
= E inf gf (X, z) − inf gj (X, z)
z z
Similarly for R.
b So,
|R(f
b ) − R(f )| ≤ |R(f
b j ) − R(fj )| + δ.
Therefore,
P sup |R(f
b ) − R(f )| > ≤ P max |R(f
b j ) − R(fj )| > /2
f ∈F fj
2
≤ 2N , F, k · k# e−n /(2C) .
4L
Some comments on this result are in order. First, Smola, Mika, Schölkopf, Williamson (2001)
compute N 4L , F, k · k# for several classes. For the Gaussian kernel they show that
s
1
N (, F, k · k# ) = O
for some constant s. This implies that R(fb) − R(f∗ ) = O(n−1/2 ) which is a parametric rate
of convergence. This is somewhat misleading. As we get more and more data, we should
regularize less and less if we want a truly nonparametric analysis. This is ignored in the
analysis above.
20
9 Random Projections: Part I
A simple method for reducing the dimension is to do a random projection. Surprisingly, this
can actually preserve pairwise distances. This fact is known as the Johnson-Lindenstrauss
Lemma, and this section is devoted to an elementary proof of this result.1
Theorem 8 (Johnson-Lindenstrauss) Fix > 0. Let m ≥ 32 log n/2 . Then, with prob-
2
ability at least 1 − e−m /16 ≥ 1 − (1/n)2 , we have
for all i, j.
Notice that the embedding dimension m, does not depend on the original dimension d.
where
Xj − X k
Zi = Si ,
||Xj − Xk ||
where Si is the ith row of S. Note that Zi ∼ N (0, 1) and so Zi2 ∼ χ21 and E[Zi2 ] = 1. The
moment generating function of Zi2 is m(λ) = (1 − 2λ)−1/2 (for λ < 1/2). So, for λ > 0 small
enough,
2 e−λ 2
E[eλ(Zi −1) ] = √ ≤ e2λ .
1 − 2λ
Hence, " !#
2
X
E exp λ (Zi2 − 1) ≤ e2mλ .
i
1
In this section and the next, we follow some lecture notes by Martin Wainwright.
21
Thus
m
!
1 X 2 Pm 2
P Zi − 1 ≥ = P eλ i=1 Zi −1 ≥ eλm
m i=1
Pm 2 2
≤ e−λm E eλ i=1 Zi −1 ≤ e2mλ −mλ
2 /8
≤ e−m
1
Pm 2
where, in the last step, we chose λ = /4. By a similar argument, we can bound P m
Z
i=1 i − 1 ≤ − .
Hence,
||S(Xj − Xk )||2
2
P 2
− 1 ≥ ≤ 2e−m /8 .
m||Xj − Xk ||
By the union bound, the probability that (17) fauls for some pair is at most
2 /8 2 /16
n2 2e−m ≤ e−m
The key to the Johnson-Lindenstrauss (JL) theorem was applying concentration of measure
to the quantity
||Su||2
Γ(K) = sup −1
u∈K m
where
Xj − Xk
K= : j 6= k .
||Xj − Xk ||
Note that K is a subset of the sphere S d−1 .
We can generalize this to other subsets of the sphere. For example, suppose that we take
b = m−1 S T S. Note that each row of Si has mean 0 and variance matrix I
K = S d−1 . Let Σ
and Σ
b is the estimate of the covaraince matrix. Then
||Su||2 ||Su||2
sup − 1 = sup −1
u∈K m ||u||=1 m
= sup uT (m−1 S T S − I)u = ||Σ
b − I||
||u||=1
which is the operator norm of the difference between the sample covariance and true covari-
ance.
22
Now consider least squares. Suppose we want to minimize ||Y − Xβ||2 where Y is an n × 1
vector and X is a n × d matrix. If n is large, this may be expensive. We could try to
approximate the solution by minimizing ||S(Y − Xβ)||2 . The true least squares solution lies
in the column space of X. The approximate solution will lie in the column space of SX. It
can be shown that if This suggests taking
n o
d−1 d
K= u∈S : u = Xv for some v ∈ R .
Later we will show that, if Γ(K) is small, then the solution to the reduced problem approxi-
mates the original problem.
How can we bound Γ(K)? To answer this, we use the Gaussian width which is defined by
W (K) = E suphu, Zi
u∈K
Theorem 9 Let S be a m × d Gaussian projection matrix. Let K be any subset of the sphere
and suppose that m ≥ W 2 (K). Then, for any ∈ (0, 1/2),
W (K) 2
P Γ(K) ≥ 4 √ + ≤ 2e−m /2 .
m
In particular, if m ≥ W 2 (K)/δ 2 , then Γ(K) ≤ 8δ with high probability.
Since the set is finite, we know from our previous results on expectations of maxima, that
p p
W (K) ≤ 2 log N ≤ 4 log n.
According to the above theorem, we need to take m ≥ W 2 /δ 2 log n/δ 2 which agrees with
the JL theorem.
The proof of the theorem is quite long but it basically uses concentration of measure ar-
guments to control the maximum fluctuations as u varies over K. When applied to least
squares, if we want to approximate ||Y − Xβ||2 it turns out that the Gaussian width has
constant order. Thus, taking m to be a large, fixed constant is enough. But this result
assumed we are interested in approximating β, b we need m ≈ n which is not useful. How-
ever, there is an improvement that uses iterative sketching that only requires m = O(log n)
observations. A good reference is:
M. Pilanci and M. J. Wainwright. Iterative Hessian Sketch: Fast and accurate solution
approximation for constrained least-squares. arXiv:1411.0347.
23