Linear Algebra Review. Fei-Fei Li

Similar documents
Linear Algebra Review. Fei-Fei Li

Lecture: Face Recognition and Feature Reduction

Lecture: Face Recognition and Feature Reduction

Linear Algebra & Geometry why is linear algebra useful in computer vision?

Linear Algebra & Geometry why is linear algebra useful in computer vision?

The Singular Value Decomposition

Foundations of Computer Vision

(a) If A is a 3 by 4 matrix, what does this tell us about its nullspace? Solution: dim N(A) 1, since rank(a) 3. Ax =

The Singular Value Decomposition (SVD) and Principal Component Analysis (PCA)

Notes on singular value decomposition for Math 54. Recall that if A is a symmetric n n matrix, then A has real eigenvalues A = P DP 1 A = P DP T.

Chapters 5 & 6: Theory Review: Solutions Math 308 F Spring 2015

UNIT 6: The singular value decomposition.

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

Remark 1 By definition, an eigenvector must be a nonzero vector, but eigenvalue could be zero.

Linear Algebra review Powers of a diagonalizable matrix Spectral decomposition

Glossary of Linear Algebra Terms. Prepared by Vince Zaccone For Campus Learning Assistance Services at UCSB

Remark By definition, an eigenvector must be a nonzero vector, but eigenvalue could be zero.

CS 143 Linear Algebra Review

Dimensionality Reduction: PCA. Nicholas Ruozzi University of Texas at Dallas

Properties of Linear Transformations from R n to R m

1. Linear systems of equations. Chapters 7-8: Linear Algebra. Solution(s) of a linear system of equations (continued)

Linear Algebra: Matrix Eigenvalue Problems

Linear Algebra Review. Vectors

Conceptual Questions for Review

Linear Algebra, part 3. Going back to least squares. Mathematical Models, Analysis and Simulation = 0. a T 1 e. a T n e. Anna-Karin Tornberg

and let s calculate the image of some vectors under the transformation T.

Linear Algebra Primer

1 Linearity and Linear Systems

Properties of Matrices and Operations on Matrices

Review problems for MA 54, Fall 2004.

Problem # Max points possible Actual score Total 120

Math Bootcamp An p-dimensional vector is p numbers put together. Written as. x 1 x =. x p

MATH36001 Generalized Inverses and the SVD 2015

Knowledge Discovery and Data Mining 1 (VO) ( )

Maths for Signals and Systems Linear Algebra in Engineering

Repeated Eigenvalues and Symmetric Matrices

TBP MATH33A Review Sheet. November 24, 2018

Math 102, Winter Final Exam Review. Chapter 1. Matrices and Gaussian Elimination

Math 315: Linear Algebra Solutions to Assignment 7

22.3. Repeated Eigenvalues and Symmetric Matrices. Introduction. Prerequisites. Learning Outcomes

Symmetric and anti symmetric matrices

Chapter 2. Matrix Arithmetic. Chapter 2

Linear Algebra - Part II

MATH 240 Spring, Chapter 1: Linear Equations and Matrices

Singular Value Decompsition

Review of Linear Algebra

Econ Slides from Lecture 7

Linear Algebra, part 3 QR and SVD

B553 Lecture 5: Matrix Algebra Review

MATH 423 Linear Algebra II Lecture 33: Diagonalization of normal operators.

EK102 Linear Algebra PRACTICE PROBLEMS for Final Exam Spring 2016

Solutions to Final Practice Problems Written by Victoria Kala Last updated 12/5/2015

Recall : Eigenvalues and Eigenvectors

COMP 558 lecture 18 Nov. 15, 2010

Background Mathematics (2/2) 1. David Barber

8. Diagonalization.

. = V c = V [x]v (5.1) c 1. c k

Singular Value Decomposition

Review of Some Concepts from Linear Algebra: Part 2

18.06SC Final Exam Solutions

c c c c c c c c c c a 3x3 matrix C= has a determinant determined by

Data Mining Lecture 4: Covariance, EVD, PCA & SVD

Lecture 6 Sept Data Visualization STAT 442 / 890, CM 462

0.1 Eigenvalues and Eigenvectors

MATH 2331 Linear Algebra. Section 2.1 Matrix Operations. Definition: A : m n, B : n p. Example: Compute AB, if possible.

Study Guide for Linear Algebra Exam 2

Chapter 3. Determinants and Eigenvalues

Chapter 5 Eigenvalues and Eigenvectors

Linear Algebra and Matrices

CS 246 Review of Linear Algebra 01/17/19

Linear Algebra for Machine Learning. Sargur N. Srihari

Cheng Soon Ong & Christian Walder. Canberra February June 2017

Computational Methods. Eigenvalues and Singular Values

Singular Value Decomposition (SVD)

Linear Algebra. Matrices Operations. Consider, for example, a system of equations such as x + 2y z + 4w = 0, 3x 4y + 2z 6w = 0, x 3y 2z + w = 0.

