39
Linear Algebra Review (with a Small Dose of Optimization) Hristo Paskov CS246

Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

  • Upload
    others

  • View
    8

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Linear Algebra Review

(with a Small Dose of Optimization)

Hristo Paskov

CS246

Page 2: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Outline

• Basic definitions

• Subspaces and Dimensionality

• Matrix functions: inverses and eigenvalue

decompositions

• Convex optimization

Page 3: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Vectors and Matrices

• Vector � ∈ ℝ�

� =����⋮��

• May also write

� = �� �� … ��

Page 4: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Vectors and Matrices

• Matrix � ∈ ℝ�×�

� =��� ⋯ ���⋮ ⋱ ⋮��� ⋯ ���

• Written in terms of rows or columns

� =��⋮��

= �� … ��

�� = ��� … ��� �� = ��� … ���

Page 5: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Multiplication

• Vector-vector: �, � ∈ ℝ� → ℝ�� =�����

���• Matrix-vector: � ∈ ℝ�, � ∈ ℝ�×� → ℝ�

�� =��⋮��

� =���⋮�� �

Page 6: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Multiplication

• Matrix-matrix: � ∈ ℝ�×� , � ∈ ℝ�×� → ℝ�×�

=5

3

3

4 4

5

Page 7: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Multiplication

• Matrix-matrix: � ∈ ℝ�×� , � ∈ ℝ�×� → ℝ�×�– � rows of �, !" cols of �

�� = �!� … �!� = ��⋮ � �

= �!� ⋯ �!�⋮ �!" ⋮

� !� ⋯ � !�

Page 8: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Multiplication Properties

• Associative

�� # = � �#• Distributive

� � + # = �� + �#• NOT commutative

�� ≠ ��– Dimensions may not even be conformable

Page 9: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Useful Matrices

• Identity matrix & ∈ ℝ�×�– �& = �, &� = �

1 0 00 1 00 0 1

&�" = )0* ≠ +1* = +

• Diagonal matrix � ∈ ℝ�×�

� = diag 0�, … , 0� =0� ⋯ 0⋮ 0� ⋮0 ⋯ 0�

Page 10: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Useful Matrices

• Symmetric � ∈ ℝ�×�: � = �• Orthogonal 2 ∈ ℝ�×�:

22 = 22 = &– Columns/ rows are orthonormal

• Positive semidefinite � ∈ ℝ�×�:

��� ≥ 0forall� ∈ ℝ�– Equivalently, there exists 8 ∈ ℝ�×�

� = 88

Page 11: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Outline

• Basic definitions

• Subspaces and Dimensionality

• Matrix functions: inverses and eigenvalue

decompositions

• Convex optimization

Page 12: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Norms

• Quantify “size” of a vector

• Given � ∈ ℝ�, a norm satisfies

1. 9� = 9 �2. � = 0 ⇔ � = 03. � + � ≤ � + �

• Common norms:

1. Euclidean 8�-norm: � � = ��� +⋯+ ���2. 8�-norm: � � = �� +⋯+ ��3. 8<-norm: � < = max� ��

Page 13: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Linear Subspaces

Page 14: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Linear Subspaces

• Subspace ? ⊂ ℝ� satisfies

1. 0 ∈ ?2. If �, � ∈ ? and 9 ∈ ℝ, then 9 � + � ∈ ?

• Vectors A�, … , A� span ? if

? = �B�A��

���B ∈ ℝ�

Page 15: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Linear Independence and Dimension

• Vectors A�, … , A� are linearly independent if

∑ B�A����� = 0 ⟺ B = 0– Every linear combination of the A� is unique

• Dim ? = F if A�, … , A� span ? and are

linearly independent

– If G�, … , G� span ?then

• H ≥ F• If H > F then G� are NOT linearly independent

Page 16: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Linear Independence and Dimension

Page 17: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Matrix Subspaces

• Matrix � ∈ ℝ�×� defines two subspaces

– Column space col � = �B B ∈ ℝ� ⊂ ℝ�– Row space row � = �L L ∈ ℝ� ⊂ ℝ�

• Nullspace of �: null � = � ∈ ℝ� �� = 0– null � ⊥ row �– dim null � + dim row � = P– Analog for column space

Page 18: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Matrix Rank

• rank � gives dimensionality of row and

column spaces

• If � ∈ ℝ�×� has rank H, can decompose into

product of F × H and H × P matrices

�rank = H

=F

P

FP

H

H

Page 19: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Properties of Rank

• For �, � ∈ ℝ�×�1. rank � ≤ min F, P2. rank � = rank �3. rank �� ≤ min rank � , rank �4. rank � + � ≤ rank � + rank �

• � has full rank if rank � = min F, P• If F > rank � rows not linearly independent

– Same for columns if P > rank �

Page 20: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Outline

• Basic definitions

