In many areas of machine learning, statistics and signal processing, eigenvalue decompositions are commonly used, e.g., in principal component analysis, spectral clustering, convergence analysis of Markov chains, convergence analysis of optimization algorithms, low-rank inducing regularizers, community detection, seriation, etc.
Understanding how the spectral decomposition of a matrix changes as a function of a matrix is thus of primary importance, both algorithmically and theoretically. We thus need a perturbation analysis or more generally some differentiability properties for eigenvalues or eigenvectors [1], or any spectral function [2]. These properties can be obtained from many angles, but a generic tool can be used for all of these: it is a surprising and elegant application of Cauchy’s residue formula, which is due to Kato [3].
Before diving into spectral analysis, I will first present the Cauchy residue theorem and some nice applications in computing integrals that are needed in machine learning and kernel methods.
Cauchy residue formula
A function f:C→C is said holomorphic in λ∈C with derivative f′(λ)∈C, if is differentiable in λ, that is if z−λf(z)−f(λ) tends to f′(λ) when z tends to λ. Many classical functions are holomorphic on C or portions thereof, such as the exponential, sines, cosines and their hyperbolic counterparts, rational functions, portions of the logarithm.
We consider a function which is holomorphic in a region of C except in m values λ1,…,λm∈C, which are usually referred to as poles. We also consider a simple closed directed contour γ in C that goes strictly around the m values above.
The Cauchy residue formula gives an explicit formula for the contour integral along γ:
∮γf(z)dz=2iπj=1∑mRes(f,λj),(1)
where Res(f,λ) is called the residue of f at λ . If around λ, f(z) has a series expansions in powers of (z−λ), that is, f(z)=k=−∞∑+∞ak(z−λ)k, then Res(f,λ)=a−1.
For example, if f(z)=z−λg(z) with g holomorphic around λ, then Res(f,λ)=g(λ), and more generally, if f(z)=(z−λ)kg(z) for k⩾1, then Res(f,λ)=(k−1)!g(k−1)(λ). For more details on complex analysis, see [4].
The result above can be naturally extended to vector-valued functions (and thus to any matrix-valued function), by applying the identity to all components of the vector.
This result is due to Cauchy [10] in 1825. The original paper where this is presented is a nice read in French where you can find some pepits like “la fonction s’évanouit pour x=∞”.
If you are already familiar with complex residues, you can skip the next section.
Where does it come from?
At first, the formula in Eq. (1) seems unsettling. Why doesn’t the result depend more explicitly on the contour γ? Where does the multiplicative term 2iπ come from? Here is a very partial and non rigorous account (go to the experts for more rigor!).
Complex-valued functions on C can be seen as functions from R2 to itself, by writing
f(x+iy)=u(x,y)+iv(x,y),
where u and v are real-valued functions. We have thus a function (x,y)↦(u(x,y),v(x,y)) from R2 to R2. Expanding f(z+dz)=f(z)+f′(z)dz, which is the definition of complex differentiability, into real and imaginary parts, we get (using i2=−1):
This in turn leads to the Cauchy-Riemann equations∂x∂u=∂y∂v and ∂y∂u=−∂x∂v, which are essentially necessary and sufficient conditions to be holomorphic. Thus holomorphic functions correspond to differentiable functions on R2 with some equal partial derivatives. These equations are key to obtaining the Cauchy residue formula.
Contour integral with no poles. We first consider a contour integral over a contour γ enclosing a region D where the function f is holomorphic everywhere. The contour γ is defined as a differentiable function γ:[0,1]→C, and the integral is equal to
Thus, because of the Cauchy-Riemann equations, the contour integral is always zero within the domain of differentiability of f. Note that this extends to piecewise smooth contours γ.
Circle and rational functions. For a circle contour of center λ∈C and radius r, we have, with γ(t)=λ+re2iπt:
which is equal to zero if k=1, and to ∫012iπdt=2iπ for k=1. Thus, for a function with a series expansion, the Cauchy residue formula is true for the circle around a single pole, because only the term in z−λ1 contributes.
No dependence on the contour. Now that the Cauchy formula is true for the circle around a single pole, we can “deform” the contour below to a circle.
This can be done considering two contours γ1 and γ2 below with no poles inside, and thus with zero contour integrals, and for which the integrals along the added lines cancel.
This “shows” that the integral does not depend on the contour, and so in applications we can be quite liberal in the choice of contour. Note that similar constructions can be used to take into account several poles.
Before going to the spectral analysis of matrices, let us explore some cool choices of contours and integrands, and (again!) some positive definite kernels.
Classical examples
The Cauchy residue theorem can be used to compute integrals, by choosing the appropriate contour, looking for poles and computing the associated residues. Here are classical examples, before I show applications to kernel methods. See more examples in http://residuetheorem.com/, and many in [11].
Fourier transforms. For ω>0, we can compute ∫−∞∞f(x)eiωxdx for holomorphic functions f by integrating on the real line and a big upper circle as shown below, with R tending to infinity (so that the contribution of the half-circle goes to zero because of the exponential term). This leads to 2iπ times the sum of all residues of the function z↦f(z)eiωz in the upper half plane. See an example below related to kernel methods.
Trigonometric integrals. For holomorphic functions Q, we can compute the integral ∫02πQ(cosθ,sinθ)dθ. Indeed, letting f(z)=iz1Q(2z+z−1,2iz−z−1), it is exactly equal to the integral on the unit circle. The desired integral is then equal to 2iπ times the sum of all residues of f within the unit disk.
For example, when Q(cosθ,sinθ)=2+sinθ1, we have f(z)=z2+4iz−12, with a single pole inside the unit circle, namely λ=i(3−2), and residue equal to −i/3, leading to ∫02π2+sinθdθ=32π.
Series. If the function f is holomorphic and has no poles at integer real values, and satisfies some basic boundedness conditions, then
n∈Z∑f(n)=–λ∈poles(f)∑Res(f(z)πsinπzcosπz,λ).
This is a simple consequence of the fact that the function z↦πsinπzcosπz has all integers n∈Z as poles, with corresponding residue equal to 1. This is obtained from the contour below with m tending to infinity.
The same trick can be applied to n∈Z∑(−1)nf(n)=–λ∈poles(f)∑Res(f(z)πsinπz1,λ). See [7, Section 11.2] for more details. Experts will see an interesting link with the Euler-MacLaurin formula and Bernoulli polynomials.
Applications to kernel methods. In non-parametric estimation, regularization penalties are used to constrain real-values functions to be smooth. One such examples are combinations of squared L2 norms of derivatives. For functions f defined on an interval I of the real line, penalties are typically of the form ∫I∑k=0sαk∣f(k)(x)∣2dx, for non-negative weights α0,…,αk. For these Sobolev space norms, a positive definite kernel K can be used for estimation (see, e.g., last month blog post).
A classical question is: given the norm defined above, how to compute K? For I=R, then this can be done using Fourier transforms as:
K(x,y)=2π1∫R∑k=0sαkω2keiω(x−y)dω.
This is exactly an integral of the form above, for which we can use the contour integration technique. For example, for α0=1 and α1=a2, we get for x−y>0, one pole i/a in the upper half plane for the function 1+a2z21=(1+iaz)(1−iaz)1, with residue −2aie−(x−y)/a, leading to the familiar exponential kernel K(x,y)=2a1e−∣x−y∣/a. More complex kernels can be considered (see, e.g., [8, page 277], for ∑k=0sαkω2k=1+ω2s).
We can also consider the same penalty on the unit interval [0,1] with periodic functions, leading to the kernel (see [9] for more details):
K(x,y)=n∈Z∑∑k=0sαk(2nπ)se2inπ(x−y).
For the same example as above, that is, α0=1 and α1=a2, this leads to an infinite series on which we can apply the Cauchy residue formula as explained above. This leads to, for x−y∈[0,1/2], K(x,y)=2a1sinh(2a1)cosh(2a1−2(x−y)). We can then extend by 1-periodicity and parity to all x−y. See the detailed computation at the end of the post.
Now that you are all experts in residue calculus, we can move on to spectral analysis.
Spectral analysis of symmetric matrices
We consider a symmetric matrix A∈Rn×n, with its n ordered real eigenvalues λ1⩾⋯⩾λn, counted with their orders of multiplicity, and an orthonormal basis of their eigenvectors uj∈Rn, j=1,…,n. We have A=∑j=1nλjujuj⊤. When we consider eigenvalues as functions of A, we use the notation λj(A), j=1,…,n. These functions are always well-defined even when eigenvalues are multiple (this is not the case for eigenvectors because of the invariance by orthogonal transformations).
The key property that we will use below is that we can express the so-called resolvent matrix (zI–A)−1∈Cn×n, for z∈C, as:
(zI−A)−1=j=1∑nz−λj1ujuj⊤.
The dependence on z of the form z−λj1 leads to a nice application of Cauchy residue formula.
Assuming the k-th eigenvalue λk is simple, we consider the contour γ going strictly around λk like below (for k=5).
We consider integrating the matrix above, which leads to:
using the identity ∮γz–λj1dz=1 if j=k and 0 otherwise (because the pole is outside of γ). We thus obtain an expression for projectors on the one-dimensional eigen-subspace associated with the eigenvalue λk.
With simple manipulations, we can also access the eigenvalues. Indeed, we have:
The key benefit of these representations is that when the matrix A is slightly perturbed, then the same contour γ can be used to enclose the corresponding eigenvalues of the perturbed matrix, and perturbation results are simply obtained by taking gradients within the contour integral. Note that several eigenvalues may be summed up by selecting a contour englobing more than one eigenvalues.
Gradients of eigenvalues
The expression with contour integrals allows to derive simple formulas for gradients of eigenvalues. These can be obtained by other means [5], but using contour integrals shows that this is simply done by looking at the differential of (zI–A)−1 and integrating it. The central component is the following expansion, which is a classical result in matrix differentiable calculus, with ∥Δ∥2 the operator norm of Δ (i.e., its largest singular value):
(zI−A–Δ)−1=(zI–A)−1+(zI−A)−1Δ(zI−A)−1+o(∥Δ∥2).
Note here that the asymptotic remainder o(∥Δ∥2) can be made explicit.
By expanding the expression on the basis of eigenvectors of A, we get
using the identity ∮γ(z–λk)2zdzdz=∮γ((z–λk)2λk+z–λk1)dz=1.
Thus the gradient of λk at a matrix A where the k-th eigenvalue is simple is simply ukuk⊤, where uk is a corresponding eigenvector. Note that this result can be simply obtained by the simple (rough) calculation: if x is a unit eigenvector of A, then Ax=λx, and x⊤x=1, leading to x⊤dx=0 and dAx+Adx=dλx+λdx, and by taking the dot product with x, dλ=x⊤dAx+x⊤Adx=x⊤dAx+λx⊤dx=x⊤dAx, which is the same result. However, this reasoning is more cumbersome, and does not lead to neat approximation guarantees, in particular in the extensions below.
Other perturbation results
Given the gradient, other more classical perturbation results could de derived, such as Hessians of eigenvalues, or gradient of the projectors ukuk⊤. Here I derive a perturbation result for the projector Πk(A)=ukuk⊤, when λk is a simple eigenvalue. Using the same technique as above, we get:
Spectral functions are functions on symmetric matrices defined as F(A)=∑k=1nf(λk(A)), for any real-valued function f. For f(x)=x, we get back the trace, for f(x)=logx we get back the log determinant, and so on. The function F can be represented as
F(A)=k=1∑nf(λk(A))=2iπ1∮γf(z)tr[(zI–A)−1]dz,
where the contour γ encloses all eigenvalues (as shown below).
This representation can be used to compute derivatives of F, by simple derivations, to obtain the same result as [12].
Singular values of rectangular matrices
Singular value decompositions are also often used, for a rectangular matrix W∈Rn×d. It consists in finding r pairs (uj,vj)∈Rn×Rd, j=1,…,r, of singular vectors and r positive singular values σ1⩾⋯⩾σr>0 such that W=∑j=1rσjujvj⊤ and (u1,…,ur) and (v1,…,vr) are orthonormal families.
There are two natural ways to relate the singular value decomposition to the classical eigenvalue decomposition of a symmetric matrix,
first through WW⊤ (or similarly W⊤W). Here it is more direct to consider the so-called Jordan-Wielandt matrix, defined by blocks as
Wˉ=(0W⊤W0).
The matrix Wˉ is symmetric, and its non zero eigenvalues are +σi and −σi, i=1,…,r, associated with the eigenvectors 21(uivi) and 21(ui−vi).
All necessary results (derivatives of singular values σj, or projectors ujvj⊤ can be obtained from there); see more details, in, e.g., the appendix of [6].
Going beyond
In this post, I have shown various applications of the Cauchy residue formula, for computing integrals and for the spectral analysis of matrices. I have just scratched the surface of spectral analysis, and what I presented extends to many interesting situations, for example, to more general linear operators in infinite-dimensional spaces [3], or to the analysis fo the eigenvalue distribution of random matrices (see a nice and reasonably simple derivation of the semi-circular law from Terry Tao’s blog).
References
[1] Gilbert W. Stewart and Sun Ji-Huang. Matrix Perturbation Theory. Academic Press, 1990.
[2] Adrian Stephen Lewis. Derivatives of spectral functions. Mathematics of Operations Research, 21(3):576–588, 1996.
[3] Tosio Kato. Perturbation Theory for Linear Operators, volume 132. Springer, 2013.
[4] Serge Lang. Complex Analysis, volume 103. Springer, 2013.
[5] Jan R. Magnus. On differentiating eigenvalues and eigenvectors. Econometric Theory, 1(2):179–191, 1985.
[6] Francis Bach. Consistency of trace norm minimization. Journal of Machine Learning Research, 9:1019-1048, 2008.
[7] Joseph Bak, Donald J. Newman. Complex analysis. New York: Springer, 2010.
[8] Alain Berlinet, and Christine Thomas-Agnan. Reproducing kernel Hilbert spaces in probability and statistics. Springer Science & Business Media, 2011.
[9] Grace Wahba. Spline models for observational data. Society for Industrial and Applied Mathematics, 1990.
[10] Augustin Louis Cauchy, Mémoiresur les intégrales définies, prises entre des limites imaginaires, 1825, re-published in Bulletin des Sciences Mathématiques et Astronomiques, Tome 7, 265-304, 1874.
[11] Dragoslav S. Mitrinovic, and Jovan D. Keckic. The Cauchy method of residues: theory and applications. Vol. 9. Springer Science & Business Media, 1984.
[12] Adrian S. Lewis, and Hristo S. Sendov. Twice differentiable spectral functions. SIAM Journal on Matrix Analysis and Applications 23.2: 368-386, 2001.
Computing the Sobolev kernel
The goal is to compute the infinite sum
n∈Z∑1+(2aπn)2e2iπq⋅n
for q∈(0,1/2). We consider the function
f(z)=1+(2aπz)2eiπ(2q−1)zsin(πz)π.
It is holomorphic on C except at all integers n∈Z, where it has a simple pole with residue 1+(2aπn)2eiπ(2q−1)n(−1)n=1+(2aπn)2eiπ2qn, at z=i/(2aπ) where it has a residue equal to 4iaπe–(2q−1)/(2a)sin(i/(2a))π=–4ae–(2q−1)/(2a)sinh(1/(2a))1, and at z=−i/(2aπ) where it has a residue equal to 4iaπe(2q−1)/(2a)sin(i/(2a))π=–4ae(2q−1)/(2a)sinh(1/(2a))1. With all residues summing to zero (note that this fact requires a precise analysis of limits when m tends to infinity for the contour defined in the main text), we get: