Revision as of 07:00, 30 April 2014 by Jang64 (Talk | contribs)


Basics and Examples of Principal Component Analysis (PCA)

A slecture by Sujin Jang

Partly based on the ECE662 Spring 2014 lecture material of Prof. Mireille Boutin.



Introduction

Principal Component Analysis (PCA) is one of famous techniqeus for dimension reduction, feature extraction, and data visualization. In general, PCA is defined by a transformation of a high dimensional vector space into a low dimensional space. Let's consider visualization of 10-dim data. It is barely possible to effectively show the shape of such high dimensional data distribution. PCA provides an efficient way to reduce the dimensionalty (i.e., from 10 to 2), so it is much easier to visualize the shape of data distribution. PCA is also useful in the modeling of robust classifier where considerably small number of high dimensional training data is provided. By reducing the dimensions of learning data sets, PCA provides an effective and efficient method for data description and classification.

This lecture is designed to provide a mathematical background of PCA and its applications. First, fundamentals of linear algebra is introduced that will be used in PCA. Technical procedure of PCA will be provided to aid understanding of practical implementation of PCA. Based on the procedure, several examples of PCA will be given in dimension reduction.


Eigenvectors, Eigenvalues, and Singular Vector Decompositoin

To understand mechanism of PCA, it is important to understand some important concepts in linear algebra. In this lecture, we will briefly discuss eigenvectors and eigenvalues of a matrix. Also singular vector decomposition (SVD) will be examined in the extraction of principal components.

Eigenvectors and Eigenvalues

Let define a n-by-n matrix A and a non-zero vector $ \vec{x}\in\mathbb{R}^{n} $. If there exists a scalar value $ \lambda $ which satisfies the vector equation

$ A\vec{x}=\lambda\vec{x}, $

we define $ \lambda $ as an eigenvalue of the matrix A, and the corresponding non-zero vector $ \vec{x} $ is called an eigenvector of the matrix A. To determine eigenvalues and eigenvectors a characteristic equation

$ D(\lambda)=det\left(A-\lambda I\right) $

is used. Here is an example of determining eigenvectors and eigenvalues where the matrix A is given by

$ A=\left[\begin{matrix}-5 & 2\\ 2 & -2 \end{matrix}\right]. $

Then the characteristic equation is given by

$ D(\lambda)=\left(-5-\lambda\right)\left(-2-\lambda\right)-4=\lambda^{2}+7\lambda+6=0. $

By solving the quadratic equation for $ \lambda $, we will have two eigenvalues $ \lambda_{1}=-1 $ and $ \lambda_{2}=-6 $. By substituting $ \lambda's $ into the vector equation, we can obtain corresponding eigenvectors;

$ \lambda_{1}:\;\left(A-\lambda_{1}I\right)\vec{x}=0\Rightarrow\begin{cases} -4x_{1}+2x_{2} & =0\\ 2x_{1}-x_{2} & =0 \end{cases} \Rightarrow\vec{x}_{1}=\left[\begin{matrix}1\\ 2 \end{matrix}\right] $
$ \lambda_{2}:\;\left(A-\lambda_{2}I\right)\vec{x}=0\Rightarrow\begin{cases} x_{1}+2x_{2} & =0\\ 2x_{1}+4x_{2} & =0 \end{cases} \Rightarrow\vec{x}_{2}=\left[\begin{matrix}2\\ -1 \end{matrix}\right] $

Singular Vector Decomposition (SVD)

In the implementation of PCA, singular vector decomposition (SVD) is used to extract principal components (eiegenvectors) from a given data set. Given a n-by-m matrix A, a singular vector decomposition of A is expressed as:

$ A=U\Sigma V^{T} $

where $ U\in\mathbb{R}^{n\times n},\;\Sigma\in\mathbb{R}^{n\times m},\; V\in\mathbb{R}^{m\times m} $. The matrix U and V are orthogonal matrices, and consist of left and right singular vectors respectively. The matrix $ \Sigma $ is diagonal and consists of non-negative singular values $ \sigma_{i} $. The singular values are placed in $ \Sigma $ in descending order such as

$ \sigma_{1}\geq\sigma_{2}\geq\cdots\geq\sigma_{p}\geq0\; where\; p=min\left(n,m\right). $

Technical Procedure of PCA

In this section, a brief procedural description of PCA is provided. More detailed theoretical background is directed to BOOK. Assume that we are given by a m-by-n data matrix X consists of n number of m-dim vectors $ \vec{x}_{i}\in\mathbb{R}^{m} $.