• Subspaces and Dimensionality

• Matrix functions: inverses and eigenvalue

decompositions

• Convex optimization

Page 21: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Matrix Inverse

• � ∈ ℝ�×� is invertible iff rank � = F• Inverse is unique and satisfies

1. �T�� = ��T� = &2. �T� T� = �3. � T� = �T� 4. If � is invertible then �� is invertible and

�� T� = �T��T�

Page 22: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Systems of Equations

• Given � ∈ ℝ�×�, � ∈ ℝ� wish to solve

�� = �– Exists only if � ∈ col �

• Possibly infinite number of solutions

• If � is invertible then � = �T��– Notational device, do not actually invert matrices

– Computationally, use solving routines like

Gaussian elimination

Page 23: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Systems of Equations

• What if � ∉ col � ?

• Find � that gives �V = �� closest to �– �V is projection of � onto col �– Also known as regression

• Assume rank � = P < F� = �� T����V = � �� T���

Invertible Projection

matrix

Page 24: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Systems of Equations

1 02 1

.5X2.5 = .5

X1.5X1 11 1

X1X.5 = .5

X1.5

Page 25: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Eigenvalue Decomposition

• Eigenvalue decomposition of symmetric � ∈ ℝ�×� is

� = YΣY =�[�\�\��

���– Σ = diag [�, … , [� contains eigenvalues of �– Y is orthogonal and contains eigenvectors \� of �

• If � is not symmetric but diagonalizable

� = YΣYT�– Σ is diagonal by possibly complex

– Y not necessarily orthogonal

Page 26: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Characterizations of Eigenvalues

• Traditional formulation

�� = [�– Leads to characteristic polynomial

det � X [& = 0• Rayleigh quotient (symmetric �)

max_���� ��

Page 27: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Eigenvalue Properties

• For � ∈ ℝ�×� with eigenvalues [�1. tr � = ∑ [�����2. det � = [�[�…[�3. rank � = #[� ≠ 0

• When � is symmetric

– Eigenvalue decomposition is singular value decomposition

– Eigenvectors for nonzero eigenvalues give orthogonal basis for row � = col �

Page 28: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Simple Eigenvalue Proof

• Why det � − [& = 0?

• Assume � is symmetric and full rank

1. � = YΣY2. � − [& = YΣY − [& = Y Σ − [& Y3. If [ = [�, *ab eigenvalue of � − [& is 0

4. Since det � − [& is product of eigenvalues,

one of the terms is 0, so product is 0

YY = &

Page 29: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Outline

• Basic definitions

• Subspaces and Dimensionality

• Matrix functions: inverses and eigenvalue

decompositions

• Convex optimization

Page 30: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Convex Optimization

• Find minimum of a function subject to solution constraints

• Business/economics/ game theory

– Resource allocation

– Optimal planning and strategies

• Statistics and Machine Learning

– All forms of regression and classification

– Unsupervised learning

• Control theory

– Keeping planes in the air!

Page 31: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Convex Sets

• A set # is convex if ∀�, � ∈ # and ∀B ∈ 0,1B� + 1 − B � ∈ #

– Line segment between points in # also lies in #• Ex

– Intersection of halfspaces

– 8d balls

– Intersection of convex sets

Page 32: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Convex Functions

• A real-valued function e is convex if dome is

convex and ∀�, � ∈ dome and ∀B ∈ 0,1e B� + 1 − B � ≤ Be � + 1 − B e �– Graph of e upper bounded by line segment

between points on graph

�, e �

�, e �

Page 33: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Gradients

• Differentiable convex e with dome = ℝ�• Gradient fe at � gives linear approximation

fe = geg�� … ge

g��

e

e � + hfe

Page 34: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Gradients

• Differentiable convex e with dome = ℝ�• Gradient fe at � gives linear approximation

fe = geg�� … ge

g��

e

e � + hfe

Page 35: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Gradient Descent

• To minimize emove down gradient

– But not too far!

– Optimum when fe = 0• Given e, learning rate B, starting point �i� = �iDo until fe = 0

� = � − Bfe

Page 36: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Stochastic Gradient Descent

• Many learning problems have extra structure

e j =�8 j; A��

���• Computing gradient requires iterating over all

points, can be too costly

• Instead, compute gradient at single training

example

Page 37: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Stochastic Gradient Descent

• Given e j = ∑ 8 j; A����� , learning rate B,

starting point jij = jiDo until e j nearly optimal

For * = 1toP in random order

j = j − Bf8 j; A�• Finds nearly optimal j

Page 38: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Minimize ∑ �� − jA� �����

Page 39: Linear Algebra Reviewsnap.stanford.edu/class/cs246-2014/slides/LinAlgSession.pdfMultiplication Properties • Associative ... • Business/economics/ game theory – Resource allocation

Learning Parameter