Linear Algebra in Actuarial Science: Slides to the lecture

1. What is the determinant of the following matrix? a 1 a 2 4a 3 2a 2 b 1 b 2 4b 3 2b c 1. = 4, then det

SINGULAR VALUE DECOMPOSITION

Diagonalization of Matrix

2. Every linear system with the same number of equations as unknowns has a unique solution.

ICS 6N Computational Linear Algebra Eigenvalues and Eigenvectors

MTH 464: Computational Linear Algebra

Deep Learning Book Notes Chapter 2: Linear Algebra

Chap 3. Linear Algebra

Introduction to Matrix Algebra

Singular Value Decomposition and Digital Image Compression

Announcements Wednesday, November 01

Spring 2014 Math 272 Final Exam Review Sheet

Matrix Algebra: Summary

Numerical Methods. Elena loli Piccolomini. Civil Engeneering. piccolom. Metodi Numerici M p. 1/??

Numerical Linear Algebra Homework Assignment - Week 2

Image Registration Lecture 2: Vectors and Matrices

Ir O D = D = ( ) Section 2.6 Example 1. (Bottom of page 119) dim(v ) = dim(l(v, W )) = dim(v ) dim(f ) = dim(v )

1. The Polar Decomposition

City Suburbs. : population distribution after m years

14 Singular Value Decomposition

Linear Algebra Fundamentals

4. Determinants.

Homework 1 Elena Davidson (B) (C) (D) (E) (F) (G) (H) (I)

Linear Algebra Highlights

Transcription:

Linear Algebra Review Fei-Fei Li 1 / 37

Vectors Vectors and matrices are just collections of ordered numbers that represent something: movements in space, scaling factors, pixel brightnesses, etc. A vector is a quantity that involves both magnitude and direction A column vector v R nx1 where A row vector v T R nx1 where x 1 x 2 v =. x n v T = [ x 1 x 2... x n ] (1) (2) 2 / 37

Vectors Vectors can represent an offset in 2D or 3D space Points are just vectors from the origin Data (pixels, gradients at an image keypoint, etc) can also be treated as a vector Such vectors don t have a geometric interpretation, but calculations like distance can still have value 3 / 37

Images Note that matrix coordinates are NOT Cartesian coordinates. The upper left corner is [y,x] = (1,1) Grayscale images have one number per pixel, and are stored as an m x n matrix. 4 / 37

Images Color images have 3 numbers per pixel red, green, and blue brightnesses Stored as an m x n x 3 matrix 5 / 37

Matrix Operations Addition Can only add a matrix with matching dimensions, or a scalar. Scaling 6 / 37

Matrix Operations Inner product (dot product) of vectors Multiply corresponding entries of two vectors and add up the result xy is also x y Cos( the angle between x and y ) If B is a unit vector, then AB gives the length of A which lies in the direction of B 7 / 37

Matrix Operations Multiplication For A.B; each entry in the result is (that row of A) dot product with (that column of B) 8 / 37

Matrix Operations Transpose row r becomes column c A useful identity 9 / 37

Matrix Operations Determinant det(a) returns a scalar value for square matrix A. For, Properties: 10 / 37

Special Matrices Identity matrix I Square matrix, 1s along diagonal, 0s elsewhere I.A = A Diagonal matrix Square matrix with numbers along diagonal, 0s elsewhere (A diagonal).(another matrix B) scales the rows of matrix B 11 / 37

Special Matrices Symmetric matrix Skew-symmetric matrix 12 / 37

Homogeneous System In general, a matrix multiplication lets us linearly combine components of a vector But notice, we can t add a constant! The (somewhat hacky) solution? Stick a 1 at the end of every vector 13 / 37

Homogeneous System This is called homogeneous coordinates In homogeneous coordinates, the multiplication works out so the rightmost column of the matrix is a vector that gets added 14 / 37

Inverse of Matrix Given a matrix A, its inverse A 1 is a matrix such that AA 1 =A 1 A = I [ ] 1 [ ] 2 0 1/2 0 = 0 3 0 1/3 Inverse does not always exist. If A 1 exists, A is invertible or non-singular. Otherwise, its singular. Useful identities, for matrices that are invertible: 15 / 37

Matrix Operations Pseudoinverse Say you have the matrix equation AX=B, where A and B are known, and you want to solve for X You can calculate the inverse and premultiply by it: A 1 AX = A 1 BX = A 1 B Python command is numpy.linalg.inv(a) B But calculating the inverse for large matrices often brings problems with computer floating-point resolution (because it involves working with very small and very large numbers together). Or, your matrix might not even have an inverse. Fortunately, there are workarounds to solve AX=B in these situations. Pseudoinverse : numpy.linalg.pinv(a) B 16 / 37