Step 1: Compute mean and covariance of data matrix

The covariance matrix of X is called $ S\in\mathbb{R}^{m\times m} $ and defined by

$ S=\frac{1}{n}\sum_{i=1}^{n}\left(\vec{x}_{i}-\bar{x}\right)\left(\vec{x}_{i}-\bar{x}\right)^{T} $

where $ \bar{x}\in\mathbb{R}^{m} $ is the mean of each row in X and defined by

$ \bar{x}=\frac{1}{n}\sum_{i=1}^{n}\vec{x}_{i}. $

Step 2: SVD

Singular vector decomposition of S is implemented to extract principal components and directions:

$ S=U\Sigma V^{T} $

where $ U\in\mathbb{R}^{n\times n},\;\Sigma\in\mathbb{R}^{n\times m},\; V\in\mathbb{R}^{m\times m} $. In the implementation, we use the matrix $ V=\left[u_{1}u_{2}\cdots u_{m}\right] $ where a vector $ u_{i}\in\mathbb{R}^{m} $ represents a principal component direction.

Step 3: Projection

The data matrix X can be projected into a new matrix $ Y\in\mathbb{R}^{k\times m} $ by multiplying a matrix $ P^{T} $

$ Y=P^{T}X $

where $ P=\left[\begin{matrix}u_{1}u_{2}\cdots u_{k}\end{matrix}\right],\; k\leq m $. Proper number of principal components k should be selected in prior to perform projection of data matrix.


Examples

1. 2D data analysis

In this example, PCA is implemented to project 2-D data $ X\in\mathbb{R}^{2\times100} $ on 1-D space (Matlab code is attached above). Figure 1 shows elliptical distribution of X with principal component directions $ \vec{u}_{1} $ and $ \vec{u}_{2} $. The principal directions are extracted from covariance matrix of original data set using SVD method:

$ V=\left[\begin{matrix}\vec{u}_{1} & \vec{u}_{2}\end{matrix}\right]\in\mathbb{R}^{2\times2}. $

As shown in Figure 2, the data matrix X can be rotated to align principal axes with x and y axis:

$ X'=V^{T}X $

where X' represents rotated data matrix. In Figure 3 and 4, the matrix X is projected on the primary and secondary principal direction. Euclidean distances between original and projected 2D points are computed and summed up to quantitatively show reliability in data representation. Errors for each principal axis projection are 97.9172 (primary axis) and 223.0955 (secondary axis). As a result of PCA, it is observed that selection of proper eigenvector is important for the effective representation of higher dimensional data with lower dimensions while the loss of information is minimized.

2. Image compression

In this example, PCA is applied in the compression of 512-by-512 grey-scale image (Figure 5). The image is represented by a matrix $ X\in\mathbb{R}^{512\times512} $. According to the procedure described in Section 3, principal component directions $ V\in\mathbb{R}^{512\times512} $ is extracted. Detailed information on Matlab implementation is referred to (http://people.maths.ox.ac.uk/richardsonm/SignalProcPCA.pdf). Figure 6 depicts the first 30 eigenvalues. By only looking at the eigenvalues, it is hard to judge how many principal components are required to effectively represent the original image without loss of generality. As shown in Figure 8, even though the first three principal components show relatively large eigenvalues, the projected image does not provide clear correspondence to the original image. Figure 7-13 show projection of the original image on new image space defined by different number of principal components. As the number of principal components increases, the projected image becomes visually close to the original image.

3. Nonlinear multimodal data distribution

In this section, two examplar cases where PCA fails in data representation. In the first example, circular pattern of 2D data is analyzed using PCA. Figure 12 shows the original circualr 2D data, and Figure 13 and 14 represent projection of the original data on the primary and secondary principal direction.

The second example is PCA on multi-Gaussian data distribution. Figure 15 depicts the original data distribution, and PCA results using the principal directions are given in Figure 16 and 17. These two examples show limitations of PCA in dimension reduction. When a given data set is not linearly distributed but might be arranged along with non-orthogonal axes or well described by a parameter, PCA could fail to represent and recover original data from projected variables. For example, by only looking at data distribution projected on the principal direction in Figure 13-14 and 16-17, it is almost impossible to find correspondence among different data sets. To resolve these issues, in literature, kernel PCA or statistically independent component analysis (ICA) are employed where PCA fails.


Questions and comments

If you have any questions, comments, etc. please post them on this page.


Back to ECE662, Spring 2014

Alumni Liaison

EISL lab graduate

Mu Qiao