scieee AI-readable full text Open interactive document viewer

Review of linear algebra and applications to data science

Barceló Ordinas, José María,García Vidal, Jorge,Ferrer Cid, Pau

Full text

SANS-MIRI: Review of linear algebra and applications to data science Jorge Garcia Vidal, Jose M. Barcelo Ordinas and Pau Ferrer Cid July 17, 2023 The course SANS (Statistical Analysis of Networks and Systems) belongs to the Master MIRI (Master of Innovation and Research in Computer Science) of the Faculty of Computer Science of Barcelona. The course is an introduction to some mathematical foundations used in data science. The course content includes an introduction to probability, linear algebra, and estimation. These lecture notes of the course are devoted to linear algebra concepts applied to data science, and is divided into the following topics: 1. Basics in Linear Algebra: vector spaces, matrices and applications (linear equations and least squares equations); 2. Eigendecomposition of square matrices: eigenvectors and eigenvalues, positive definite matrices and the trace operator; 3. Quadratic forms. Multivariate Gaussian distribution; 4. Eigendecomposition of square matrices: singular value decomposition, pseudoinverses, matrix norms, Eckart-Young approximation (low-rank approximation of matrices); 5. Principal component analysis (PCA), the eigenfaces problem; 6. Fourier Transform and its applications; 7. Graph signal processing (GSP) and its applications. Linear Algebra is a classical topic, and there are many very good books covering the material that we need for our course at different levels of deep. Two books that we especially like are: ”Introduction to Linear Algebra” by Gilbert Strang, and ”Linear Algebra and Learning from Data” by Strang, Gilbert. Other books related to this course is ”Data-Driven Science and Engineering: Machine Learning, Dynamical Systems, and Control” by Steven L. Brunton and J. Nathan Kutz, or ” Introduction to Applied Linear Algebra – Vectors, Matrices, and Least Squares” by Stephen Boyd and Lieven Vandenberghe. 1 1 Some basic facts that you probably know about vectors and linear maps 1.1 Vector spaces and sub-spaces Let Vbe a set in which we have defined the addition operation and the multiplication by a scalar (in this course, the scalars will be usually real numbers). We say that Vis a vector space if the addition and scalar multiplication operations satisfy the following properties: ∀u, v, w∈V: •Associativity: u+ (v+w)=(u+v) + w, •Commutativity: u+v=v+u, •Additive identity: ∃0∈Vsuch that v+0=v, , •Existence of inverse: ∀v∈V, ∃−v∈Vsuch that v+ (−v) = 0. ∀a, b ∈Rand ∀u, v∈V: •Associativity of scalar multiplication: a(bv)=(ab)v, •Scalar multiplication identity: 1v=v, •Distributivity of scalar sums: (a+b)v=av+bv, •Distributivity of vector sums: a(u+v) = au+av. The elements of a vector space are called vectors. Some examples of vector spaces are: Example 1.1 (Coordinate space) The set of vectors x∈Rnwith coordinates x=(x1, ..., xn)and t∈Ris a vector space. Example 1.2 (Set of matrices) The set of matrices A∈Rm×nis a vector space over R, (addition of matrices and multiplication of scalar over matrices). Example 1.3 (Set of polynomials) The set of polynomials Pnover R(coefficients in R) and of order less or equal of nis a vector space. Example 1.4 (Set of continuous functions) The set of continuous functions f:Rn−→ R, where (f+g)(x) = f(x)+g(x) and (af)(x)=af(x) is a vector space. 2 If Sis a subset of V(S⊂V) which is closed respect the operations of sum of vectors (if u,v∈S, then u+v∈S), multiplication by an scalar (if u∈Sand a scalar then au∈S), and the zero vector is in S, we say that Sis a vector subspace of V. Some examples/non-examples of vector subspaces V are: Example 1.5 A line or a plane containing the origin is a vector subspace. Example 1.6 A line or a plane non containing the origin is not a vector subspace. Example 1.7 A quadrant is not a vector subspace (fails to be close under scalar multiplication). Example 1.8 A circle is not a vector subspace (fails to be close under scalar or vector multiplication and does not contain the zero). 1.2 Linear combinations and independence If we have a set of vectors {v1, ..., vk}, a linear combination of these vectors is an expression of the form v=Piaivifor some scalars ai. If we have a set of vectors belonging to a vector space, {v1, ..., vk}, the set of all linear combinations of these vectors is a vector subspace. This subspace is called: span{v1, ..., vk}={ k X j=1 βjvj;with βj∈R}(1.2.1) One vector wis linearly independent of a set of vectors {v1, ..., vk}when wcannot be expressed as linear combination of the vectors {v1, ..., vk}, or in other words, when w/∈span{v1, ..., vk}. A set of vectors {v1, ..., vk}are linearly independent when the only linear combination that produces the vector 0is the one with all coefficients equal to zero. Summarizing, let us assume that Pk j=1 ajvj= 0; if some aj=0 then the vectors are linearly dependent (l.d.), while if all aj=0 then the vectors are linearly independent (l.i.). 1.3 Bases and dimension There are many examples of vector spaces: Rn,Cn, or Pn(R), the set of polynomials of ndegree with real coefficients. These spaces are examples of finite dimensional vector spaces. This means that there is a set of linearly independent vectors of V,{ui}i=1,...,n (a base of V) such that all other vectors of V can be expressed as v=Pn i=1 viui. A vector space has in general an infinite 3 number of possible bases, but the number of elements in each of those basis is always the same. We say that this number nthe dimension of V, dim(V) = n. Moreover, we can use these coefficients to represent vas a column vector: v= [v1, v2, ..., vn]⊤=     v1 v2 . . . vn      (1.3.1) The same definitions apply to vector subspaces. Some vector spaces have infinite dimensions, for instance, P∞(R), the set of polynomials of an arbitrary order, C[0,1], the set of continuous functions defined on the interval [0,1], or L2[0,1], the set of square integrable functions ffor which R1 0|f|2dµ < ∞. In this course, we will deal with the finite dimensional case only. The infinite dimensional case is studied in functional analysis, and is important, for instance, when dealing with stochastic processes. 1.4 Scalar product, orthogonality, and vector norms The scalar product is an operation that takes two vectors u,v∈Vand returns a scalar; i.e., ⟨·,·⟩:V×V−→ R. For this operation to qualify as a scalar product, it must fulfill the following properties: •commutative: ⟨u,v⟩=⟨v,u⟩, •distributive: ⟨u,v+w⟩=⟨u,v⟩+⟨u,w⟩, •linearity in any argument: ⟨au,v⟩=⟨u, av⟩=a⟨u,v⟩, •positive definiteness: if u= 0, then ⟨u,u⟩>0. The most commonly used definition of the scalar product for two column vectors uand vis: ⟨u,v⟩=u⊤v.(1.4.1) Note, however, that we can define other scalar products. For instance, if Sis a symmetric positive definite matrix (see section 2.6), we can define a scalar product as: ⟨u,v⟩=u⊤Sv.(1.4.2) Another important example is the scalar product of two square matrices Aand Bdefined as (see section 3.3 for the definition of trace): ⟨A,B⟩=tr(A⊤B).(1.4.3) 4 A very important property of the scalar product is the Cauchy-Schwarz inequality: |⟨u,v⟩|2≤ ⟨u,u⟩ ⟨v,v⟩.(1.4.4) We have equality only when u=avfor some scalar a. A simple proof of this important fact is the following: consider an arbitrary scalar aand two non-zero vectors u,v. Assume first that there is no scalar afor which au=v. Then, the positive-definiteness property of the scalar product implies that for any a: 0<⟨au−v, au−v⟩=⟨u,u⟩a2−2⟨u,v⟩a+⟨v,v⟩.(1.4.5) But this second-degree polynomial on ais always non-negative for all aonly when: 4(⟨u,v⟩)2−4⟨u,u⟩⟨v,v⟩<0,(1.4.6) and from this, we arrive at the strict Cauchy-Schwarz inequality. Assume now that there is a scalar a∗for which a∗u=v. In this case, we have 0≤ ⟨au−v, au−v⟩=⟨u,u⟩a2−2⟨u,v⟩a+⟨v,v⟩.(1.4.7) with equality for a=a∗. This means that the second-degree polynomial in a has a double root at a∗, which is only possible if: 4(⟨u,v⟩)2−4⟨u,u⟩⟨v,v⟩= 0,(1.4.8) and from this, we arrive at the equality case of Cauchy-Schwarz inequality when vis colinear with u. We can define the angle αbetween two non-zero vectors u,vas: cos(α) = ⟨u,v⟩ p⟨u,u⟩ ⟨v,v⟩.(1.4.9) Two non-zero vectors are orthogonal when its scalar product is zero: ⟨u,v⟩= 0.(1.4.10) Thus, the angle between two orthogonal vectors is α= 90◦. Anorm is a function ∥·∥:Rn−→ R, such that for each vector v∈Rn, the following conditions are satisfied: •∥·∥is non-negative, ∥v∥ ≥ 0 •∥·∥is definite, ∥v∥= 0 iif v= 0, 5 •∥·∥is homogeneous ∥(av)∥=|a|∥v∥with ascalar, •∥ · ∥ satisfies the triangle inequality (subadditivity property) ∥u+v∥ ≤ ∥u∥+∥v∥. The Euclidean norm or also called L2-norm represents the length of a vector v, and is defined as the non-negative number: ∥v∥= +p⟨v,v⟩(1.4.11) Other well-known norms are represented by a subscript ∥·∥p, where p∈R+(R+ means any real number ≥0). Examples of useful norms are: •∥v∥0(zero-norm or L0-norm) defined as the number of non-zero coordinates of vector v(or also as the Hamming distance of the vector from zero), •∥v∥1(Taxicab norm or Manhattan norm or sum-absolute norm) defined as ∥v∥1=Pn i=1 |vi|, •∥v∥2(Euclidean norm or L2-norm) defined as ∥v∥2=pPn i=1 |vi|2= √v⊤v, •∥v∥p(Lp-norm) defined as ∥v∥p= (Pn i=1 |vi|p)1/p, •∥v∥∞(maximum norm or infinity norm or Chebyshev norm) defined as ∥v∥∞=maxi=1...n{|vi|}. Example 1.9 (vector norms) Let us assume vector v=[1,0,0,4,2,-3]. Then, ∥v∥0= 4,∥v∥1= 10,∥v∥2=√30 = 5.477,∥v∥3.2= 4.558 and ∥v∥∞= 4 The Cauchy-Schwarz inequality for the Euclidean norm reads: |u⊤v|≤∥u∥ ∥v∥(1.4.12) Let us define the unit circle or unit ball as the set of all vectors vof norm 1 (∥v∥p= 1). Then plot, as an exercise, the unit circle for norms ∥v∥0,∥v∥1, ∥v∥2,∥v∥∞, and ∥v∥pfor any p. 1.5 Linear maps and matrices Alinear map Lis an application L:V→W, where V(domain) and W(codomain) are vector spaces, that satisfies ∀u,v∈V, and ∀a, b∈R: L(u+v) = L(u) + L(v)and L(au) = aL(u),(1.5.1) 6 or (identical definition) L(au+bv) = aL(u) + bL(v).(1.5.2) For example; L(x1,x2)=(x1+x2,x1,x2+1) is not a linear map, as it fails in the condition L(au) = aL(u). A linear map always transforms 0to 0, i.e., L(0) = 0. Assume that {vi}i=1,...,n is a base of a ndimensional space V, while {wi}i=1,...,m is a base of a mdimensional space W. The image of the uibase vector by the linear map L, i.e. L(ui), is a vector of W, that we can express in the base {wi}i=1,...,m: L(ui) = a1iw1+a2iw2+... +amiwm(1.5.3) An m×nmatrix Ais an arrangement of these numbers aij into an m×narray A= [aij]. For an arbitrary vector v, expressed as a column vector in the base {vi}i=1,...,n, the product Avgives a result the vector w, which is the image of the vector vby the linear map Lexpressed in the base {wi}i=1,...,m. This is a bit confusing at first. Let’s think on the following example: {1, x, x2} is a possible base of P2(R). Using this base, we can represent the polynomial p(x) = a+bx +cx2by the R3vector p= [a, b, c]⊤. Let us define the linear map d dx :P2(R)→P2(R) that assigns to a polynomial p(x) its derivative (another polynomial). If we represent the polynomials in the image and domain sets by the same base {1, x, x2}, we can thus represent this linear map by the matrix: D=  010 002 000 .(1.5.4) Usually, we will use matrices to represent linear maps. Very often, we express a matrix Aas an arrangement of its columns (or its rows) considered vectors. For instance if A= [aij] and let us define the ncolumn vectors ai= [ai1, ..., aim]⊤ for i= 1, ..., n. We can write the matrix as: A= [a1, ..., an] (1.5.5) Similarly, we can write Ausing its row vectors ri⊤= [a1i, ..., ani]: A=   —r1⊤— . . . —rm⊤—   .(1.5.6) If we have a matrix Aand a column vector v= [v1, ..., vn]⊤, we can express its matrix times vector product as w=Av= [a1, ..., an]   v1 . . . vn   =X i=1,..,n viai,(1.5.7) 7 which is saying that the image vector wis a linear combination of the column vectors ai. 1.6 Rank of a matrix The image fof all vectors of a subspace Sof Vby means of a matrix Ais also a subspace Tof W;f:S⊂V→T⊂W. In the special case when the subspace Sis Vitself, the generated subspace is span{a1, ..., an}. The dimension of this subspace is the rank of the matrix A, rank(A), and it is the number of linearly independent columns. Very surprisingly, this number is also the number of linearly independent rows of the matrix A, meaning that Aand A⊤have the same rank. In terms of rows and columns of a matrix A∈Rm×nand matrix A⊤∈Rn×m, we can state the actions of an m×nmatrix remembering that matrix Acan be expressed as column vectors {a1, ..., an}or matrix Acan be expressed as row vectors {r1⊤, ..., rm⊤}. In the same way matrix A⊤can be expressed as column vectors {r1, ..., rm}or matrix A⊤can be expressed as row vectors {a1⊤, ..., an⊤}. For any matrix, we can associate several subspaces: the null space (NS), the column space (CS), the row space (RS), and the left null space (LNS). Let us define the Range(A) or Im(A)=Image(A) as the image of the linear transformation f:Rn⊂V→Rm⊂W: Im(A) = Range(A) = {y∈Rm|y=Ax for some x∈Rn}(1.6.1) and we can observe, Range(A)= Im(A) is a subspace of Rm. The Im(A⊤) is defined in a similar way and is a subspace of Rn. Im(A⊤) = Range(A⊤) = {x∈Rn|x=A⊤yfor some y∈Rm}(1.6.2) and, Range(A⊤)= Im(A⊤) is a subspace of Rn. Define the column space of A, CS(A), as the linear combination of its columns: CS(A)={w∈Rm,w=c1a1+···+cnan}, where ai∈Rm. The CS(A) is then a subspace of Rm. The CS(A) is the Range(A) or Im(A) of the linear transformation f:Rn⊂V→Rm⊂W. In a similar way, we define the row space of A, RS(A), as the linear combination of its rows: RS(A)= {v∈Rn,w=d1r1+··· +dnrm}, where ri∈Rn. The RS(A) is then a subspace of Rn, and then it is the Range(A⊤) or Im(A⊤). We know that dim(RS(A))= rank(A) and that dim(CS(A))= rank(A), which makes dim(RS(A))=dim(CS(A))= rank(A). Since the columns of Aare the rows of A⊤, finding a basis for CS(A) is equivalent to finding a basis for RS(A⊤). 8 The null space NS(A) or Ker(f) is defined as: NS(A) = {x∈Rn|Ax = 0}(1.6.3) and we can observe that NS(A) is a subspace of Rn. The NS(A⊤) (also called the Left Null Space of A, LNS(A) or the CoKer(f)) is defined in a similar way and is a subspace of Rm. LNS(A) = NS(A⊤) = {y∈Rm|A⊤y= 0}={y∈Rm|y⊤A= 0}(1.6.4) If A=[a1, ..., an] is a column partitioning, and rank(A)=span{a1, ..., an}. Now, since the rank(A) is the dimension of the image; rank(A)= dim(Range(A))= dim(Im(A))=dim(CS(A)), and we know that rank(A)=rank(A⊤). We say that the matrix A∈Rm×nis rank deficient if rank(A)<min{m,n}, and therefore: dim(RS(A)) + dim(NS(A)) = rank(A) + dim(NS(A)) = n(1.6.5) We can state that RS(A)= Im(A⊤)⊂Rn⊥NS(A)⊂Rn. On the other hand, in terms of the CS and LNS: CS(A) = Im(A)⊂Rm⊥LNS(A) = NS(A⊤)⊂Rm(1.6.6) and dim(CS(A)) + dim(LNS(A)) = rank(A) + dim(LNS(A)) = m(1.6.7) You can see this in the following way: A⊤y=0 (or y⊤A=0), so rows of A⊤ multiplied by vectors yin the null space are equal to 0 (or vectors yof the left null space multiplied by columns of Aare equal to 0), so they are orthogonal. Example 1.10 (Row space, column space, null space and left null space) Let’s see an example of a matrix A∈Rm×n, with m=3 and n=4: A=  2111 3002 1360  The rank of this matrix is r=3. It has 3 row vectors; r⊤ 1= [2,1,2,1],r⊤ 2= [3,0,0,2] and r⊤ 3= [1,3,6,0]. They form a basis of the row space that is a subspace of Rn=R4. The null space has 1 vector with basis rns = [−2/3,4/9,−1/9,1]. Now, vectors r1,r1,r1and rns form a basis of the space Rn=R4. Matrix Ahas 4 column vectors; a⊤ 1= [2,3,1],a⊤ 2= [1,0,3],a⊤ 3= [1,0,6] and a⊤ 4= [1,2,0]. vectors a2and a3are linear dependent, thus, vectors a1,a2and a4form a basis of the column space that is a subspace of Rm=R3, and the left null space only contains vector alns = [0,0,0]. 1.7 Applications Let us see some applications where these concepts appear. 9 •We define a projection as a linear operator P:V→Vsuch that P2=P. If the vector space Vis finite-dimensional, a square matrix Pis called projection matrix if P2=P. Moreover, if Pis real, and P2=P=P⊤then Pis called a orthogonal projection matrix. For the general case of a non-unitary vector v, the projection matrix is defined as: P=v<v,v>−1v⊤(2.2.1) so the projection of a vector ton the vector v, would be given by: ˆ t=P t =v<v,v>−1v⊤t(2.2.2) Example 2.1 (Projection matrix for a vector) We want to project vector t=[1,2] over vector v=[2,1]. We first obtain the projection matrix P: P=1 ∥v∥2 2 vv⊤=1 52 12 1=1 54 2 2 1 Then, now, the projection of vector ton the vector v, would be given by: ˆ t=P t =1 54 2 2 11 2=1 56 4=1.2 0.8 and the projected vector will be ˆ t= [1.2,0.8]. We can observe that the matrix Psatisfies property P2=P=P⊤: P2=1 54 2 2 11 54 2 2 1=1 25 20 10 10 5 =1 54 2 2 1 Finally, observe that since we project a vector over a vector, matrix Phas rank r= 1. In the special case in which vis unitary, <v,v>=1, and P=vv⊤. The projection of vector ton the unitary vector vwill then be ˆ t=P t =vv⊤t. In the case that the we want to project a vector ton a subspace generated by the matrix A, then the projection matrix will be given by: P=A(A⊤A)−1A⊤(2.2.3) and the projection of the vector ton the subspace generated by the matrix Awill be given by: ˆ t=A(A⊤A)−1A⊤t(2.2.4) Example 2.2 (Projection matrix for a matrix) We want to project vector t=[1,2] over the space generated by matrix: A=  2 1 1 3 0 1  16 The projection matrix Pwill be given P=A(A⊤A)−1A⊤: P=  2 1 1 3 0 1 (210 131  2 1 1 3 0 1 )−1210 131=1 30   29 2 −5 2 26 10 −5 10 5   and we can observe that matrix Phas rank r= 2 (the same as matrix A). 2.3 An n×mmatrix of rank rmaps a sphere of dimension ninto an ellipsoid of dimension r A basic fact of linear algebra is the following: Assume that we have an n×m matrix Awith rank(A)=r. Assume that we compute the products y=Ax, where xis an n-dimensional vector that lies in a sphere of radius 1 in the space Rn. Then the locus (set of points) of all the generated vector ylies in an ellipsoid of dimension rembedded in the space Rm. As an example, assume a 2×2 matrix Aof rank 2. If we compute y=Ax for x= (cos(θ), sin(θ))⊤with θ∈[0,2π), the vector ywill lie in an ellipsoid centered in the origin in R2. If rank(A)=1, the ellipsoid will collapse one of its dimensions, resulting in a segment that crosses the origin. 2.4 Matrix factorization In this course, we deal with two important matrix factorizations: •S=QΛQ⊤, for symmetric matrices. •A=UΣV⊤, Singular Value Decomposition (SVD) for general matrices. We are interested in the first factorization as covariance matrices are symmetric, and we are interested in the second factorization as it allows us to approximate clouds of points in high-dimensional spaces by clouds of points in lower dimensional spaces. 2.5 Diagonalization of symmetric matrices Assume that Sis an n×nsymmetric matrix, i.e. S=S⊤, i.e., aij =aji ∀i, j. Symmetric matrices have the following properties: i) S1+S2(sum) is symmetric if S1,S2are symmetric, ii) S1S2(product) is not necessarily symmetric even if S1,S2are symmetric, iii) if S−1exists, is symmetric if and only if S1is symmetric. The spectral theorem tells us when a linear operator or matrix can be diagonalized. In the case of S(symmetric matrix), the finite-dimensional spectral 17 theorem says that any symmetric matrix Swhose entries are real can be diagonalized by an orthogonal matrix (so, the eigenvectors are orthonormal). •Shas nreal eigenvalues, λi, (counting possible multiplicities) •The nassociated eigenvectors, qiare orthonormal. •These matrices are not defective (defective means that rank(A)=r<n, then rank(S)=n) if they are positive definite. Let us prove it for the case in which the matrix has non-repeated eigenvalues. This result can be extended for the repeated eigenvalues case by using continuity arguments. 2.5.1 Eigenvectors are orthogonal Assume that Sv =λvand Su =µudifferent eigenvalues λand µ. We have: v⊤Su =µv⊤u(2.5.1) and u⊤Sv =λu⊤v(2.5.2) but u⊤Sv =v⊤S⊤u=v⊤Su as Sis symmetric, and u⊤v=λv⊤u, which implies λu⊤v=µu⊤v, and from this we get u⊤v= 0 (eigenvectors are orthogonal). 2.5.2 Eigenvalues are real Assume that λis a complex eigenvalue. As Sis real, λ∗(i.e. its complex conjugate) must also be an eigenvalue: Sv =λv(2.5.3) and: Sv∗=λ∗v∗(2.5.4) Then we have: v∗TSv =λv∗Tv=λ(2.5.5) since eigenvectors vare orthonormal (v∗v= 1), and: vTSv∗=λ∗vTv∗=λ∗(2.5.6) 18 But λ∗=vTSv∗= (vTSv∗)⊤=v∗TSv =λ, meaning λ=λ∗. As a consequence, we can write Sas: S=QΛQ⊤, where Qis an n×nmatrix with columns the eigenvectors of S,Q=[q1,. . . ,qn], and Λ is a diagonal matrix with diagonal elements Λi,i =λi. An alternative way of expressing this is by the formula: S=Piλiqiqit. Recall that the terms qiqitare rank 1 matrices. If rank(S)=n, the eigenvalues λimust be different from 0 (if not, the correspondent eigenvector qiwould belong to the null space and rank(S)<n). In this case, Shas an inverse, which is also a symmetric matrix, and: S−1=QΛ−1Q⊤= Pi1 λiqiqi⊤. Example 2.3 (Symmetric matrices) Let us assume the following symmetric matrix A: A=    2101 1345 0414 1544     Then the eigendecomposition of matrix Awill A=QΛQ⊤, with: Q=    −0.128 −0.978 −0.155 −0.051 −0.596 0.021 0.553 −0.582 −0.463 0.204 −0.812 −0.29 −0.643 0.028 0.103 0.758     and Λ=    11.712 0.0 0.0 0.0 0.0 1.95 0.0 0.0 0.0 0.0−2.228 0.0 0.0 0.0 0.0−1.434     and as we can observe, all eigenvalues are real, and the eigenvectors are othornormal; q⊤ iqi= 1 and q⊤ iqj= 0 with i=j, e.g. q⊤ 0q0=[−0.128,−0.596, −0.463,−0.643]⊤[−0.128,−0.596,−0.463,−0.643]=1.0and q⊤ 0q2=[−0.128, −0.596,−0.463,−0.643]⊤[−0.155,0.553,−0.812,0.103]=0.0. Observe also that the matrix Qis a rotation matrix; for example Qqi=[0,. . . , 1,. . . ,0], a unitary vector with a 1at position i,0’s in the remainder. 2.6 Positive definite matrices When all eigenvalues Sare positive, we say that the symmetric matrix is positive definite. In this case, S−1is also a symmetric positive definite matrix. These matrices somehow play the role of positive numbers in the matrix world. 19 For example, the variance-covariance matrix Σ=E[(X1, .., Xn)(X1, ..., Xn)⊤] of multivariate Gaussian distributions is a positive definite matrix. The inverse of the covariance matrix, called precision matrix is also positive definite. •An n×nsymmetric real matrix Ais said to be positive definite if x⊤Ax>0 (2.6.1) for all non-zero vectors x∈Rnand it is said negative definite if x⊤Ax<0.(2.6.2) •An n×nsymmetric real matrix Ais said to be positive semi-definite if x⊤Ax≥0 (2.6.3) x⊤Ax≥0 for all non-zero vectors x∈Rnand it is said negative semidefinite if x⊤Ax≤0 (2.6.4) •An n×nsymmetric real matrix which is neither positive semi-definite nor negative semi-definite is called indefinite. •A matrix Ais positive (negative) definite if and only if all of its eigenvalues are >0 (<0). •A matrix Ais positive (negative) semi-definite if and only if all of its eigenvalues are ≥0 (≤0). You can find several interesting properties such as: i) if Aand Bare positive definite matrices, then the sum A+Bis a positive definite matrix; or ii) if A is a positive definite matrix, then the inverse A−1is a positive definite matrix. Finally, an interesting result is the following: let be a m×nAmatrix. The matrix S=A⊤Ais positive definite (and then symmetric), and therefore Shas orthonormal eigenvectors and positive eigenvalues. Example 2.4 (Positive definite matrices) Let us consider matrices A,B, Cand D. Check positive definiteness. A= −1 1 −1 101 011 ;B= −3 0 −1 0−5−2 −1−2−3  C=  3 1 −1 0 4 −2 −1−2 3  ;D=  3 1 −1 0 4 −2 3 4 −3  20 Let us obtain the eigenvalues. The eigenvalues of matrix Aare λ=[−1.879, 0.347,1.532]. The matrix is neither positive or negative definite. The eigenvalues of matrix Bare λ=[−1.319,−3.358,−6.323] are all negative, and then the matrix is negative definite. The eigenvalues of matrix Care λ=[1.097,3.194, 5.709] are all positive, and then the matrix is positive definite. The eigenvalues of matrix Dare λ=[0.0,0.586,3.414] are all positive or equal to zero, and then the matrix is positive semidefinite. Moreover, since there are one eigenvalue equal to zero, the rank of this matrix is 2. On the other hand, the rank of matrices A,B,Cis 3. 3 Useful properties of matrices 3.1 Geometric interpretation for symmetric matrices: Rotation/Reflection, Stretching, Rotation/Reflection−1 Figure 3: Symmetric matrix applied to a disc of radius 1. We know that matrix multiplication can be interpreted as linear map composition, meaning that the geometric interpretation of Sv=QΛQ⊤vfor an arbitrary vector vis: •Rotate the coordinate system to align it with the set of vectors qiwhich form the columns of the matrix Q. The vector vin this new coordinate system has the expression Q⊤v(note that the vectors qiexpressed in the 21 new coordinate system have the expression Q⊤qi= [0, ..., 1, ...0] as we expect). •Stretch each component of the resulting vector Q⊤vaccording with the diagonal elements of the matrix Λ, obtaining the vector ΛQ⊤v. This stretching causes in general a change of direction of the vector, but if vis aligned with a vector qi, it does not change its direction. •Apply the inverse rotation to the coordinate system. If we express the resulting ΛQ⊤vin this new coordinate system we obtain QΛQ⊤v. For instance, a positive definite matrix Swill map an n-dimensional sphere of radius 1 to an n-dimensional ellipsoid with axis given by its eigenvectors qi, and axis lengths given by its eigenvalues λi, (think on this, Figure 3). 3.2 Derivatives with vectors and matrices First, some matrix manipulations typically appear when working with differentiation. •(AB)−1=B−1A−1 •(AB)⊤=B⊤A⊤ •(a⊤Ab)⊤=b⊤A⊤a •a⊤b=b⊤a •(A+B)C=AC +BC •AB =BA •a⊤b=b⊤a •(a+b)⊤C=a⊤C+b⊤C The Hadamard product (also known as the element-wise product, entry-wise product, or Schur product) returns a matrix of the multiplied corresponding elements. It is defined with the symbol ⊙(sometimes also with symbol ◦): (A◦B)ij = (A⊙B)ij = (A)ij(B)ij.(3.2.1) Example 3.1 (Hadamard product of matrices) Consider matrices Aand B. A=  2 1 −2 1 0 2 0 1 3  ;B= −3 0 −1 2−5−2 −1 2 4   22 Its Hadamard product is given by: A⊙B=  2 1 −2 1 0 2 0 1 3  ⊙ −3 0 −1 2−5−2 −1 2 4  = −6 0 2 2 0 −4 0 2 12  Let us assume vector xand we want to obtain vector derivatives over the function f(x) of the form df(x)/dx. We use the denominator layout (meaning that f⊤and x) •f(x) = x⊤a−→ df(x)/dx=a •f(x) = x⊤A−→ df(x)/dx=A •f(x) = Ax −→ df(x)/dx=A⊤ •f(x) = x⊤x−→ df(x)/dx= 2x •f(x) = x⊤Ax −→ df(x)/dx= 2Ax if Ais symmetric •f(x) = x⊤Ax −→ df(x)/dx= (A+A⊤)x 3.3 The trace operator For a square matrix n×n A we define the trace as the sum of the elements of its diagonal: tr(A) = n X k=1 akk =a11 +a22 +···+ann (3.3.1) The trace of the n×n I identity matrix is the dimension of the space, namely n: tr (In) = n. The following relationships are satisfied: tr(A+B) = tr(A) + tr(B) tr(cA) = ctr(A)(3.3.2) for all square matrices A and B, and all scalars c. Moreover: tr(A) = tr AT(3.3.3) 3.3.1 The trace of a matrix is the sum of its eigenvalues counting multiplicities As we know, the eigenvalues λkare the solutions of the equation: det(A−λI) = (−1)nλn+ (−1)n−1tr(A)λn−1+... = 0 (3.3.4) 23 The eigenvalues λkare the roots of the polynomial in λ, meaning that we have: (−1)n(λ−λ1)(λ−λ2)... = 0 (3.3.5) and from this we obtain: X k λk=tr(A) (3.3.6) Example 3.2 (Symmetric matrices) Let us assume the following symmetric matrix A: A=    2101 1345 0414 1544     The eigenvalues are λ=[11.712,2.228,1.95,1.434]. We can observe that Piλi= 11.712 + 1.95 + (−2.228) + (−1.434)=10.0and that tr(A) = 2 + 3 + 1 + 4 = 10 3.3.2 The trace operator is cyclic Let Aand Bbe general non-square matrices of sizes n×mand m×n. The diagonal elements of P=AB can be found as: pkk =X i=1,...,m akibik (3.3.7) while that for Q=BA we have: qii =X k=1,...,n aikbki (3.3.8) We have then tr(AB) = X k=1,..,n X i=1,...,m akibik =X i=1,..,m X k=1,...,n akibik =tr(BA) (3.3.9) If we have now three arbitrary matrices of the right sizes to produce a square matrix in its product BAC we have: tr(BAC) = tr((BA)C) = tr(C(BA)) = tr(CBA) (3.3.10) Moreover for real column vectors a∈Rnand b∈Rn, the trace of the outer product is equivalent to the inner product: tr baT=aTb(3.3.11) 24 3.3.3 Derivatives of a trace Let A∈Rn×mand X∈Rm×nmatrices. Then: d dXtr(AX) = d dXtr(XA) = A⊤(3.3.12) Moreover, if A,X∈Rn×m: d dXtr(AX⊤) = d dXtr(X⊤A) = A(3.3.13) Then, assuming correct matrices sizes A,B,X: d dXtr(AXB) = d dXtr(BAX) = (BA)⊤(3.3.14) On the other hand, for deriving (X⊤AX) with respect to X, we first fix one of the Xand then the other (e.g. fix one Xand substitute the other Xby Y and derive with respect Y, and then repeat exchanging the order): d dXtr(X⊤AX) = d dYtr(Y⊤AX)+ d dYtr(XAY ) = (A+A⊤)X(3.3.15) Using these rules, we can obtain the derivative of more complex trace expressions. 3.4 Quadratic forms, sub-level sets, paraboloids and ellipsoids A quadratic function has the form of f(x) = 1 2x⊤P x +b⊤x+c(3.4.1) where Pis a n×nsymmetric matrix, band xare n-dim vectors, and c is a real number. Define now a αsub-level set Cαof a function f:Rn→R, as Cα={x∈dom{f}|f(x)≤α}(3.4.2) Let us now remember the equation of an n-dim ellipsoid as x2 1 a2 1 +x2 2 a2 2 +···+x2 n a2 n = 1 Thus, we can see that the αsub-level set of a quadratic form is an ellipsoid. In fact, ϵ={x|(x−xc)⊤P−1(x−xc)≤1}(3.4.3) 25 •The left eigenvectors u1,...,urwith ui∈Rmare the orthonormal basis of the Image(A)= CS(A); •The left eigenvectors ur+1,...,umwith ui∈Rmare the orthonormal basis of the Left Null Space LNS(A)= NS(A⊤); U= [Ur|˜ Um−r] = [u1,...,ur | {z } Ur ,ur+1,...,um | {z } ˜ Ur ] (4.3.1) •The right eigenvectors v1,...,vrwith vi∈Rnare the orthonormal basis of the row space RS(A); •The right eigenvectors vr+1,...,vnwith vi∈Rnare the orthonormal basis of the null space NS(A); V= [Vr|˜ Vn−r]=[v1,...,vr | {z } Vr ,vr+1,...,vn | {z } ˜ Vr ] (4.3.2) We first assume symmetric matrix A⊤A∈Rn×n, and its eigenvalue decomposition (obtain its eigenvalues and eigenvectors since it is a squared n×nmatrix): A⊤A=V DV ⊤, where Dis a diagonal matrix with eigenvalues λiarranged in nonincreasing order (λ1≥λ2≥ ··· ≥ 0), and the columns of V(eigenvectors of A⊤A) are the orthonormal vectors {v1,...,vn}. We can observe that vectors {v1,...,vn}form a basis of Rn. Moreover, since our matrix Ahas rank(A)=r, the right singular vectors associated with non-zero singular values (there are r of them) form a basis of RS(A), while the n-rright singular vectors associated with the zero n-rsingular values form a basis of the NS(A). Remember that the Im(A) = Range(A) = {y∈Rm|y=Ax for some x∈Rn}, and then: Avi·Avj= (Avi)⊤·Avj=vi⊤(A⊤Avj) = vi⊤(λjvj) = λjvi⊤vj= 0 (4.3.3) since viand vjare orthonormal. Then Aviand Avjalso are orthogonal (not necessarily orthonormal). Then the eigenvectors of A⊤Aand their images under Aform a basis for the range or image of A(or the column space CS(A)). We must check now that the vectors ukdefined as Avk=σkukare also orthonormal: u⊤ iuj=1 σiσj v⊤ iA⊤Avj=σ2 j σiσj v⊤ ivj= 0, i =j(4.3.4) In order to complete the orthonormal bases of the range, we have to normalize, thus: ui=Avi |Avi|=Avi √λi =Avi σi ; 1 ≤i≤r(4.3.5) 32 and defining σ2 i=λi, we obtain Avi=σiui, with 1 ≤i≤r, which shows that AV =UΣtaking uithe columns of Uand vithe columns of Vand Σii =σi. Finally, we can express the matrix Aas: A= [Ur,˜ Ur]Σr0 0 0  Vr ˜ Vr(4.3.6) The dimensions of the matrices are Ur∈Rm×r,˜ Ur∈Rm×(m−r),Vr∈Rn×r, and ˜ Vr∈Rn×(n−r). Observe that the following conditions are satisfied: U⊤ rUr=Ir˜ U⊤ r˜ Ur=Im−rU⊤ r˜ Ur=0U⊤ rUr+˜ U⊤ r˜ Ur=Im V⊤ rVr=Ir˜ V⊤ r˜ Vr=In−rV⊤ r˜ Vr=0V⊤ rVr+˜ V⊤ r˜ Vr=In (4.3.7) Example 4.1 (SVD example) Let’s calculate the SVD for matrix A∈R3×2: A=  2 1 3 0 1 3 = −0.531 −0.113 −0.839 −0.595 −0.654 0.466 −0.602 0.748 0.279    4.169 0 0 2.572 0 0  −0.560 0.828 0.828 0.56  where we have used the full matrix decomposition; A=UΣV⊤. If we consider the SVD with rank r=2, we can use the economy SVD A=UrΣrV⊤ r: A=  2 1 3 0 1 3 = −0.531 −0.113 −0.595 −0.654 −0.602 0.748  4.169 0 0 2.572−0.560 0.828 0.828 0.56  It can be easily seen that u⊤ iui= 1 and u⊤ iuj= 0 with i=j, e.g. u⊤ 0u0= [−0.531,−0.595,−0.602]⊤[−0.531,−0.595,−0.602] = 1.0and u⊤ 0u1=[−0.531, −0.595,−0.602]⊤[−0.113,−0.654,0.748]=0.0. 4.4 Geometric interpretation Remember that we have a function f:Rn→Rmassociated to matrix A∈Rm×n. What happens if we apply matrix Ato a unit sphere Rn(we assume m≤n) ? Let us assume that x∈Rnare the vectors in the unit sphere. Remembering that when we apply an orthonormal matrix to a vector we rotate the vector, then: Ax =UΣV⊤x(4.4.1) which means that we first apply a rotation V⊤to vectors x(still in Rn), then we stretch or shrink in each direction (since we multiply vectors by singular values larger or than 0), producing an ellipsoid in Rm, and finally we rotate again using Uin Rm. In other words, we produce a linear mapping in which a sphere in Rnis converted to an ellipsoid in Rm(make some figures showing the geometric interpretation). 33 4.5 SVD, pseudo-inverse and projection matrices Let us consider a linear system of equations: Ax=y(4.5.1) where A∈Rm×n,x∈Rnand y∈Rm. If m=nwe have a two-sided inverse of matrix A, i.e., AA−1=A−1A=I, that is what we call inverse of Aif the nullspace(A) and nullspace(A⊤) only contain the zero vector. Let us consider the case in which the rank(A)=r=n, and then the nullspace(A) only contains the zero vector. In this case m>n (overdetermined case) in which case we can not produce an inverse. However, A⊤Ahas inverse since it is a symmetric n×nmatrix. From here and the SVD we can deduce what is called the left pseudo-inverse: A−1 left =A†= (A⊤A)−1A⊤(4.5.2) Deduction: Ax =y→A⊤Ax =A⊤y(4.5.3) We can observe that: A⊤A=VΣ⊤ΣV⊤, and: VΣ⊤ΣV⊤x=A⊤y→x=V(Σ⊤Σ)−1V⊤A⊤y(4.5.4) since (A⊤A)−1=V(Σ⊤Σ)−1V⊤, we conclude that: x= (A⊤A)−1A⊤y=A−1 lefty(4.5.5) Note that A−1 leftA=Inand that AA−1 left only is Inif n=m. As a statement, a non-symmetric matrix can not have a two-sided since Aor A⊤has null-space different of the zero vector. In the same way, let us consider the case in which the rank(A)=r=m, and then the nullspace(A⊤) only contains the zero vector. In this case m<n (underdetermined case) in which case we can not produce an inverse. However, AA⊤ has inverse since it is a symmetric n×nmatrix. From here and the SVD we can deduce what is called the right pseudo-inverse: A−1 right =A†=A⊤(AA⊤)−1(4.5.6) Note that AA−1 right =Imand that A−1 rightAonly is Imif n=m. As a statement, a non-symmetric matrix can not have a two-sided since Aor A⊤has null-space different of the zero vector. Finally, If Ais full column rank (r=n), and A−1 left = (A⊤A)−1A⊤, then matrix P=AA−1 left =A(A⊤A)−1A⊤(4.5.7) 34 projects Rminto the column space of A. In a similar way, If Ais full row rank (r=m), and A−1 right =A⊤(A⊤A)−1, then matrix P=A−1 rightA=A⊤(A⊤A)−1A(4.5.8) projects Rninto the row space of A. What is the pseudo-inverse in terms of the SVD? The pseudo-inverse is a matrix that satisfies that x=AA†x. In other words: UΣV⊤A†=I, and remembering that matrices Uand Vare othornormal (and easy to invert), then A†=U⊤Σ†V. The best approximation of Σ†is a matrix with diagonal values for i= 1, . . . , r for the first r rows (or columns), with rthe rank of Aand the rest of diagonal values are zero. Example 4.2 (Pseudo-inverse using the SVD) Remembering example 1.12, we obtained the pseudoinverse of matrix A Ax =  2 1 1 3 0 1  as A†= (A⊤A)−1A⊤: A†= (210 131  2 1 1 3 0 1 )−1210 131=0.567 −0.133 −0.167 −0.167 0.333 0.167  then, if we want to solve Ax =b, with b= [3,1,4], we obtain x=A†b=[0.9,0.5]. Using the SVD, A†=U⊤Σ†V. Since (see example 4.1) U= −0.499 0.847 0.183 −0.834 −0.413 −0.365 −0.234 −0.335 0.913  ;Σ=  3.719 0 0 1.473 0 0  ;V−0.493 −0.87 0.87 −0.493 and considering the inverse of the Σmatrix (Σ†) as: Σ†=  0.268 0 0 0.679 0 0   Then, now: A†=U⊤Σ†V=0.567 −0.133 −0.167 −0.167 0.333 0.167  35 4.6 Economy, compact and truncated SVD Remember that matrix Σ is a diagonal matrix with rsingular values in positions Σii, with i= 1, . . . , r and zeros otherwise: Σ =         σ10 0 ... 0 0 0σ20... 0 0 ... ... ... ... ... ... 0 0 ... σr0... 0 0 ... ... 0... 0 0 ... ... ... 0         (4.6.1) while V= [v1, ..., vn] and U= [u1, ..., um]. Let us assume that k=min(m, n). Then, Acan be written as: A=UΣV⊤ = [σ1u1, ..., σkuk,0, ..., 0][v1, ..., vn]⊤ =X j=1,..k σjujv⊤ j+X j=k+1,..n 0v⊤ j =X j=1,..k σjujv⊤ j (4.6.2) Defining Σj=diag(σ1, ..., σk), Uk= [u1, ..., uk], and Vk= [v1, ..., vk], we obtain: A=UkΣkV⊤ k(4.6.3) which is known as the economy SVD. On the other hand, if the rank rof Ais r<min(m, n), then there only are rsingular values different of zero, and then A=UrΣrV⊤ r(4.6.4) which is known as the compact SVD. This fact is useful when obtaining matrices Uand Vsince only urand vrvectors have to be calculated. Finally, in low-rank aproximation, only tsingular values (the thighest ones) are considered, and: A=UtΣtV⊤ t(4.6.5) which is known as the truncated SVD. 4.7 The SVD as the sum of rmatrices of rank 1 Let us take the economy SVD expression: A=UrΣrV⊤ r. and express matrix A as the sum of rmatrices of rank 1: A=UrΣrV⊤ r= r X k=1 σkukv⊤ k(4.7.1) 36 This will be a key fact to find the best low-rank approximation (in the following sections) of a matrix by using the SVD. 4.8 Matrix norms Remember that norms assign a real number (a length) to an element of vector space. The four (non-negativity, positive definiteness, absolute homogeneity and subadditivity or triangle inequality) defining properties of any norm applied to matrices Aand Bare (assume correct dimensions of the matrices): •∥A∥ ≥ 0 (positive-valued), •∥A∥= 0 only if A=0mn (definite), •∥λA∥=|λ| ∥A∥(absolutely homogeneous), •∥A+B∥≤∥A∥+∥B∥(triangle inequality). For matrix norms we introduce the additional condition: •∥AB∥ ≤ ∥A∥ ∥B∥(sub-multiplicative). 4.8.1 Matrix norms induced by vectors p-norms One way of defining a matrix norm, is using vector norms. The matrix norm measures how much a vector (assuming a vector p-norm) can increase in size when it is multiplied by A. Observe that in the definition we use a vector x that is a unitary vector (i.e., with norm ∥·∥= 1). From this we can define: •l−1norm: maximum absolute column sum of A, i.e., sum all columns and take the highest one: ∥A∥1=max∥Ax∥1 ∥x∥1 =max∥x∥1=1∥Ax∥1= max 1≤j≤n m X i=1 |aij|(4.8.1) •l−2norm: maximum singular value of A: ∥A∥2=max∥Ax∥2 ∥x∥2 =max∥x∥2=1∥Ax∥2=qλmax(A⊤A) = σmax(A) (4.8.2) This can be seen because A=UΣV⊤, and the vector with maximum length is v1. Then ∥Av1∥2=∥σ1u1∥2=σ1∥u1∥2, taking into account that ∥v1∥2=1 and ∥u1∥2=1, which yields the result; 37 •l−∞ norm: maximum absolute row sum of A, i.e., sum all rows and take the highest one: ∥A∥∞=max∥Ax∥∞ ∥x∥∞ =max∥x∥∞=1∥Ax∥∞= max 1≤i≤m n X j=1 |aij|(4.8.3) You can find geometrically the value of a matrix norm for a given matrix A geometrically by: •Plotting the unit sphere for the matrix •Finding the image under the transformation y=A=x •Finding the maximum of ∥y∥ That means that an induced matrix norm ∥A∥is how much a matrix can stretch a vector to a maximum. If norm of a matrix is say number d; it means it can stretch a vector x by dmaximum. Example 4.3 (Matrix norms) Let us take as example the matrix: A=1 2 0 2 and plot figures for ∥A∥1,∥A∥2and ∥A∥infty (Figure 8). Observe that σ1= 2.9208 and σ2= 0.6847. Thus ∥A∥1= 4,∥A∥2= 2.9208 and ∥A∥∞= 3. Observe, also, how vectors (1,0) transforms to (1,0) and (0,1) transforms in (2,2), that precisely is ymax for ∥A∥1and ∥A∥2. However, ymax=(3,2) corresponds to point (1,1) for ∥A∥∞. Applying the norm definition to ymax, you should obtain the same norm than applying the matrix p-norm definitions. 4.8.2 Schatten norms: Matrix norms that can be expressed in terms of singular values Other possible matrix norms are the Schatten norms, which are defined in terms of the singular values, and which in some cases can be expressed in terms of the trace operator. The spectral norm is the operator norm induced by the vector 2-norm. Then, this norm coincides with the induced vector p= 2 norm: ∥A∥2=max∥Ax∥2 ∥x∥2 =σmax(A) (4.8.4) 38 Figure 8: Induced matrix norms representation. The Frobenius norm can be defined in several ways (in terms of sum of all absolute coefficient values of the matrix, in terms of the trace of (AA⊤) or trace of (A⊤A), and in terms of the sum of singular values): ∥A∥F=sX kX i|aik|2=qtr(A⊤A) = qtr(AA⊤) = sX k σ2 k(4.8.5) Frobenius norm is often easier to compute than induced norms, and has the useful property of being invariant under rotations (and unitary operations in general), meaning that if Uis a rotation (unitary matrix), then ∥A∥F=∥AU∥F= ∥UA∥F. From here, we get the connection between the expression ”summatory of all matrix aij coefficients” and the summatory of square singular values, since A=UΣV⊤. This norm is used in many applications, such as regularization in machine learning/optimization problems when using matrices. An example is in obtaining the Laplacian matrix coefficients in graph signal processing (GSP) from the data measurements (we will see this application in some days). For the semidefinite matrix A⊤Awe can define an square root as a matrix B 39 Figure 9: Spectral and Frobenius norms representation (2-D). The nuclear norm is the sum of σ1+σ2and thus is the perimeter of the paralelogram (sum of orange and blue arrows). for which B2=A⊤A. We define the nuclear (or Ky-Fan) norm or trace norm as: ∥A∥N=X k σk=tr(q(A⊤A)) (4.8.6) these norms usually appear in infinite dimensional spaces, and also it is often used in mathematical optimization to search for low-rank matrices (measures the ”amount of rank-1 matrices” needed to construct A). It has applications in deep learning (chooses the best weights in gradient descent when there is more weights than samples), and also appears in other applications such as compressive sensing (express a vector in a ”compressed” way with many zero entries). Example 4.4 (Schatten norms) Let us assume matrix A A=  2101 1342 0133  Their singular values are σ1= 6.909,σ2= 2.238 and σ3= 1.501. The spectral norm is ∥A∥2=σmax(A) = σ1= 6.909. The Frobenius norm is ∥A∥F= pPkσ2 k= 7.416, and the nuclear norm is ∥A∥N=Pkσk= 10.648. 40 4.9 Condition number of a matrix The condition number of a matrix A∈Rn×ncharacterizes the sensitivity of the solution of a linear system Ax =bto small changes in Aand b. Let us take derivatives at both sides of the linear system: Adx+ (dA)x=db⇒dx=A−1(db−(dA)x) (4.9.1) Now, taking the Euclidean norm at both sides: ∥dx∥≤∥A−1∥ ∥(db−(dA)x)∥ ≤ ∥A−1∥(∥db∥+∥dA∥ ∥x∥) (4.9.2) Now, we can use the inequality ∥b∥=∥Ax∥≤∥A∥ ∥x∥, we get: ∥d(x)∥ ∥x∥≤κ(A) (∥dA∥ ∥A∥+∥db∥ ∥b∥) (4.9.3) We define the condition number of matrix A as: κ(A) = ∥A∥2∥A−1∥2=σmax σmin (4.9.4) where σmax and σmax are the maximum and minimum singular values of matrix A. Large condition number κ(A) results in a highly sensitive system, that is, small changes in Aor bmay result in very large changes in the solution x. On the other hand, a large condition number κ(A) implies that σmax >> σmin, and then the matrix Ais almost singular (is not invertible). Example 4.5 (Condition number) Let us assume matrix A0(it is a singular matrix) and an approximated matrix A. A0=2 4 1 2;A=2.0002 3.9999 0.9996 2.0002 The SVD of matrix Ais: A=2.0002 3.9999 0.9996 2.0002=−0.894 −0.447 −0.447 0.894 4.999 0 0 0.00049−0.447 −0.894 −0.894 0.447  The condition number is κ(A) = σmax/σmin = 4.999/0.00049 = 1000.00. Let us calculate A†: A†=800.08 −1599.96 −399.84 800.08 = Let us solve the linear system Ax =bwith several b’s: 2.0002 3.9999 0.9996 2.0002x1 x2=b1 b2 For example b= [2,1] results in x= [0.2,0.4], while a small change in component b1such as b= [2.05,1] results in x= [40.204,−19.592], or a small change in component b2such as b= [2,1.02] results in x= [−31.79,16.402]. 41 papers or in the book of S. Brunton ”Data driven Science & Engineering”). r=λ(β)√nγ (5.5.4) r=λ(β)=(2(β+ 1) + 8β (β+ 1) + (β2+ 14β+ 1)1/2)1/2(5.5.5) If n<<m, then β=n/m, and of β=1 the expression reduces to the previous one. If the magnitude of γis unknown, and X∈Rm×n(non-square) then the optimal threshold is given by: ˜σ=w(β)σmed (5.5.6) where σmed is the median of the singular values, while w(β) is obtained as: w(β)≈0.56β3−0.95β2+ 1.82β+ 1.43 (5.5.7) where β=m/n. Finally, rcorresponds to the number of singular values that are greater than the threshold ˜σ. Figure 11: Eigenfaces database (taken from Brunton book ”Data driven Science & Engineering”). The approximation improves for r≥400. 6 Fourier transform and its applications The idea of Fourier series and Fourier transforms is to decompose functions into their basic components. Fourier transforms have many applications such as noise filtering, spectral derivatives, transforming partial differential equations, 48 Figure 12: Eigenfaces database (taken from Brunton book ”Data driven Science & Engineering”). Since faces have mouth, eyes, cheeks, and a lot of features, and there are more than 1600 faces representing a lot of situations, the approximation works pretty well for a dog. Figure 13: Eigenfaces database (taken from Brunton book ”Data driven Science & Engineering”). Approximation for a cappuccino, works well because the 1600 faces also represent non-localized spatial features. image processing, and a way of express vector data in generic or universal bases, in contrast with vector data expressed in tailored bases, in which we were able to compress data using the SVD (reduction of dimensionality). Sparsity consists in expressing a signal with a vector in which many components 49 are zero, Although the fast Fourier transform is a technology that allows a signal to be reconstructed from its sparse coefficients, it is not the only way to do so, e.g. Fourier is the basis of JPEG or MPEG. The Fourier modes are generic or universal bases, in the sense that nearly all natural images or audio signals are sparse in these bases. It is also possible to compress signals using the SVD, resulting in a tailored basis. 6.1 Fourier series As in finite-dimensional vector spaces, the inner product may be used to project a function into an new coordinate system defined by a basis of orthogonal functions. A Fourier series representation of a function f is precisely a projection of this function onto the orthogonal set of sine and cosine functions with integer period on the domain [a, b]. An important result is that if f(x) is periodic and piecewise smooth, then it can be written as a Fourier series. For example, if f(x) is L-periodic in [0,L), then: f(x) = a0 2+∞ X k=1 (akcos(2πkx L) + bksin(2πkx L)) (6.1.1) ak=2 LZL 0 f(x)cos(2πkx L)dx =< f(x), cos(2πkx L)> ∥cos(2πkx L)∥2(6.1.2) bk=2 LZL 0 f(x)sin(2πkx L)dx =< f(x), sin(2πkx L)> ∥sin(2πkx L)∥2(6.1.3) These coefficients may be viewed as the coordinates obtained by projecting the function onto the orthogonal cosine and sine basis {cos(kx), sin(kx)}∞ k=0. Since we can write the Fourier series in complex form using the facts that eikx =cos(2πkx L) + i sin(2πkx L) and ck=ak+i bk: f(x) = ∞ X k=−∞ ckeikx =∞ X k=−∞ ckψk(x) (6.1.4) Thus, a Fourier series is just a change of coordinates of a function f(x) into an infinite-dimensional orthogonal function space spanned by sines and cosines. 6.2 Fourier transform The Fourier series is defined for periodic functions, so that outside the domain of definition, the function repeats itself forever. The Fourier transform integral is essentially the limit of a Fourier series as the length of the domain goes to infinity, which allows us to define a function defined on (−∞,∞). 50 Thus, we represent the set of frequencies as wk=kπ/L, and taking the limit L→ ∞, such as k/L →f,w=2πf, ∆w=2π/L, and ∆w→0, we will arrive to the classical Fourier transforms formulas (not necessary to proof here the pass from Fourier series to Fourier transform, see books for that proof if interested): F(w) = Z∞ −∞ f(x)e−iwx dx (6.2.1) f(x) = Z∞ −∞ F(w)eiwx dw (6.2.2) Example 6.1 (Fourier Transform example) For example, assume a box signal, Figure 14, f(x)=A if x∈[−T/2, T/2] and 0 otherwise, has Fourier Transform F(f)=ATsinc(fT)= ATsin(πfT/(πfT)), where the sinc(f)=sin(πf)/(πf). (a) Box signal. (b) Sinc signal Figure 14: The box signal f(x)=A if x∈[−T/2, T/2] and 0 otherwise, has Fourier Transform F(f)=ATsinc(fT)= ATsin(πfT)/(πfT)). 51 6.2.1 Some basic properties of the FT Let us assume that we have functions f(x), g(x), and their Fourier Transform F(w), G(w). The following basic properties hold: •Linearity: the Fourier transform of sum of two or more functions that are multiplied by a constant is the sum of the Fourier transforms of the functions (af(x) + bg(x)) =⇒(aF(w) + bG(w)) (6.2.3) •Scaling: if we stretch a function by the factor in the time domain then squeeze the Fourier transform by the same factor in the frequency domain: f(ax) =⇒(1/|a|)F(w/a) (6.2.4) •Derivative: differentiating function with respect to time yields to the constant multiple of the initial function: df(x)/dx =⇒(jw)F(w) (6.2.5) •Convolution: the Fourier transform of a convolution of two functions is the point-wise product of their respective Fourier transforms: f(x)∗g(x) =⇒F(w)G(w) (6.2.6) Note: the convolution of two functions is a mathematical operation that says how the shape of a function is changed by the other function, a convolution in continuous time is expressed as f(x)∗g(x) = Z∞ −∞ f(y)g(x−y)dy =Z∞ −∞ f(x−y)g(y)dy (6.2.7) •Time shift: a linear displacement in time corresponds to a linear phase factor in the frequency domain: f(x−x′) =⇒F(w)e−jwx′(6.2.8) •Frequency shift: frequency is shifted according to the co-ordinates: f(x)ejw′x=⇒F(w−w′) (6.2.9) 6.2.2 Applications There are many applications in engineering in which Fourier Transforms are used. Among them, we can list: i) solving of partial differential equations such as the heat equation d2f(x,t)/dx2= df(x,t)/dt or the wave equation d2f(x,t)/dx2= d2f(x,t)/dt2; ii) spectral analysis of time-series (e.g. to find the response of the LTI ( linear time invariant ) systems); iii) filtering (lowpass, bandpass or highpass); iv) etc, etc, etc. We will see some examples after seeing the discrete version of the FT. 52 6.3 Discrete Fourier Transform and Fast Fourier Transform We have seen how to obtain the Fourier transform when the signal f(x) is a continuous function. However, in general, we discretize the analog/continuous signals, e.g., using an ADC that samples the signal to a specific sampling rate or spacing ∆x, having a vector of data [f0, f1, . . . , fN−1]. Thus, it is necessary, when dealing with vectors of data, to approximate the Fourier transform for dealing with discrete vectors. This is called the discrete Fourier transform, DFT. Remember that the domain of the function was called xand then the data is sampled at point xiand the evaluation of the function (samples) are then called fi. However, for simplicity, from now, we will express our vectors of sampled data [f0, f1, . . . , fN−1] as [x0, x1, . . . , xN−1], to be coherent with the variables expressed during the course (meaning that vector xis the sample data and not the domain of the function). Let us define the complex number wN=ej2π N=cos(2π N) + j sin(2π N), i.e. is the first N-th root of −1. The Fourier matrix FNis defined as: FN=1 √N          1 1 1 ... 1 1w−1 Nw−2 N... w−(N−1) N 1w−2 Nw−4 N... w−2(N−1) N 1w−2 Nw−6 N... w−3(N−1) N ... ... ... ... ... 1w−(N−1) Nw−2(N−1) N... w−(N−1)(N−1) N          (6.3.1) Sometimes the factor 1 √Nis omitted in the definition. This matrix is unitary, meaning that FNHFN=FNFNH=I. The matrix AH is called hermitian if it is a complex square matrix that is equal to its own conjugate transpose, i.e., aij = ¯aji (remember complex conjugate; if aij=3+j4, then ¯aji=3-j4) or A=AH(special case is when the component is a real number in which A=A⊤). In other words, hermitian matrices can be understood as the complex extension of real symmetric matrices. Remember that as we are dealing with complex vectors and matrices, the scalar product between two vectors xand y(e.g. two columns of FN) is defined as xHy.Do not forget to use the conjugate transpose instead of simply transpose!. For instance, if N= 4 we have: F4=1 2    1 1 1 1 1−j−1j 1−1 1 −1 1j−1−j    (6.3.2) The Fourier matrix is one of the most important matrices in applied mathemat- 53 ics and engineering. 6.3.1 The Discrete Fourier Transform (DFT) The discrete Fourier transform (DFT), ˆx, is the operation of multiplying a vector of data xby the matrix FN: ˆx=FNx=1 √N          1 1 1 ... 1 1w−1 Nw−2 N... w−(N−1) N 1w−2 Nw−4 N... w−2(N−1) N 1w−2 Nw−6 N... w−3(N−1) N ... ... ... ... ... 1w−(N−1) Nw−2(N−1) N... w−(N−1)(N−1) N                  x0 x1 x2 x3 . . . xN−1         (6.3.3) This operation is the same as: ˆxk= N−1 X i=0 xie−j2πik/N ∀k= 0, . . . , N −1 (6.3.4) meaning that: x=[x0, x1, . . . , xN−1]DF T =⇒ˆx=[ˆx0,ˆx1,...,ˆxN−1] (6.3.5) The result of this multiplication ˆxis called the transformed vector. For commodity, we will use the term signal for the vector xand Fourier transform for the vector ˆx. Recall that both vectors have dimension N. We can observe that the DFT is a linear operator (a matrix) that maps data points xin the frequency domain ˆx. It is to say, we see the DFT operation corresponds to finding the components of vector xexpressed in the unitary base created by the columns of FN(the so called Fourier base). The Inverse DFT is defined as: x=FH Nˆx(6.3.6) and this operation is the same as: xi=1 N N−1 X k=0 ˆxkej2πki/N ∀i= 0, . . . , N −1 (6.3.7) meaning that: ˆx=[ˆx0,ˆx1,...,ˆxN−1]IDF T =⇒x=[x0, x1, . . . , xN−1] (6.3.8) For a 2D signal X(e.g. a picture represented by a matrix with Mrows and N columns) we define the DFT as a two-step process: First find the DFT of the 54 columns, and then find the DFT of the columns of the resulting matrix (the order can be changed): ˆ X=FH MXFN(6.3.9) 6.3.2 The Fast Fourier Transform (FFT) In general, if Ais a N×Nmatrix, and xis a vector with Ncomponents, the operation Ax requires N2multiplications. In the special case of FNx, the FFT algorithm gives a method for computing this product in only 1 2Nlog2Nmultiplications. This is a huge improvement. Some people (e.g. G. Strang) considers that the FFT is the most important numerical algorithm of the XXth century. 6.3.3 The complex conjugate of the columns of the Fourier matrix are the eigenvectors of the circulant matrices Another extraordinary property of the columns of the Fourier matrix is that the complex conjugate of its columns are the eigenvectors of circulant matrices. A circulant matrix has the following form: C=    h0hN−1hN−2... h1 h1h0hN−1... h2 ... ... ... ... ... hN−1hN−2hN−3... h0    (6.3.10) Circulant matrices are especially important as they can be used to represent a very rich and important class of linear system, the linear systems that are invariant to time shifts. The eigenvector (1, wi, w2i, ..., w(N−1)i)⊤has associated the eigenvalue λi= h0+h1w−i+h2w−2i+... +hN−1w(N−1)i.Defining Λ=diag(λ0, ..., λN−1), we obtain the decomposition: C=FH NΛFN(6.3.11) The output signal for an input xcan be obtained very efficiently by applying the FFT algorithm. Example 6.2 (Filtering noise (denoising) in a signal) Afirst example es filtering noise (denoising) in a signal. For example consider figure 15 where we have a signal f(t)= sin(2πf1t) + sin(2πf2t) for f1=50 and f2=120 (black curve). We add some Gaussian noise distributed with zero mean and σ2vari- ance, i.e., N(0,σ2), (red curve). If we obtain the FT, we can observe the two 55 Figure 15: Denoising a signal (Figure taken from S.L. Brunton book, ”Data driven science & engineering”). peaks centered at f1=50 and f2=120. We can then filter the signal keeping frequencies lower than f2=120, and then removing high frequency components. We can observe in the third figure the original (without noise) signal and the denoised filtered signal. An example of a filter is to pass the signal f(t) by a linear system h(t). The output is the convolution y(t)=f(t)∗h(t) −→ Y(W)=F(W)H(w). If H(w) is a filter allowing to pass frequencies f1and f2and not allowing the rest of frequencies, we are denoising (filtering noise) our signal. Example 6.3 (Spectral derivative) Asecond example is the spectral derivative. We know that the FT of the derivative of a function in continuous time is F(df(x)/dx)=jwF(f(x)). If we discretize, then we can substitute jw →jκ, with κ= 2πk/n, assuming ncomponents. For example, let us assume the function: f(x) = cos(x)e−x2/25 =⇒df(x)/dx =−sin(x)e−x2/25 −2 25xf(x) (6.3.12) 56 (a) Derivative methods with n=128 points. (b) Error as a function of n Figure 16: Taking the derivative of a signal (Figure taken from S.L. Brunton book, ”Data driven science & engineering”). One way of obtaining the derivative is to use finite differences: df dx(xk) = f(xk+1)−f(xk) ∆x(6.3.13) for some ∆x. So, if we want to obtain the derivative of our signal, we have two options: i) use finite differences, and ii) take our signal, discretize with n samples, obtain the FFT of the signal, multiple by jκ, and obtain the IFFT. We can observe in Figure 16.a) the result of the true derivative (black), the finite difference method (blue) and the FFT (red). Both, the finite difference method (blue) and the FFT (red) are very close to the true derivative, but we can observe in Figure 16.b) the error in both methods, in which is seen how the FFT performs much better than the finite Euler method. 6.4 Most natural signals are sparse in the Fourier base Let us assume a vector of data x∈Rn, a vector xis called sparse if it has a large number of components equal to zero (or a small number of nonzero components). A vector xis called dense if it has a large number of components non equal to 57 The inverse graph discrete Fourier transform (IGDFT) of a signal, x, is thus defined as: x=UX (7.6.3) In case of having a circular graph, the GDFT reduces to the classical DFT. Given that we have defined a GDFT/IGDFT, we can define filters, convolutions, spectral analysis, signal reconstruction, denoising, and different operations performed in classical signal processing. 7.7 Signal reconstruction in a IoT network We consider the problem of having a subset of nodes (vertices of the graph) with samples and we would like to estimate the signal of the graph in the other vertices so that the resulting signal is smooth. Let is call Mthe set of nodes in the graph with observed data, and Uthe set of nodes in the graph with observed data (missing data). Thus the objective is to find the unobserved data from the observed neighboring nodes. This can be seen as a signal reconstruction problem that can be solved using methods from various fields. Let us consider the following methods; Laplacian interpolation and GSP low-pass based graph signal reconstruction. Laplacian interpolation is a graph-based semi-supervised learning algorithm whose goal is regression with graph regularization assuming smoothness with respect to the Laplacian matrix. This method regresses a function f:V→Rover the graph G, assuming partial information, it is to say, information for M nodes. GSP low-pass based graph signal reconstruction is a graph signal processing reconstruction method that considers subsampling low-pass graph signals, thus assuming a sparse Fourier coefficient vector. 7.7.1 Laplacian interpolation Also known as graph interpolated regularization by Belkin et al., this method minimizes the quadratic form of the Laplacian matrix with respect to the graph signal x, which is a measure of signal smoothness, given that the observed measurements {xm:∀m∈M} remain unchanged. This reconstruction results in a linear combination of the observations weighted by the Laplacian matrix entries Lij. Minimize yy⊤Ly s.t. ym=xm,∀m∈M (7.7.1) 7.7.2 Graph Signal Processing (GSP) low-pass reconstruction This technique recovers a set of unobserved nodes {xu:∀u∈U} given that the graph discrete Fourier transform of the complete signal is sparse and of low-pass 64 nature, meaning that it has Knonzero components corresponding to the lowest frequencies (smallest eigenvalues λiof the Laplacian matrix). Given that the Laplacian matrix admits the eigendecomposition L=UΛU⊤, the graph discrete Fourier transform (GDFT) of a graph signal xcan be computed as: X=U−1x(7.7.2) Now, a K-sparse GDFT coefficient vector of the following form is to be recovered: X= (X(0), . . . , X(K−1),0,...,0)⊤(7.7.3) For this purpose a subset of measurements Mare used to recover the sparse coefficient vector by solving the following system: xM=UMKXK(7.7.4) Since the system is overdetermined, the solution of the above system in the least squares sense is given by XK=U† MKxM, where U† MK= (U⊤ MKUMK)−1U⊤ MK is the matrix pseudo-inverse of UMK; the nonzero coefficients are obtained, and after appending the corresponding zero coefficients, the inverse graph discrete Fourier transform (IGDFT) x=UX is computed to obtain the complete set of measurements xat all vertices. Example 7.3 (GSP low pass reconstruction) Let us assume a network with N= 8 nodes, in which we only have M= 4 measurements, e.g. x(2), x(4), x(5) and x(7), and we want to reconstruct the signal with K= 2 coefficients. Then, we have to find X(0) and X(1) that satisfies:   x(4) x(5) x(7) =  u0(4) u1(4) u0(5) u1(5) u0(7) u1(7) X(0) X(1)(7.7.5) For finding X(O)and X(1), we solve the overdetermined system, and when we have these GDFT coefficients, we can obtain the original ones applying the IGDFT x=UX, with X=[X(0), X(1),0,0,0,0,0,0]. 65