Rank of A Matrix Linear independence Suppose we have a set of vectors v 1,..., v n If we can express v1 as a linear combination of the other vectors v 2...v n, then v1 is linearly dependent on the other vectors. The direction v1 can be expressed as a combination of the directions v 2...v n. (E.g.v 1 =.7v 2.7v 4 ) If no vector is linearly dependent on the rest of the set, the set is linearly independent. 17 / 37

Rank of A Matrix Column/row rank col rank(a)= the max. number of linearly independent column vector of A row rank(a)= the max. number of linearly independent row vector of A Column rank always equals row rank Matrix rank : rank(a) := col rank(a) = row rank(a) For transformation matrices, the rank tells you the dimensions of the output E.g. if rank of A is 1, then the transformation p = Ap maps points onto a line. 18 / 37

Rank of A Matrix If an m x m matrix is rank m, we say its full rank Maps an m x 1 vector uniquely to another m x 1 vector An inverse matrix can be found If rank < m, we say its singular At least one dimension is getting collapsed. No way to look at the result and tell what the input was Inverse does not exist Inverse also doesnt exist for non-square matrices 19 / 37

Eigenvalues and Eigenvectors Suppose we have a square matrix A. We can solve for vector x and scalar λ such that Ax = λx In other words, find vectors where, if we transform them with A, the only effect is to scale them with no change in direction. These vectors are called eigenvectors (German for self vector of the matrix), and the scaling factors λ are called eigenvalues An m x m matrix will have m eigenvectors where λ is nonzero To find eigenvalues and eigenvectors rewrite the equation: (A λi )x = 0 x = 0 is always a solution but we have to find x 0. This means A λi should not be invertible so we can have many solutions. det(a λi ) = 0 20 / 37

Eigenvalues and Eigenvectors For example; A = [ ] 3 1 1 3 det(a λi )x = 0 3 λ 1 1 3 λ = 0 then λ 1 = 4, x1 T = [1 1] and λ 2 = 2, x2 T = [ 1 1] Another example; [ ] 0 1 B = 1 0 then λ 1 = 1, x1 T = [1 1] and λ 2 = 1, x2 T Relation between these two matrices? = [ 1 1] 21 / 37

Singular Value Decomposition (SVD) There are several computer algorithms that can factor a matrix, representing it as the product of some other matrices The most useful of these is the Singular Value Decomposition. Represents any matrix A as a product of three matrices: UΣV T MATLAB command: [U,S,V]=svd(A) A = UΣV T where U and V are rotation matrices, and Σ is a scaling matrix. 22 / 37

Singular Value Decomposition (SVD) Eigenvectors are for square matrices, but SVD is for all matrices To calculate U, take eigenvectors of AA T Square root of eigenvalues are the singular values (the entries of Σ). To calculate V, take eigenvectors of A T A In general, if A is m x n, then U will be m x m, Σ will be m x n, and V T will be n x n. 23 / 37

Singular Value Decomposition (SVD) U and V are always rotation matrices. Geometric rotation may not be an applicable concept, depending on the matrix. So we call them unitary matrices (each column is a unit vector) Σ is a diagonal matrix The number of nonzero entries = rank of A The algorithm always sorts the entries high to low 24 / 37

Singular Value Decomposition (SVD) Look at how the multiplication works out, left to right Column 1 of U gets scaled by the first value from The resulting vector gets scaled by row 1 of VT to produce a contribution to the columns of A 25 / 37

Singular Value Decomposition (SVD) Each product of (column i of U).(value i from Σ).(row i of V T ) produces a component of the final A 26 / 37

Singular Value Decomposition (SVD) Were building A as a linear combination of the columns of U Using all columns of U, well rebuild the original matrix perfectly But, in real-world data, often we can just use the first few columns of U and well get something close (e.g. the first A partial, above) 27 / 37

Singular Value Decomposition (SVD) We can call those first few columns of U the Principal Components of the data They show the major patterns that can be added to produce the columns of the original matrix The rows of V T show how the principal components are mixed to produce the columns of the matrix 28 / 37

SVD Applications 29 / 37

SVD Applications For this image, using only the first 10 of 300 principal components produces a recognizable reconstruction So, SVD can be used for image compression 30 / 37

Principal Component Analysis Remember, columns of U are the Principal Components of the data: the major patterns that can be added to produce the columns of the original matrix One use of this is to construct a matrix where each column is a separate data sample Run SVD on that matrix, and look at the first few columns of U to see patterns that are common among the columns This is called Principal Component Analysis (or PCA) of the data samples 31 / 37

Principal Component Analysis For example One use of this is to construct a matrix where each column is a separate data sample Run SVD on that matrix, and look at the first few columns of U to see patterns that are common among the columns This is called Principal Component Analysis (or PCA) of the data samples 32 / 37

Validation Set, Cross Validation 33 / 37

Validation Set, Cross Validation Class labels for test set 34 / 37

Validation Set, Cross Validation Predicted class labels for test set (accuracy = 0.254 for k=3) 35 / 37

Validation Set Choose a validation set from the training set 36 / 37

Cross Validation 37 / 37