Numerical Linear Algebra (Continued)
CS 740
Ajit Rajwade
1
Eigenvectors and Eigenvalues
2
Eigenvectors and Eigenvalues
3
Examples
4
Non-uniqueness
5
Characteristic equation
6
Characteristic equation
7
Matrix of eigenvectors and eigenvalues
8
Physical example 1
9
In this transformation, the red arrow changes direction but the blue arrow does not. The blue arrow is an eigenvector of this shear mapping, and since its length is unchanged its eigenvalue is 1. The red direction in the second figure is also an eigenvector – it is the direction in which the cloth is stretched and it has an eigenvalue greater than 1.
Physical example 1
10
Physical example 2
11
Properties of Eigenvalues and Eigenvectors
12
Properties of Eigenvalues and Eigenvectors
13
Properties of Eigenvalues and Eigenvectors
14
The product (𝜆-a11)(𝜆-a22)...(𝜆-ann) has a term 𝜆n-1 with the coefficient -(a11 + a22+....+ann).
Eigenvectors and eigenvalues of special matrices
15
Computation of Eigenvectors and Eigenvalues
16
[V,D] = eig(A) returns two outputs. D is a diagonal matrix containing the eigenvalues. V is a matrix whose columns are the corresponding right eigenvectors.
[V,D] = eigs(A) returns a diagonal matrix D of A's six largest magnitude eigenvalues and a matrix V whose columns are the corresponding eigenvectors.
[V,D] = eigs(A,k) returns a diagonal matrix D of A's k largest magnitude eigenvalues and a matrix V whose columns are the corresponding eigenvectors.
Computation of Eigenvectors and Eigenvalues
17
Computing eigenvectors
18
19
Each such term tends to 0, as k tends to ∞, because λ1 is the largest magnitude eigenvalue of A.
This method of eigenvector computation is called as power iteration. It converges to the eigenvector with the largest eigenvalue.
Caution: The possibility that the starting vector x0 has no component in the direction v1 (i.e. if α1 = 0) is very small, and can be eliminated by slightly and randomly perturbing the starting vector.
Caution: If there are two or more eigenvalues that are the largest and have the same magnitude, the starting vector will converge to some linear combination of the corresponding eigenvectors.
Caution: If the initial vector is real and A is real, it will not converge to a complex eigenvector!
Computation of Eigenvectors and Eigenvalues
20
Computation of Eigenvectors and Eigenvalues
where v1 and λ1 are the estimated first eigenvector and first eigenvalue.
21
Computation of Eigenvectors and Eigenvalues
22
Singular Value Decomposition (SVD)
23
Singular value Decomposition
24
Diagonal matrix with non-negative entries on the diagonal – called singular values.
Singular value Decomposition
25
Singular value Decomposition
26
Singular value Decomposition
27
This m by n matrix ui vTi is the product of a column vector ui and the transpose of column vector vi. It has rank 1. Thus A is a weighted summation of r rank-1 matrices.
Note: ui and vi are the i-th column of matrix U and V respectively.
Singular value decomposition
28
Application: SVD of Natural Images
29
30
Left to right, top to bottom:
Reconstructed image using the first i= 1,2,3,5,10,25,50,100,150 singular values and singular vectors.
Last image: original
31
Left to right, top to bottom, we display:
where i = 1,2,3,5,10,25,50,100,150.
Note each image is independently re-scaled to the 0-1 range for display purpose.
Note: the spatial frequencies increase as the singular values decrease
SVD: Use in Image Compression
32
Properties of SVD: Best low-rank reconstruction
is given using the SVD of A as follows:
33
Note: We are using the singular vectors corresponding to the r largest singular values.
This property of the SVD is called the Eckart Young Theorem.
Properties of SVD: Best low-rank reconstruction
34
Frobenius norm of the matrix (fancy way of saying you square all matrix values, add them up, and then take the square root!)
Why?
Geometric interpretation: Eckart-Young theorem
35
Properties of SVD: Singularity
36
Properties of SVD: Rank, Inverse, Determinant
37
Properties of SVD: Pseudo-inverse
38
Properties of SVD: Frobenius norm
39
Solution to equations of the form � Av = 0
40
Solution to equations of the form � Av = 0
41
Solution to equations of the form � Av = 0
42
Thus v is a linear combination of right singular vectors corresponding to zero singular values.
We can express v = Vc where c is a vector of n coefficients since V is an orthonormal basis.
Solution to equations of the form � Av = 0
43
Orthogonal Procrustes problem
http://www.cse.iitb.ac.in/~ajitvr/CS740_Fall2026/procrustes.pdf
44
Geometric interpretation of the SVD
45
Q
AQ
Geometric interpretation of the SVD
46
Geometric interpretation of the SVD
47
n x n diagonal matrix - S
m x n matrix with orthonormal columns - U
n x n orthonormal matrix V
Geometric interpretation of the SVD
48
Computation of the SVD
49
s = svd(X) returns a vector of singular values.
[U,S,V] = svd(X) produces a diagonal matrix S of the same dimension as X, with nonnegative diagonal elements in decreasing order, and unitary matrices U and V so that X = U*S*V'.
[U,S,V] = svd(X,0) produces the "economy size" decomposition. If X is m-by-n with m > n, then svd computes only the first n columns of U and S is n-by-n.
[U,S,V] = svd(X,'econ') also produces the "economy size" decomposition. If X is m-by-n with m >= n, it is equivalent to svd(X,0). For m < n, only the first m columns of V are computed and S is m-by-m.
s = svds(A,k) computes the k largest singular values and associated singular vectors of matrix A.
SVD Uniqueness
50
SVD Uniqueness
51
Any other applications of SVD?
52
Structure from Motion
CS 763
Ajit Rajwade
Problem definition
Human perception of motion
Contents of the lecture
Tomasi and Kanade, “Shape and motion from image streams under orthography: a factorization method”, International Journal of Computer Vision, 1992.�http://link.springer.com/article/10.1007%2FBF00129684#page-1
Algorithm input and assumptions
Algorithm input and assumptions
Algorithm: input and assumptions
Algorithm: input and assumptions
Algorithm: input and assumptions
For each frame, compute the centroid of the 2D points. Deduct the centroid from the points in every frame to create the new matrix on the left. Why do we do this? We will see soon.
We will prove that this matrix actually has rank at the most 3 under ideal conditions (no noise in point coordinates). This is called the Rank Theorem.
Proof: Rank Theorem
Proof: Rank Theorem
The image coordinates are thus given as follows:
point coordinates measured in camera’s coordinate system
The X and Y axes of the coordinate system of the camera in the i-th frame – represented as vectors in 3D. These axes are expressed in the world coordinate system (if they were expressed in the camera’s coordinate system, they would be (1,0,0) and (0,1,0).
Pj = (Xj,Yj,Zj) = coordinates of the j-th point in world coordinate system. {Pj} for j=1 to n constitute the object’s “structure”
Proof: Rank Theorem
Proof: Rank Theorem
Proof: Rank Theorem
R has size 2F x 3 and has rank 3 as F ≥ 3.
S has size 3 x n
and will have rank 3 if the points in S are non-coplanar.
So W̃ has rank 3.
What does the rank theorem tell you?
Reduced form of the SVD as W̃ has rank only 3
R
S
Problem!
Problem solution
These 3 equations are true for all i from 1 to F (i.e. for each frame). These equations are called the metric properties or metric constraints on R. Recall that ii and ji are obtained from the R matrix that you get from the SVD of W̃.
Problem solution: not so soon!
These 3 equations are true for all i from 1 to F (i.e. for each frame). Recall that ii and ji are obtained from the R matrix that you get from the SVD of W̃.
Problem solution: not bad after all!
What about camera translation from frame to frame?
What about camera rotation from frame to frame?
Measurement noise
Measurement noise
How to estimate Q?
How to estimate Q?
How to estimate Q?
5. The linear approximation is given as:
6. But we want fk(qt+ δ) = 0 for all k. Hence for a given k, we have
This is a 9 x 1 vector of first derivatives. Remember that δ is a 9 x 1 vector.
How to estimate Q?
7. Collecting together 3F such equations, we have:
8. One can solve for δ by pseudo-inverse.
9. But this solution will not exactly satisfy all the equations as we performed a linear approximation which was not fully accurate, and also because a least squares solution for δ is not guaranteed to yield fk(qt+ δ) = 0 for all k.
The yellow box contains a 9 x 3F matrix called the Jacobian. Again, δ is a 9 x 1 vector and f(qt) is also a 9 x 1 vector.
How to estimate Q?
10. Hence we update our solution from qt to qt+1 = qt+ δ.
Principal Components Analysis
84
PCA: what does it do?
85
PCA
86
Look at this scatter-plot of points in 2D. The points are highly spread out in the direction of the slanted red line.
PCA
87
PCA
88
PCA
onto u, most accurately approximates it.
89
xi
zi
u
Projection error for yi
Mean deducted point
Projection of yi onto u
90
Total reconstruction error J(u)
The first term does not depend on u, so minimizing J(u) is equivalent to maximizing the following:
91
Scatter matrix (proportional to the sample covariance matrix)
As S is symmetric, V is orthonormal and eigenvalues in 𝛬 are non-negative
Express u as a linear combination of the eigenvectors – this is possible as V is an orthonormal basis. That is any vector in Rd can be expressed as a linear combination of the columns of V
92
It is easy to show this if you express u = Va where a is a d x 1 vector
PCA
93
This term is proportional to the variance of the data when projected along u.
PCA
94
PCA
95
PCA
96
97
For any column vector z, ztz = |z|2 = trace(zzt)
Here we are assuming that 𝜆1 ⩾ 𝜆2 ⩾ … ⩾ 𝜆d.
Thus, the optimal U consists of the eigenvectors of S corresponding to the two largest eigenvalues. This derivation easily extends for any larger k as well.
PCA: Algorithm
98
PCA: algorithm
4. Find the eigenvectors of C:
5. Extract the k eigenvectors corresponding to the k largest eigenvalues. This is called the extracted eigenspace:
99
There is an implicit assumption here that the first k indices indeed correspond to the k largest eigenvalues. If that is not true, you would need to pick the appropriate indices.
PCA: algorithm
6. Project each point onto the eigenspace, giving a vector of k eigen-coefficients for that point.
100
We are representing each face as a linear combination of the k eigenvectors corresponding to the k largest eigenvalues. The coefficients of the linear combination are the eigen-coefficients.
Note that αik is a vector of the eigencoefficients of the i-th sample point, and it has k elements. The j-th element of this vector is denoted as αik (j).
PCA and Face Recognition: Eigen-faces
101
Example 1
102
A face database
http://people.ece.cornell.edu/land/courses/ece4760/FinalProjects/s2011/bjh78_caj65/bjh78_caj65/
103
Top 25 Eigen-faces for this database!
http://people.ece.cornell.edu/land/courses/ece4760/FinalProjects/s2011/bjh78_caj65/bjh78_caj65/
PCA and Face recognition: �Eigenfaces
104
PCA and Face recognition: �Eigenfaces
105
Eigen-coefficients of the probe image zp.
PCA and Face recognition: �Eigenfaces
106
Eigen-coefficients of the probe image zp.
Eigen-coefficients of the l-th gallery image xl.
Note: other distance measures (different from sum of squared differences) may also be employed. One example is sum of absolute differences, given as follows:
Another could be normalized dot product (and this distance measure should be maximized!):
PCA and Face recognition: eigenfaces
M. Turk and A. Pentland (1991). Eigenfaces for recognition, Journal of Cognitive Neuroscience, 3(1): 71–86.
107
PCA and Face recognition: eigenfaces
109
One word of caution: Eigen-faces
110
Eigen-faces: reducing computational complexity.
111
Eigen-faces: reducing computational complexity.
112
Back to Eigen-faces: reducing computational complexity.
113
Xw is an eigenvector of C=XXT! Computing all eigenvectors of C will now have a complexity of only O(N3) for computation of the eigenvectors of XTX + O(N x dN) for computation of Xw from each w = total of O(N3 + dN2) which is much less than O(d3). Note that C has at most only min(N-1,d) eigenvectors corresponding to non-zero eigen-values (why?).
Eigenfaces: Algorithm (N << d case)
114
Eigen-faces: Algorithm (N << d case)
4. Find the eigenvectors of L:
5. Obtain the eigenvectors of C from those of L:
6. Unit-normalize the columns of V.
7. C will have at most only N eigenvectors corresponding to non-zero eigen-values*. Out of these you pick the top k (k < N) corresponding to the largest eigen-values.
* Actually this number is at most N-1 – this is due to the mean subtraction, else it would have been at most N.
115
Example 1
116
A face database
117
Top 25 Eigen-faces for this database!
Example 2
118
The Yale Face database
119
Top 25 eigenfaces from the previous database
Reconstruction of a face image using the top 1,8,16,32,…,104 eigenfaces (i.e. k varied from 1 to 104 in steps of 8)
What if both N and d are large?
120
How to pick k in an actual application?
121
How to pick k in an actual application?
122
Some observations about PCA for face images
123
This error is small on an average for a well-aligned group of face images – we will see why on the next slide.
Vector whose first k entries are identical to those in αi, and the rest are 0.
124
The eigenvalues of the covariance matrix typically decay fast in value (if the faces were properly normalized). Note that the j-th eigenvalue is proportional to the variance of the j-th eigencoefficient, i.e.
What this means is that the data have low variance when projected along most of the eigenvectors, i.e. effectively the data are concentrated in a lower-dimensional subspace of the d-dimensional space.
X-axis = eigenvalue index (in sorted, descending order)
Y-axis = eigenvalue
Example
125
The Yale Face database
126
Top 25 eigenfaces from the previous database: each eigenface is an eigenvector of the covariance matrix reshaped to form an image
Reconstruction of a face image using the top 1,8,16,32,…,104 eigenfaces (i.e. k varied from 1 to 104 in steps of 8)
PCA Algorithm using SVD
PCA Algorithm using SVD
4. Instead of finding the eigenvectors of C, we find the left singular vectors of X and its singular values
5. Extract the k eigenvectors in U corresponding to the k largest singular values to form the extracted eigenspace:
There is an implicit assumption here that the first k indices indeed correspond to the k largest eigenvalues. If that is not true, you would need to pick the appropriate indices.
U,S,V are obtained by computing the SVD of X.
LU Decomposition, QR decomposition and Cholesky decomposition
See lecture material here (SSO accessible).
QR factorization: lecture material (see board-work) taken from here (See part on Gram-Schmidt process).
Cholesky decomposition: see board work; a derivation similar to the one I gave in class is here.
129
References
130