Computation of the von Neumann entropy of large matrices via trace estimators and rational Krylov methods

We consider the problem of approximating the von Neumann entropy of a large, sparse, symmetric positive semidefinite matrix A, defined as tr(f(A))\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$${{\,\textrm{tr}\,}}(f(A))$$\end{document} where f(x)=-xlogx\documentclass[12pt]{minimal} \usepackage{amsmath} \usepackage{wasysym} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{amsbsy} \usepackage{mathrsfs} \usepackage{upgreek} \setlength{\oddsidemargin}{-69pt} \begin{document}$$f(x)=-x\log x$$\end{document}. After establishing some useful properties of this matrix function, we consider the use of both polynomial and rational Krylov subspace algorithms within two types of approximations methods, namely, randomized trace estimators and probing techniques based on graph colorings. We develop error bounds and heuristics which are employed in the implementation of the algorithms. Numerical experiments on density matrices of different types of networks illustrate the performance of the methods.


Introduction
The von Neumann entropy [56] of a symmetric positive semidefinite matrix A with tr(A) = 1 is defined as S(A) = tr(−A log A), where log A is the matrix logarithm.With the usual convention that 0 • log 0 = 0, the von Neumann entropy is given by where λ 1 , . . ., λ n are the eigenvalues of the n × n matrix A. The von Neumann entropy plays an important role in several fields including quantum statistical mechanics [42], quantum information theory [5], and network science [15].For example, computing the von Neumann entropy is necessary in order to determine the ground state of many-electron systems at finite temperature [1].The von Neumann entropy of graphs is also an important tool in the structural characterization and comparison of complex networks [22,36].
If the size of A is large, the computation of S(A) by means of explicit diagonalization can be too expensive, so it becomes necessary to resort to cheaper methods that compute approximations of the entropy.In recent years, a few papers have appeared devoted to this problem; see, e.g., [17,31,44,59].These papers investigate different approaches based on quadratic (Taylor) approximants, the global Lanczos algorithm, Gaussian quadrature and Chebyshev expansion.In general, the problem of computing the von Neumann entropy of a large matrix is difficult because the underlying matrix function is not analytic in a neighbourhood of the spectrum when the matrix is singular; difficulties can also be expected when A has eigenvalues close to zero, which is usually the case.In particular, polynomial approximation methods may converge slowly in such cases.
In this paper we propose to approximate the von Neumann entropy using either the probing approach developed in [29] or a stochastic trace estimator [39,47,49].The main contributions of this work are outlined in the following.
In Section 2.1 we obtain an integral expression for the entropy function f (x) = −x log x that relates it with a Cauchy-Stieltjes function [58, Chapter VIII], and we use it to derive error bounds for the polynomial approximation of f , which in turn lead to a priori bounds for the approximation of S(A) with probing methods.In order to also have a practical stopping criterion alongside the theoretical bounds, in Section 5.1 we propose some heuristics to estimate the error of probing methods, and in Section 6.2 we demonstrate their reliability with numerical experiments.In Section 3.1 we also use properties of symmetric M -matrices to show that, in the case of the graph entropy, the approximation obtained with a probing method is a lower bound for the exact entropy.
Both probing methods and stochastic trace estimators require the computation of a large number of quadratic forms with f (A), which can be efficiently approximated using Krylov subspace methods [30,35].In Section 4.2 we propose to combine polynomial Krylov iterations with rational Krylov iterations that use asymptotically optimal poles for Cauchy-Stieltjes functions [45].In Section 4.3 we obtain new a posteriori error bounds and estimates for this task, building on the ones presented in [34], and we discuss methods to compute them efficiently.For the case of the graph entropy, we make use of a desingularization technique introduced in [11] that exploits properties of the graph Laplacian to compute quadratic forms more efficiently.
The resulting algorithm can be seen as a black box method that only requires an input tolerance and computes an approximation of S(A) with relative accuracy .While this accuracy is not guaranteed when the rigorous bounds are replaced by heuristics, we found the algorithm to be quite reliable in practice.
Our implementation of the probing algorithm is compared to a state-of-the-art randomized trace estimator developed in [49] with several numerical experiments in Section 6, in which we approximate the graph entropy of various complex networks.
The rest of the paper is organized as follows.In Section 2 we recall some properties of the von Neumann entropy and we obtain bounds for the polynomial approximation of f (x) = −x log x, which we use in the subsequent sections.In Section 3 we give an overview of probing methods and stochastic trace estimators and we derive bounds for the convergence of probing methods.In Section 4 we describe the computation of quadratic forms using Krylov subpsace methods and we derive a posteriori error bounds and estimates.In Section 5 we summarize the overall algorithm and we discuss heuristics and stopping criteria, and in Section 6 we test the performance of the methods on density matrices of several complex networks.Finally, Section 7 contains some concluding remarks.

Properties of the von Neumann entropy
A density matrix ρ is a self-adjoint, positive semi-definite linear operator with unit trace acting on a complex Hilbert space.In quantum mechanics, density operators describe states of quantum mechanical systems.Here we consider only finite dimensional Hilbert spaces, so ρ is an n × n Hermitian matrix.For simplicity, here we focus on real symmetric matrices; all the results are easily extended to the complex case.
Recall that the von Neumann entropy of a system described by the density matrix ρ [56] is given by where σ(ρ) denotes the spectrum of ρ, under the convention that 0 • log(0) = 0.Here log(x) is the natural logarithm.Note that in the literature the entropy is sometimes defined using log 2 (x) instead, but since log 2 (x) = log(x)/ log(2) the two definitions are equivalent up to a scaling factor.We also mention that in the original definition the entropy includes the factor κ B (the Boltzmann constant), which we omit.A straightforward way to compute S(ρ) is by diagonalization.However, this approach is unfeasible when the dimension is very large.Here we propose some approaches to compute approximations to the von Neumann entropy based on the trace estimation of matrix functions.
Note that the formula (2.1) is well defined even without the hypothesis of unit trace.Moreover, if ρ is given in the form ρ = γA with γ > 0, we have the relation In quantum mechanics, the von Neumann entropy of a density matrix gives a measure of how much a density matrix is distant from being a pure state, that is a rank-1 matrix with only one nonzero eigenvalue equal to one [57].For any density matrix of size n, we have 0 ≤ S(ρ) ≤ log(n).Moreover, S(ρ) = 0 if and only if ρ is a pure state and S(ρ) = log(n) if and only if ρ = 1  n I [56,57].The von Neumann entropy also has applications in network theory.Recall that a graph G is given by a set of nodes V = {v 1 , . . ., v n } and a set of edges E ⊂ V × V.The graph is called undirected if (v i , v j ) ∈ E if and only if (v j , v i ) ∈ E for all i = j.A walk on the graph of length is a sequence of + 1 nodes where two consecutive nodes are linked by an edge, for a total of edges.We say that G is connected if there exists a directed path from node i to node j for any pair of nodes (i, j).The adjacency matrix of a graph is a matrix and 0 otherwise.The degree of a node deg(v i ) is the number of nodes that are linked with v i by an edge.It can be expressed in the form deg(v i ) = [A1] i , where 1 is the vector of all ones.Finally, the graph Laplacian is given by Note that L is a singular positive semidefinite matrix and the eigenvalue 0 is simple if and only if G is connected, in which case the associated one-dimensional eigenspace is spanned by 1.Given the density matrix ρ = L/ tr(L), the von Neumann entropy of G is defined as S(ρ) [15,17].
It should be mentioned that, strictly speaking, the graph entropy defined in this manner is not a "true" entropy, since it does not satisfy the sub-additivity requirement.In other words, the graph entropy could decrease when an edge is added to the graph, see [24].For this reason, different notions of graph entropy have been proposed in the literature; see, e.g., [32,33].These entropies still have the form of a von Neumann entropy, S = − tr(ρ log ρ), but with a different definition of the density matrix ρ which, however, is still expressed as a function of a matrix (Hamiltonian) associated to the graph.Therefore, the techniques developed in this paper are still applicable, at least in principle.
If A is a symmetric (or Hermitian) matrix with σ(A) ⊂ [a, b], estimating or bounding this quantity is crucial in the study of polynomial approximations of the matrix function f (A) [4] and for establishing decay bounds for the entries of f (A) [8,23,27].
An important case is the inverse function f (x) = 1/x for x ∈ [a, b], 0 < a < b, for which we have , where κ = b/a; see, e.g., [46].In general, an inequality of the form is equivalent to the fact that f is analytic over an ellipse containing [a, b] for some computable parameters C > 0 and 0 < q < 1; see [46,Theorem 73] for more details.The function f (x) = x log(x) is not analytic on any neighborhood of 0, so we cannot expect to find a geometric decay as in (2.6) if we consider [0, b], b > 0, as the interval of definition.However, since f is continuous, by the Weierstrass Approximation Theorem E k (f, [0, b]) must go to 0 as k → ∞.A more precise estimate is the following [59], derived by computing the coefficients of the Chebyshev expansion of f (x): for all k ≥ 1.
This shows that the decay rate of the error is algebraic in k.Our approach is based on an integral representation and leads to sharper bounds.
Recall that a Cauchy-Stieltjes function [10,45] has the form where µ is a (possibly signed) real measure supported on [0, +∞) and the integral is absolutely convergent.An example is given by the function log(1 + z)/z that has the expression It is easy to check that the above identity also holds for z ∈ (−1, 0).With the change of variable x = 1 + z and some simple rearrangements, we get the following integral expression for the entropy: (2.9) With the additional change of variable s = t + 1, we can rewrite (2.9) in the form (2.10) Note that the above identities also hold for x = 0 and x = 1, because of the factor x(1 − x) in front of the integral.This shows that although the entropy function −x log(x) is not itself a Cauchy-Stieltjes function, we can recognize a factor with the form (2.8) in its integral representation.This observation will be important later for the selection of poles in a rational Krylov method; see Section 4.2.
Integral representations have proved useful for many problems related to polynomial approximations and matrix functions; see e.g.[9,10,27].The following result shows that we can derive explicit bounds for where g t (x) is continuous for (t, x) ∈ (0, ∞) × [a, b] and the integral (2.11) is absolutely convergent.Then (2.12) for all k ≥ 0, provided that the integral on the right-hand side is finite.
Proof.For all t ∈ (0, ∞) and for any degree k ≥ 0, since g t (x) is continuous over the compact interval [a, b] there exists a unique polynomial p This is well defined: for all x ∈ [a, b], the mapping t → p We want to show that p k (x) is also a polynomial.Consider the expression which defines the coefficients a i (t) as functions of t.Formally, we have where āi := ∞ 0 a i (t) dt.To conclude, we need to show that this expression is well defined, that is, the functions a i (t) are integrable in t.
, we obtain the expression where c ij is independent of t for all i, j.This shows that, for all i, a i (t) is continuous for t ∈ (0, ∞), and we have hence āi is well defined for i = 0, . . ., k and p k (x) is a polynomial of degree at most k.Finally, we have This concludes the proof.
The following result gives a new bound for Theorem 2.2.Let 0 ≤ a < b and γ = a/b.We have since k ≥ 2 and we can ignore terms of degree 1 for the polynomial approximation.For x ∈ [γ, 1] we can use the representation (2.10).Let g t (x) := x(1−x) (1+t)(x+t) be the integrand in (2.10) for all t > 0. Note that g t (x) is a continuous fuction in the variables (t, x) ∈ (0, ∞) × [a, b], so we can apply Lemma 2.1.Then can we write g t (x) as (2.14) and since k ≥ 2 and 1 − x 1+t has degree 1, we get that Hence, by using (2.5) and Lemma 2.1 we get (2.15) where κ(t) = (1 + t)/(γ + t).In order to bound the integral, consider the identities We have By checking the derivative, it can be shown that .
Remark 2.3.The result of Theorem 2.2 is an improvement of (2.7).When a > 0, the right-hand side in (2.13) is the product of an algebraic and a geometric factor, so the decay is asymptotically faster.When a = 0, we have γ = 0 and (2.13) becomes , which is better than (2.7) for all k ≥ 2. The new bound (2.13) is compared with (2.7) in Figure 1.

Trace estimation
Recall that a function f (A) of a symmetric matrix A ∈ R n×n can be defined via a spectral decomposition A = U ΛU T , where U is orthogonal and Λ = diag(λ 1 , . . ., λ n ) is the diagonal matrix containing the eigenvalues.Then provided that f is defined on the eigenvalues of A. A matrix function can be computed via diagonalization, using polynomial or rational approximants, or with algorithms tailored to specific matrix functions, such as scaling and squaring for the matrix exponential.We direct the reader to [38] for more details on these methods.In this section we present algorithms to estimate the trace of f (A) that do not require the explicit computation of the diagonal entries of f (A).It is necessary to resort to this class of algorithms whenever the size of A is too large to make the computation of f (A) (or its diagonal) feasible.In the sections that follow, we prefer to use the notation A instead of ρ for matrices, since most of our results are applicable in general for symmetric positive semidefinite matrices, and not only to density matrices.
3.1.Probing methods.Let us summarize the approach described in [29] to compute the trace of a matrix function f (A), where A ∈ R n×n is a sparse matrix.Recall that the graph G(A) associated with A has nodes V = {1, . . ., n} and edges E = {(i, j) : [A] ij = 0, i = j}, and the geodesic distance d(i, j) between i and j is the shortest length of a walk that starts with i and ends with j, and is ∞ if no such walk exists or 0 if i = j.Let V 1 , . . ., V s be a coloring (i.e. a partitioning) of the set {1, . . ., n}.We write col(i) = col(j) if and only if i and j belong to the same set.We have a distance-d coloring if col(i) = col(j) whenever d(i, j) ≤ d, where d(i, j) is the geodesic distance between i and j in the graph G(A) associated with A. The associated probing vectors are where e i is the i-th vector of the canonical basis.The induced approximation of the trace is The problem of finding the minimum number s of colors, or sets, in the partition needed to get a distance-d coloring for a fixed d is NP-complete for general graphs [41].It is important to keep s as small as possible since, in view of (3.2), it is the number of quadratic forms needed to compute T d (f (A)).A greedy and efficient algorithm to get a quasi optimal distance-d coloring is given by Algorithm 1 [53,Algorithm 4.2].

Algorithm 1 Greedy algorithm for a distance-d coloring
col(i) = min{k > 0 : k = col(j) for all j ∈ W i } 5: end for One can obtain different colorings depending on the order of the nodes; sorting the nodes by descending degree usually leads to a good performance [53,41].The number of colors obtained with this algorithm is at most ∆ d +1, where ∆ is the maximum degree of a node in the graph induced by A, and the cost is at most O(n ∆ d ) if the d-neighbors W i of each node i are computed with a traversal of the graph.Alternatively, the greedy coloring can be obtained by computing A d , which can be done using at most 2 log 2 d matrix-matrix multiplications [38,Section 4.1].In our Matlab implementation of the probing method, we construct the greedy distance-d coloring by computing A d , since we found it to be faster than the graph-based approach; this is likely due to the more efficient Matlab implementation of matrix-matrix operations. If This coloring is optimal with s = dβ + 1 if all the entries within the band are nonzero.Note that to diagonalize a symmetric banded matrix one must first reduce it to a tridiagonal form, and this costs O(βn 2 ) [54].On the other hand, if we assume that quadratic forms with f (A) can be approximated with a fixed number of Krylov iterations, the computation of each quadratic form costs O(βn), and the cost for T d (f (A)) is approximatively O(dβ 2 n) and this can be much less than the cost for the diagonalization provided that the requested accuracy is not too high.For a general sparse matrix A, as an alternative to Algorithm 1 one can use the reverse Cuthill-McKee algorithm [20] to reorder the nodes and reduce the bandwidth, and then use (3.3) to find a distance-d coloring [29].Depending on the structure of the graph induced by A this can yield good results, but in many cases better colorings are obtained by using Algorithm 1; see Example 3.4.
Regarding the accuracy of the approximation of tr(f (A)) by T d (f (A)) we have the following result [29,Theorem 4.4].
, so that tr(f (A)) = S(A), we have the following result.
Remark 3.3.The bound (3.5) can be pessimistic in practice, especially for large values of d.We will see this in Example 3.4 and in Section 6.2.A priori bounds based on polynomial approximations often fail to catch the exact convergence behavior in many problems related to matrix functions since a minimization problem over the spectrum of a matrix is relaxed to the whole spectral interval.This occurs in the convergence of polynomial Krylov methods [43,Section 5.6] and in the decay bounds on the entries of matrix functions [9,28].Also, the coloring we get via Algorithm 1 can return far more colors than needed for a distance-d coloring, and this can benefit the convergence in a way that is not predicted by the bound.We will see in Section 5.1 a more practical heuristic to predict the error with higher accuracy.
Example 3.4.Let us see how the bound and the convergence of the probing method perform in practice.We use the density matrix ρ = L/ tr(L), where L is the Laplacian of the graph minnesota from the SuiteSparse Matrix Collection [21].More precisely, we consider the biggest connected component whose graph Laplacian has size n = 2640 and 9244 nonzero entries.
For several values of d, we compute the approximation T d (−ρ log ρ) associated with two different distance-d colorings: the first is obtained by the greedy coloring (Algorithm 1) after sorting the nodes by descending degree, while for the second we use the reverse Cuthill-McKee algorithm to get a 67-banded matrix and then (3.3).
In Figure 2 we compare T d (−ρ log(ρ)) with the value of S(ρ) obtained by diagonalizing ρ, considered as exact.The left plot shows the error in terms of the number of colors (i.e. the number of probing vectors) associated with the distance-d colorings.In the right plot the errors are shown in terms of d together with bound (3.6), where b = λ max (ρ).
For a fixed value of d, the coloring based on the bandwidth provides a smaller error than the greedy one, but it also uses a larger number of colors.Indeed, we can see from the left plot that with the same computational effort the greedy algorithm obtains a smaller error.On the right we can observe that bound (3.6) is close to the error given by the greedy coloring for small values of d, while it fails to catch the convergence behavior for large values of d.
For the graph entropy, i.e. when ρ = L/ tr(L) and L is a graph Laplacian of a graph G, we can show that − T d (ρ log ρ) is a lower bound for S(ρ).In the proof we use the fact that ρ is a symmetric M -matrix [14, Chapter 6], i.e. it can be written in the form ρ = θI − B where θ > 0 and B is a nonnegative matrix such that λ ≤ θ for all λ ∈ σ(B).
it can be represented by the power series Since σ(A) ⊂ (θ − B 2 , θ + B 2 ), the series expansion holds for f (A): If A is singular, consider the nonsingular M -matrix A+ I for > 0. Then the results hold for f (A+ I) (we impose θ+ < exp(−1) if θ < exp(−1)) and notice that f (A) = lim →0 f (A+ I).This concludes the proof, since the limit of nonsingular M -matrices is an M -matrix.Proposition 3.6.Let A ∈ R n×n be a symmetric M -matrix, and let . ., V s is the graph partitioning associated with a distance-d coloring, the error of the approximation can be written as see [29] for more details.By definition of a distance-d coloring, for all i, j ∈ V , i = j, we have Then, in view of Lemma 3.5, the right-hand side of (3.7) is nonnegative.
Remark 3.7.In this work we only consider the entropy of sparse density matrices.However, an important case is given by ρ = g(H), where H is the Hamiltonian of a certain quantum system and g is a function defined on the spectrum of H. Notable examples are the Gibbs state [19,57] and the Fermi-Dirac state [1].Despite ρ being a dense matrix in general, a sparse structure of H implies that ρ exhibits decay properties and can be well approximated by a sparse matrix [6,7].Moreover, since S(ρ) = −g(H) log(g(H)) one can apply the techniques described in this section to the composition −g(x) log(g(x)).Although the investigation of this problem is outside the scope of this work, it represents an interesting direction for future research.These considerations also hold for the randomized techniques discussed below.
3.2.Stochastic trace estimation.Let us consider the problem of computing tr(B), where B ∈ R n×n is a matrix that is not explicitly available but can be accessed via matrix-vector products Bx and quadratic forms x T Bx, for x ∈ R n .The case of B = f (A) can be seen as an instance of this problem, since f (A) is expensive to compute, but f (A)x and x T f (A)x can be efficiently approximated using Krylov methods, as we recall in Section 4. Stochastic trace estimators compute approximations of tr(B) by making use of the fact that, for any matrix B and any random vector , where E denotes the expected value.Hutchinson's trace estimator [39] is a simple stochastic estimator that generates N vectors x 1 , . . ., x N with i.i.d.random N (0, 1) entries and approximates tr(B) with An algorithm that improves the convergence properties of Hutchinson's estimator has been proposed in [47] with the name of Hutch++.It samples Ω ∈ R n×Nr with random i.i.d.N (0, 1) entries, then computes BΩ and an orthonormal basis Q ∈ R n×Nr of range(BΩ).Then the estimator is given by (3.9) tr Hutch++ Nr,N H (B) := tr(Q T BQ) + tr Hutch N H ((I − QQ T )B(I − QQ T )).This estimator computes the trace of a rank N r approximation of B and estimates the trace of the remaining part using the Hutchinson estimator with N H samples, so its total cost is N r matrix-vector products and N r + N H quadratic forms with B. It has been proven in [47,Theorem 4.1] that the complexity of Hutch++ is optimal up to logarithmic factors amongst algorithms that access a positive semidefinite matrix B via matrix-vector products.
The implementation of Hutch++ proposed in [18] allows to prescribe a target accuracy > 0 and a failure probability δ ∈ (0, 1) in input and then choose adaptively the parameters N r and N H in order to get the tail bound (3.10) P |tr Hutch++ Nr,N H (B) − tr(B)| ≥ ≤ δ with as little computational effort as possible.This implementation goes under the name of adaptive Hutch++ and will be our stochastic estimator of choice for the von Neumann entropy in view of its flexibility and optimal convergence properties.Note that most of our theory for Krylov methods in Section 4 can be used in combination with any other stochastic estimator based on matrix-vector products and quadratic forms with B = f (A).For instance, we mention [52] where a low rank approximation of A constructed using powers of A is used to get a good approximation in case of fast decaying eigenvalues or large spectral gaps, and the paper [16] in which a Krylov subspace projection is integrated with the low rank approximation.Furthermore, our theory in Section 4 also applies to the techniques presented in the recent preprint [25] which improves on standard Hutch++ but does not allow an adaptive choice of the parameters as in adaptive Hutch++.

Computation of quadratic forms with Krylov methods
As shown in Section 3, the approximate computation of tr(f (A)) with probing methods or stochastic trace estimators can be reduced to the computation of several quadratic forms with f (A), i.e. expressions of the form b T f (A)b.In this section, we briefly describe how they can be efficiently computed using polynomial and rational Krylov methods.
A polynomial Krylov subspace associated to A and b is given by More generally, given a sequence of poles {ξ j } j≥1 ⊂ (C ∪ {∞}) \ σ(A) ∪ {0}, we can define a rational Krylov subspace as follows, where coincides with the polynomial Krylov subspace P m (A, b), so P m (A, b) can be considered as a special case of Q m (A, b).Note that this definition of q m−1 does not allow us to have poles ξ j = 0; this can be fixed by changing the definition of q m−1 but it is not required in our case, since we are only going to use real negative poles and poles at ∞. Let us denote by V m = [v 1 . . .v m ] a matrix with orthonormal columns that spans the Krylov subspace Q m (A, b), and by A m = V T m AV m the projection of A onto the subspace.We can then project the problem on If the basis V m is constructed incrementally using the rational Arnoldi algorithm [51], we have Note that the approximation ψ m is closely related to the rational Krylov approximation of f (A)b, which is given by and is known to converge with a rate determined by the quality of rational approximations of f [35, Corollary 3.4].We refer to [34,35] for an extensive discussion on rational Krylov methods for the computation of matrix functions.The approximation (4.2) can be also interpreted in terms of rational Gauss quadrature rules, see for instance [2,50].
Remark 4.1.The standard Arnoldi algorithm is inherently sequential since the computation of the new vector of the Krylov basis v m+1 requires the previous computation of v m .It is possible to parallelize it by solving several linear systems simultaneously and expanding the Krylov basis with blocks of vectors, with one of the strategies presented in [13], at the cost of lower numerical stability.Since in this work we are expected to compute several quadratic forms b T f (A)b, we can easily achieve parallelization by assigning the quadratic forms to different processors and thus we can neglect parallelism inside the computation of a single quadratic form.Remark 4.2.We mention that for symmetric A it is possible to construct the Krylov basis V m using a method based on short recurrences such as rational Lanczos [48].This has the advantage of reducing the orthogonalization costs, which can become significant if m is large, and also avoids the need to store the matrix V m when approximating the quadratic form b T f (A)b, see (4.2).However, the implementation in finite arithmetic of short recurrence methods can suffer from loss of orthogonality, which in turn can lead to a slower convergence.In order to avoid this potential problem, we use the rational Arnoldi method with full orthogonalization.Since we expect to attain convergence in a small number of iterations, the orthogonalization costs remain modest compared to the cost of operations with A.
4.1.Convergence.By [35,Corollary 3.4], the accuracy of the approximation (4.3) for f (A)b is related to the quality of rational approximations to the function f of the form r(z) = q m−1 (z) −1 p m−1 (z), where p m−1 ∈ Π m−1 and q m−1 is determined by the poles of the rational Krylov subspace (4.1).
In the case of quadratic forms we can prove a faster convergence rate using the fact that ψ m = ψ for rational functions of degree up to By comparing Proposition 4.4 with [35, Corollary 3.4], we can expect the convergence for quadratic forms to be roughly twice as fast as the one for matrix-vector products with f (A).

4.2.
Poles for the rational Krylov subspace.Recall that the function f (z) = x log x has the integral expression (2.10), which corresponds to a Cauchy-Stieltjes function multiplied by the polynomial x(1 − x).This implies that we can expect that a pole sequence that yields fast convergence for Cauchy-Stieltjes functions will be also effective in our case, especially if we add two poles at ∞ to account for the degree-two polynomial.
The authors of [45] consider the case of a positive definite matrix A with spectrum in [a, b] and a Cauchy-Stieltjes function f , and relate the error for the computation of f (A)b with a rational Krylov method to the third Zolotarev problem in approximation theory.The solution to this problem is known explicitly and it can be used to find poles on (−∞, 0) that provide in some sense an optimal convergence rate for the rational Krylov method [45,Corollary 4].However, the optimal Zolotarev poles are not nested, so they cannot be used to expand the Krylov subspace incrementally, and they are practical only if one knows in advance how many iterations to perform, for instance by relying on an a priori error bound.This drawback can be overcome by constructing a nested sequence of poles that is equidistributed according to the limit measure identified by the optimal poles, which can be done with the method of equidistributed sequences (EDS) described in [45,Section 3.5].These poles have the same asymptotic convergence rate as the optimal Zolotarev poles and are usually better for practical purposes.To be computed, they require the knowledge of [a, b] or a positive interval Σ such that [a, b] ⊂ Σ.
As an alternative, one can also use poles obtained from Leja-Bagby points [3,35].These points can be computed with an easily implemented greedy algorithm and they have an asymptotic convergence rate that is close to the optimal one.See [35,Section 4] and the references therein for additional information.
Remark 4.5.For the function f (x) = x log x, the first few iterations of a polynomial Krylov method have a fast convergence rate that is close to the convergence rate of rational Krylov methods, even if it becomes asymptotically much slower for ill conditioned matrices.The faster initial convergence can be explained by the algebraic factor in the bound (2.13) for polynomial approximations of x log x.Since polynomial Krylov iterations are cheaper than rational Krylov iterations, this suggests the use of a mixed polynomial-rational method, that starts with a few polynomial Krylov steps and then switches to a rational Krylov method with, e.g., EDS poles to achieve a higher accuracy.These methods are compared numerically in Example 4.10, where we also test the performance of the a posteriori error bound that we prove in Section 4.3.
Remark 4.6.Note that in the context of the graph entropy the matrix A is a graph Laplacian, which is a singular matrix.Therefore in principle it is not possible to use the poles described in this section, since here we assume that A is positive definite.However, we can use one of the desingularization strategies described in [11] to remove the 0 eigenvalue of the graph Laplacian, obtaining a matrix with spectrum contained in [λ 2 , λ n ], where λ 2 is the second smallest eigenvalue of A and λ n is the largest one.In our implementation we use the approach that is called implicit desingularization in [11], which consists in replacing the initial vector b for the Krylov subspace with c = b − 1 T b n 1, where 1 is the vector of all ones.Since c is orthogonal to the eigenvector 1 associated to the eigenvalue 0, it can be shown that the convergence of a Krylov subspace method with starting vector c is the same as for a matrix with spectrum in [λ 2 , λ n ].An approximation of f (A)b can be then cheaply recovered from f (A)c using the fact that f (A)1 = f (0)1, and similarly for b T f (A)b.See [11] for more details.

4.3.
A posteriori error bound.In this section we prove an a posteriori bound for the error in the computation of the quadratic form b T f (A)b with a rational Krylov method.This bound is a variant of the one described in [34, Section 6.6.2] for f (A)b, modified in order to account for the faster convergence rate in the case of quadratic forms.
We recall that after m iterations the rational Arnoldi algorithm yields the rational Arnoldi decomposition [12, Definition 2.3] (4.4) where span V m+1 = Q m+1 (A, b) and K m , H m are (m + 1) × m upper Hessenberg matrices with full rank.Let us consider the situation when ξ m = ∞: in this case the last row of K m is zero, and the decomposition simplifies to where H m and K m denote the m × m leading principal blocks of H m and K m , respectively, and h T m+1 = h m+1,m e T m denotes the last row of H m .Note that K m is nonsingular since K m has full rank, so we can rewrite the decomposition as To derive the bound, we assume that ξ m = ∞ because it simplifies the rational Arnoldi decomposition and hence the expression of the bound.Such an assumption is not restrictive, since the value of ξ m does not have any impact on V m and A m , but only on v m+1 and the last column of H m and K m .As we shall see later, we can use a technique described in [34, Section 6.1] to compute the bound for all m, without having to set the corresponding poles ξ m = ∞.Note that if ξ m = ∞, then (4.5) does not hold, and in particular V T m AV m = H m K −1 m .By using the Cauchy integral formula for f , we can obtain the following expression for the error [34, Section 6.2.2]: where Γ is a contour contained in the region of analyticity of f that encloses the spectrum of A, and , which can be seen as a residual vector of the shifted linear system (zI where we exploited the fact that x m (z) ∈ Q m (A, b) ⊥ r m (z).
By using this property in conjunction with (4.6), we can write the error for the quadratic form b T f (A)b as (4.7) We can now follow the same steps used in [34, Section 6.
where we defined γ j = : =j α β 1 θ j − θ .By plugging this expression into (4.7)we get where for the last equality we used the residue theorem [37, Theorem 4.7a].
Let us define where the expression for z = θ j is obtained by taking the limit for z → θ j in the definition for z = θ j .The above computations immediately lead to the following a posteriori bound for the quadratic form error. Remark 4.9.We are mainly interested in the upper bound in (4.9) to have a reliable stopping criterion for the rational Krylov method, although the lower bound can also be of interest.We also mention that other bounds and error estimates can be obtained, such as the other ones described in [34, Section 6.6], but we found that the one derived in this section worked well enough for our purposes.Under certain assumptions, it is also possible to obtain upper and lower bounds for the quadratic form b T f (A)b using pairs of rational Gauss quadrature rules, such as Gauss and Gauss-Radau quadrature rules.We refer to [2] for more details.
Example 4.10.In this example we test the accuracy of the lower and upper bounds given in (4.9) for polynomial and rational Krylov methods.We consider the computation of b T f (A)b, for a 2000 × 2000 matrix A with eigenvalues given by the Chebyshev points for the interval Σ = [10 −3 , 10 3 ], a random vector b and f (x) = x log(x).The upper and lower bounds are computed numerically by evaluating g m on a discretization of the interval [λ min , λ max ].In addition to the lower and upper bounds, we also consider a heuristic estimate of the error given by the geometric mean of the upper and lower bound in (4.9), i.e.The results are shown in Figure 3. On the left plot we show the convergence for the polynomial Krylov method and for a rational Krylov method with poles from an EDS for Cauchy-Stieltjes functions, and on the right plot a mixed polynomial-rational method that uses 10 poles at ∞ (which correspond to polynomial Krylov steps) followed by 10 EDS poles (see Remark 4.5).
The upper and lower bounds match the shape of the convergence curve quite well, although they are less accurate when polynomial iterations are used.Rather surprisingly, the geometric mean of the bounds gives a very accurate estimate for the error, even in the case when the bounds themselves are less accurate.
Remark 4.11.We do not have a rigorous explanation for the accuracy of the estimate based on the geometric mean of the bounds in (4.9), but from further experiments it seems to be very accurate also for other functions.Unfortunately, if the spectral interval Σ is known only approximately, the bounds become less tight and the geometric mean estimate usually ends up underestimating the actual error by one or two orders of magnitude.Recall that the a posteriori bounds in (4.9) hold after the m-th iteration only if ξ m = ∞.In a practical scenario, i.e. when using the bounds as a stopping criterion for a rational Krylov method, it is desirable to evaluate the bounds after each iteration, without being forced to set the corresponding pole to ∞.As anticipated in Remark 4.7, we provide here two approaches to evaluate the bounds in (4.9) even when ξ m = ∞.
One way to avoid setting poles to ∞, proposed in [34, Section 6.1], is to use an auxiliary basis vector v ∞ , which is initialized as v (1) ∞ = Av 1 at the beginning of the rational Arnoldi algorithm, and maintained orthonormal to the basis vectors {v 1 , . . ., v j } at each iteration j, at the cost of only one additional orthogonalization per iteration.The basis ∞ ] is an orthonormal basis of the rational Krylov subspace Q j+1 (A, b) with poles {ξ 1 , . . ., ξ j−1 , ∞}, and it is associated to the auxiliary Arnoldi decomposition where K j e j = e 1 and the last column of H j contains the orthogonalization coefficients for v (j) ∞ .This decomposition can be used to compute the bound (4.9) since the last row of K j is zero by construction.Remark 4.12.We point out that if ξ j = ∞ for some j, then the approach described above will not work from iteration j + 1 onward, since Av 1 ∈ Q j+1 (A, b) and therefore v (j+1) ∞ = 0 after orthogonalization.This is easily fixed by switching to a different auxiliary vector at iteration j + 1, such as v ∞ = Av j+1 , or by setting directly at the start v ∞ = A +1 v 1 , where is the number of poles at ∞ used to construct the rational Krylov subspace.
In our experience, the technique described above can be sometimes subject to instability due to a large condition number of the matrix K j .We therefore also propose another approach, which is inspired by the methods for moving the poles of a rational Krylov subspace presented in [12,Section 4].The idea is to add a pole at ∞ at the beginning of the pole sequence, and reorder the poles at each iteration in order to always have the last pole equal to ∞.
First of all, we recall how to swap poles in a rational Arnoldi decomposition.This procedure is a special case of the algorithm described in [12], but we still describe it in some detail for completeness.Recall that the poles of a rational Krylov subspace are the ratios of the entries below the main diagonals of H j and K j [12, Definition 2.3], i.e. ξ j = h j+1,j /k j+1,j .In other words, the poles {ξ 1 , . . ., ξ j } are the eigenvalues of the upper triangular pencil ( H j , K j ), where we denote by H j the bottom j × j block of H j , and similarly for K j .So we can obtain a transformation that swaps two adjacent poles in the same way as orthogonal transformations that reorder eigenvalues in a generalized Schur form [40]. Let U j and W j be j × j orthogonal matrices such that the pencil U T j ( H j , K j )W j is still in upper triangular form and has the last two eigenvalues in reversed order; the matrices U j and W j only involve 2 × 2 rotations, and they can be computed and applied cheaply as described in [40].Defining U j = blkdiag(1, U j ) ∈ R (j+1)×(j+1) , we have the new rational Arnoldi decomposition This decomposition has the same poles as AV j+1 K j = V j+1 H j , with the difference that the last two poles ξ j−1 and ξ j are now swapped.In particular, if ξ j−1 = ∞, the last pole of the new decomposition is now ∞, and hence the last row of K j is equal to zero.
Given the pole sequence {ξ 1 , ξ 2 , . . .}, let us consider the rational Krylov subspace associated to the modified pole sequence {∞, ξ 1 , ξ 2 , . . .}. Clearly, after the first iteration both pole sequences identify the same subspace Q 1 (A, b), but the last (and first) pole of the modified sequence is ∞, so the last row of K 1 is zero and we can use the decomposition AV 1 K 1 = V 2 H 1 to compute the bound (4.9).After the second iteration, if ξ 1 = ∞, we can swap the poles ξ 1 and ∞ with the procedure outlined above to obtain the decomposition AV 2 K 2 = V 3 H 2 associated to the poles {ξ 1 , ∞}, where again the last row of K 2 is equal to zero (for simplicity we still use the notation K j instead of K j , and similarly for V j and H j ).If ξ 1 = ∞, there is no need to swap poles and we can proceed to the next iteration.
By repeating the same steps at each iteration, we can ensure that after j iterations we have a decomposition AV j K j = V j+1 H j , associated to the poles {ξ 1 , . . ., ξ j−1 , ∞} in this order, so that the last row of K j is equal to zero and it can be used to compute the bound (4.9).Remark 4.13.Note that V j is a basis of Q j (A, b), which is the same subspace that we would have obtained if we had run the rational Arnoldi algorithm with poles {ξ 1 , . . ., ξ j−1 }; so the method described in this section actually computes the approximation ψ j and the bound associated to the poles {ξ 1 , . . ., ξ j−1 }, and not to the modified pole sequence {∞, ξ 1 , . . ., ξ j−2 }.The initial pole at ∞ is only added to enable the computation of the bound and it is never used in the actual approximation.

Implementation aspects
In this section we outline the algorithm used to compute the entropy obtained by connecting the different components presented in the previous sections, and we briefly comment on some of the decisions that have to be taken in an implementation, especially concerning stopping criteria.Given a symmetric positive semidefinite matrix A with tr(A) = 1 and a target relative accuracy , the algorithm should output an estimate trest of tr(f (A)), where f (x) = −x log x, such that |tr(f (A)) − trest| ≤ tr(f (A)), using either the probing approach of Section 3.1 or a stochastic trace estimator from Section 3.2.Observe that the entropy of an n × n density matrix is always bounded form above by log n, but it may be in principle very small, so we prefer to aim for a certain relative accuracy rather than an absolute accuracy.Quadratic forms and matrix-vector products with f (A) are computed using Krylov methods, specifically using a certain number of poles at ∞ followed by the EDS poles described in Section 4.2.
Remark 5.1.In the following, we are going to use ˆ to denote an absolute error, to distinguish it from the target relative accuracy .Note that we can easily transform absolute inequalities for the error into relative inequalities if we know in advance an estimate or a lower bound for tr(f (A)).Recall that if A is an M -matrix, T d (f (A)) is actually a lower bound for tr(f (A)) (Proposition 3.6).In the general case, any rough approximation of the entropy can be used for this purpose, since the important point is determining the order of magnitude of tr(f (A)).
Remark 5.2.The error in the approximation of S(A) can be divided into the error in the approximation of the trace using a probing method or a stochastic estimator, and the error in the approximation of the quadratic forms with f (A) using a Krylov subspace method.For simplicity, in the following we impose that the relative error associated to each of these two components is smaller than /2.5.1.Probing method implementation.We begin by observing that it is not possible to cheaply estimate the error of a probing method a posteriori, since error estimates are usually based on approximations with different values of the distance d, which in general lead to completely different colorings that would require computing all quadratic forms from scratch.
For this reason, it is best to find a value of d that ensures a relative accuracy a priori when using a distance-d coloring.This can be done using one of the bounds in Corollary 3.2, but it can often lead to unnecessary additional work, since the bounds usually overestimate the error by a couple of orders of magnitude; see Figure 2. Therefore we also provide a heuristic criterion for choosing d that does not have the same theoretical guarantee as the bounds, but appears to work quite well in practice.In view of Corollary 3.2, we can expect the absolute error to behave as for k = 2 and some parameters C > 0 and q ∈ (0, 1).However, we found that sometimes the actual error behavior is better described with a different value of k, such as k = 3, so we do not impose that k = 2.To estimate the values of the parameters, we compute T d (f (A)) for d = 1, 2, 3 and use the estimate Assuming that (5.1) holds exactly and fixing the value of k, we can determine C and q by solving the equations We can check when the resulting estimate is below ˆ to heuristically determine d, i.e., we select d as d = min d : C d k q d ≤ ˆ , in order to have the approximate absolute error inequality We found that the best results are obtained for k = 2 and k = 3, so in our implementation we use the maximum of the two corresponding estimates.Variants of this estimate include using other values of d to estimate the parameters instead of d = 1, 2, 3, and using four different values in order to also estimate the parameter k.However, they usually give results that are similar or sometimes worse than the estimate presented above, so they are often not worth the additional effort required to compute them.In particular, using four values of d raises the risk of misjudging the value of q, causing the estimate to be inaccurate for large values of d.The error estimate (5.1) is compared to the actual error and the theoretical bound (3.5) for two different graphs in Figure 4.The figure also includes a simple error estimate based on consecutive differences, which requires the computation of T d+1 (f (A)) to estimate the error for T d (f (A)).
Remark 5.3.The heuristic criterion for selecting d requires the computation of T d (f (A)) for d = 1, 2, 3, so it is more expensive to use than the theoretical bound (3.5).However, this cost is usually small compared to the cost of computing T d (f (A)) for the selected value of d, especially if the requested accuracy is small.Note also that the heuristic criterion always computes T 3 (f (A)), so it does more work than necessary when d ≤ 2 would be sufficient.Nevertheless, in such a situation the theoretical bound (3.5) may suggest to use an even higher value of d (see Figure 4).
After choosing d such that using either the a priori bound (3.5) or the estimate (5.1), a distance-d coloring can be computed with one of the coloring algorithms described in Section 3.1, depending on the properties of the graph.The greedy coloring [53, Algorithm 4.2] is usually a good choice for general graphs.Let us now determine the accuracy required in the computation of the quadratic forms.Assume that we have where {v } s =1 are the probing vectors used in the distance-d coloring.Let ψ denote the approximation of v T f (A)v obtained with a Krylov method.Recall that v 2 = |V | 1/2 , where V denotes the set of the partition associated to the -th color.If we impose the conditions where we normalized the accuracy requested for each quadratic form depending on v 2 , we obtain the desired absolute accuracy on the probing approximation (5.4) If we are aiming for a relative accuracy , we should select ˆ = 1 2 tr(f (A)) in (5.2) and (5.4).In practice, tr(f (A)) will be replaced by a rough approximation (see Remark 5.1).
The overall probing algorithm is summarized in Algorithm 2.

5.2.
Adaptive Hutch++ implementation.We use the Matlab code of [49,Algorithm 3] provided by the authors, modified to use Krylov methods for the computations with f (A).This algorithm requires an absolute tolerance ˆ and a failure probability δ, and outputs an approximation tr adap (f (A)) such that To obtain an approximation within a relative accuracy , we can use ˆ ≈ tr(f (A)), using a rough approximation of tr(f (A)).Similarly to the probing method, in order to have a final relative error bounded by , in our implementation we use a tolerance ˆ ≈ 1 2 tr(f (A)) for adaptive Hutch++, and we set the accuracy for the computation of matrix-vector products and quadratic forms in order to ensure that the total error due to the Krylov approximations remains below 1  2 tr(f (A)).We omit the technical details to simplify the presentation.5.3.Krylov method implementation.Quadratic forms with f (A) are approximated using a Krylov method with some poles at ∞ followed by the EDS poles of Section 4.2, using as a stopping criterion either the a posteriori upper bound (4.9) or the estimate shown in Example 4.10.
The number of poles at ∞ is chosen in an adaptive way, switching to finite poles when the error reduction in the last few iterations of the polynomial Krylov method is "small".Specifically, we decide to switch to EDS poles after the k-th iteration if on average the last ≥ 1 iterations did not reduce the error bound or estimate err_est by at least a factor c ∈ (0, 1), i.e. if err_est k err_est k− −1 ≥ c .
In our implementation we use = 3 and c = 0.75, usually leading to at most 10 polynomial Krylov iterations.Since EDS poles are contained in (−∞, 0), each rational Krylov iteration involves the solution of a symmetric positive definite linear system, which can be computed either with a direct method using a sparse Cholesky factorization, or iteratively with the conjugate gradient method using a suitable preconditioner.Note that the same EDS poles can be used for all quadratic forms, so the number of different matrices that appear in the linear systems is usually small and independent of the total number of quadratic forms.Although this depends on the accuracy requested for the entropy, the number of EDS poles used is almost always bounded by 10, and often much smaller than that: see the numerical experiments in Section 6 for some examples.This is a great advantage for direct methods, especially when the Cholesky factor remains sparse, since we can compute and store a Cholesky factorization for each pole and then reuse it for all quadratic forms.If the fill-in in the Cholesky factor is moderate, the cost of a rational iteration can become comparable to the cost of a polynomial one, leading to large savings when computing many quadratic forms.Of course, for large matrices with a general sparsity structure the computation of even a single Cholesky factor may be unfeasible, so the only option is to use a preconditioned iterative method.In such a situation, it is still possible to benefit from the small number of different matrices that appear in linear systems by storing and reusing preconditioners, but the gain is less evident compared to direct methods.
The matrix-vector products with f (A) in the Hutch++ algorithm are approximated with the same Krylov subspace method, with the difference that we use the a posteriori upper and lower bounds from [34, eq. (6.15)].A geometric mean estimate similar to the one used in Example 4.10 can be also used in this context.For the computation of the a posteriori bounds we use the pole swapping technique with an auxiliary pole at ∞ described in Section 4.3.1.

Numerical experiments
The experiments were done in Matlab R2021b on a laptop with operating system Ubuntu 20.04, using a single core of an Intel i5-10300H CPU running at 2.5 GHz, with 32 GB of RAM.Since we are using Matlab, the execution times may not reflect the performance of a high performance implementation, but they are still a useful indicator when comparing different methods.
6.1.Test matrices.We consider a number of symmetric test matrices from the SuiteSparse Matrix Collection [21].All matrices are treated as binary matrices, i.e. all edge weights are set to one.For each matrix, we extract the graph Laplacian associated to the largest connected component and we normalize it so that it has unit trace.We report some information on the resulting matrices in Table 1.For the four smallest matrices, the eigenvalues were computed via diagonalization, while for the larger matrices the eigenvalues λ 2 and λ n were approximated using eigs.The cost of solving a linear system with a direct method is highly dependent on the fill-in in the Cholesky factorization; the column labelled fill-in in Table 1 contains the ratios nnz(R)/nnz(ρ), where ρ is the test matrix and R is the Cholesky factor of any shifted matrix ρ + αI, for α > 0 (nnz(M ) denotes the number of nonzeros of a matrix M ).All matrices have been ordered using the approximate minimum degree reordering option available in Matlab before factorization.6.2.Probing bound vs. estimate.In this experiment, we fix a relative error tolerance = 10 −3 and we compare the choice of d given by the theoretical bound (3.5) with the one provided by the heuristic estimate (5.1).We report in Table 2 the error, the execution time, the value of d and the number of colors used in the two cases.When the theoretical bound is used, the selected value of d is significantly higher compared to the one chosen by the heuristic estimate, but in both cases the overall error remains below the tolerance .Moreover, for certain graphs using the theoretical bound leads to greedy colorings with a number of colors equal to the number of nodes in the graph, completely negating the advantage of using a probing method.Observe that the errors obtained with the larger value of d are not much smaller than the ones for the smaller value of d, because in both cases the quadratic forms are computed with target relative accuracy , so the probing error for the larger value of d is dominated by the error in the quadratic forms.In the case of the heuristic estimate, the execution time includes the time required to run the probing method for d = 1, 2, 3 in order to evaluate (5.1).The stopping criterion for the Krylov subspace method uses the upper bound (4.9).The execution time can be further reduced by using the estimate (4.10) for the Krylov subspace method, as the following experiment shows.The diagonalization time for the matrices used in this experiment can be found in the last column of Table 4.Note that for smaller matrices, diagonalization is often the fastest method, but the advantage of approximating the entropy with a probing method is already evident for matrices of size n ≈ 10000.for the Krylov subspace method.The value of d for the probing method is selected using the heuristic estimate (5.1).The entropy error, execution time, and total number of polynomial and rational Krylov iterations are reported in Table 3.We can see that using the estimate instead of the theoretical bound moderately reduces the computational effort, while still attaining the requested accuracy on the entropy.In particular, observe that the number of rational Krylov iterations is significantly higher when using the upper bound (4.9).In this experiment, all linear systems are solved with direct methods and Cholesky factorizations are stored and reused., where S(ρ) is computed via diagonalization and considered as exact.The computational effort of Hutch++ is determined by the parameters N r and N H described in Section 3.2.In particular, the number of matrix-vector products is equal to N r and the number of quadratic forms is equal to N r + N H .We used = 10 −2 , 10 −3 as target tolerances and δ = 10 −2 as failure probability.Matrix-vector products and quadratic forms are computed using the Krylov subspace method with the geometric mean estimate as a stopping criterion (4.10).In Table 4 we compare the results for the two tolerances, obtained as an average of 100 runs of the algorithm, including both the average and worst relative error.In the majority of cases, the worst error is below the input tolerance .We see that for = 10 −2 the computation with Hutch++ is very fast for all test matrices; on the other hand, the cost becomes significantly higher for = 10 −3 , showing that the stochastic estimator quickly becomes inefficient as the required accuracy increases.Observe that for = 10 −2 adaptive Hutch++ uses only 3 matvecs for all tests problems, which is the minimum amount that can be used by the implementation in [49].This means that the internal criteria of the algorithm have determined that spending more matvecs in the low rank approximation is not beneficial, and hence the convergence of the method is roughly the same as for Hutchinson's estimator.A similar behavior can be observed in Table 7, and can be linked to the fact that for these test matrices ρ, the matrix function −ρ log ρ does not exhibit eigenvalue decay and hence cannot be well-approximated by low rank matrices.On the other hand, for problems where low rank approximation is more effective, stochastic estimators that exploit it such as Hutch++ can have much faster convergence.
6.5.Larger matrices.In this section we test the probing method and the adaptive Hutch++ algorithm on larger matrices, for which it would be extremely expensive to compute the exact entropy.In light of the results shown in Tables 2 and 3, we select the value of d for the probing method using the heuristic estimate (5.1) and we use the geometric mean estimate (4.10) for the Krylov subspace method.The results are reported in Tables 5 and 6 for the probing method, and in Table 7 for Hutch++.Figure 5 contains a more detailed breakdown of the execution time for the probing method used on the matrices of Table 5.We separate the time in preprocessing, where we evaluate the heuristic (5.1) to select d, and the main run of the algorithm with the chosen value of d.The time for the main run is further divided in coloring, and polynomial and rational Krylov iterations.The time for the Cholesky factorizations refers to the whole process, since the factors are computed and stored when a certain pole for a rational Krylov iteration is encountered for the first time.
In Table 5, we consider matrices with a "large-world" sparsity structure, such as road networks, and we use a relative tolerance of = 10 −4 .For these matrices, for which the diameter and the average path length are relatively large, it is possible to compute distance-d colorings with a relatively small number of colors, and therefore probing methods converge quickly.Moreover, Cholesky factorizations can be computed cheaply and have a small fill-in, so it is possible to rapidly solve linear systems using a direct method.On the other hand, in Table 6 we consider matrices with a "small-world" sparsity structure, more typical of social networks and scientific collaboration networks.These matrices require a much larger number of colors to construct distance-d colorings, even for small values of d.The cost of probing methods is thus significantly higher on this kind of problem.In Table 6, only polynomial Krylov iterations are used due to the low relative tolerance = 10 −2 , so it is never necessary to solve linear systems.Recall that these matrices also have a high fill-in in the Cholesky factorizations (see Table 1), so the conjugate gradient method with a suitable preconditioner is likely to be much more efficient than a direct method for solving a linear system.In Table 7 we show the results for the adaptive Hutch++ algorithm, using relative tolerance = 10 −2 .The results are obtained as an average of 100 runs of the algorithm.We can observe  5. Table 6.Results for the probing method applied to test matrices with smallworld sparsity structure, using relative tolerance = 10 that the stochastic trace estimator works well for both large-world and small-world graphs, in contrast to the probing method.
6.6.Algorithm scaling.To investigate how the complexity of the algorithms scales with the matrix size, we compare the scaling of the probing method and the stochastic trace estimator on two different test problems with increasing dimension.The first one is the graph Laplacian of a 2D regular square grid, and the second one is the graph Laplacian of a Barabasi-Albert random graph, generated using the pref function of the CONTEST Matlab package [55].For the probing method on the 2D grid, we use the optimal distance-d coloring with 1 2 (d + 1) 2 colors described in [26].For both test problems, we use a relative tolerance = 10 −4 for the probing method, and a relative tolerance = 10 −2 and failure probability δ = 10 −2 for adaptive Hutch++, averaging over 100 runs.The results are summarized in Figure 6, for graphs with a number of nodes from n = 2 10 to n = 2 20 .As expected, the probing method is much more efficient in the case of the 2D grid, since the number of colors used in the distance-d colorings remains constant as n increases.On the other hand, for the Barabasi-Albert random graph, which has a small-world structure, the number of colors used in a distance-d coloring increases with the number of nodes, and hence the scaling for the probing method is significantly worse.The adaptive Hutch++ algorithm also has a better performance for the 2D grid, but the scaling in the problem size is good for both graph categories, since the number of vectors used in the trace approximation does not increase with the matrix dimension.However, the stochastic approach is only viable with a loose tolerance for this kind of problem since low rank approximation is not effective, as discussed in Section 6.4.The initial decrease in the execution time for Hutch++ as n increases is caused by the fact that the adaptive algorithm uses a larger number of vectors for the graphs with fewer nodes.

Conclusions
In this paper we have investigated two approaches for approximating the von Neumann entropy of a large, sparse, symmetric positive semidefinite matrix.The first method is a state-of-the-art randomized approach, while the second one is based on the idea of probing.Both methods require the computation of many quadratic forms involving the matrix function f (A) with f (x) = −x log x, an expensive task given the lack of smoothness of f (x) at x = 0. We have examined the use of both polynomial and rational Krylov subspace methods, and combinations of the two.Pole selection and several implementation aspects, such as heuristics and stopping criteria, have been investigated.Numerical experiments in which the entropy is computed for a variety of networks have been used to test the various approximation methods.Not surprisingly, the performance of the methods is affected by the structure of the underlying network, especially for the method based on the probing idea.Our main conclusion is that the probing approach is better suited than the randomized one for graphs with a large-world structure, since they admit distance-d colorings with a relatively small number of colors.Conversely, for complex networks with a small-world structure, the number of colors required for distance-d colorings is larger, so the probing approach becomes more expensive.For this type of graphs, the randomized method is more competitive than the one based on probing, since it is less affected by the structure of the graph; however, for matrices in which low rank approximation cannot be exploited such as the graph Laplacians that we consider, randomized trace estimators are best suited for computing approximations with a relatively low accuracy, since their cost quickly grows as the requested accuracy is increased.

2. 1 .
Polynomial approximation.Denote the set of all polynomials with degree at most k with Π k .For a continuous function f : [a, b] → R, define the error of the best uniform polynomial approximation in Π k as(2.4)

Figure 1 .
Figure 1.Comparison of the bounds (2.7) and (2.13) with the error of the polynomial approximation of the entropy function x log x on the interval [10 −6 , 10 −2 ].

Figure 2 .
Figure 2. Absolute errors of the probing approximation of S(ρ) where the distance-d coloring is obtained either by the greedy procedure (Algorithm 1) or with the reverse Cuthill-McKee algorithm and the coloring (3.3) for banded matrices.On the left the abscissa represents the number of colors used for the coloring.On the right the errors are compared with bound (3.6) in terms of d.
and it is an M -matrix since it is positive semidefinite[14, Theorem 4.6].
with k even can be proved in the same way, by writing b T r(A)b = b T s(A) 2 b, with s(z) = q m−1 (z) −1 z j , j < m.

Lemma 4 .
3 leads to the following convergence result for the approximation of quadratic forms, with the same proof as [35, Corollary 3.4].Proposition 4.4.Let A be symmetric with spectrum contained in [λ min , λ max ], ψ = b T f (A)b and denote by ψ m the approximation (4.2).We have

2 . 2 ]
to bound the integral in (4.7).Assume that A m has the spectral decomposition A m = U m D m U T m , with U m orthogonal and D m = diag(θ 1 , . . ., θ m ), and define the vectors

Figure 3 .
Figure 3. Accuracy of error bounds and estimates for the relative error in the computation of b T f (A)b with Krylov methods, where b is a random vector, f (x) = x log(x) and A is a 2000 × 2000 matrix with eigenvalues that are Chebyshev points in the interval [10 −3 , 10 3 ].Left: polynomial Krylov and rational Krylov with EDS poles for Cauchy-Stieltjes function.Right: 10 poles at ∞ and 10 EDS poles for Cauchy-Stieltjes functions.

Figure 4 .
Figure 4. Absolute error of the probing method with greedy coloring (Algorithm 1) compared with the theoretical bound (3.5) using a = λ 2 , the heuristic error estimate (5.1) and the simple error estimate |tr(f (A) − T d (f (A))| ≈ |T d+1 (f (A)) − T d (f (A))|.Left: Laplacian of the largest connected component of the graph minnesota, with 2640 nodes.Right: Laplacian of the largest connected component of the graph eris1176, with 1174 nodes.

Figure 5 .
Figure 5. Breakdown of the execution time of the probing method for the test matrices in Table5.

Figure 6 .
Figure 6.Execution times for the probing method (left, = 10 −4 ) and the adaptive Hutch++ algorithm (right, = 10 −2 ) on the graph Laplacian of a 2D regular grid and a Barabasi-Albert random graph, as a function of the number of nodes n.

Table 1 .
Information on the matrices used in the experiments.

Table 2 .
Comparison of the theoretical bound(3.5)against the heuristic estimate (5.1) for choosing d, using relative tolerance = 10 −3 in the probing method.Top row: heuristic estimate.Bottom row: theoretical bound.Krylov bound vs. estimate.We fix an error tolerance = 10 −5 and compare the performance of the geometric mean error estimate (4.10) with the theoretical upper bound (4.9)

Table 3 .
[49,arison of the upper bound (4.9) against the geometric mean estimate (4.10) for Krylov methods used in the probing method, using relative tolerance = 10 −5 for the probing method.Top row: geometric mean estimate.Bottom row: upper bound.Adaptive Hutch++.Here we test the performance and the accuracy of the adaptive implementation of Hutch++[49, Algorithm 3].A relative accuracy is achieved by setting the absolute tolerance to S(ρ)

Table 4 .
Results for Hutch++ applied to some test matrices.For each matrix, the first and second row show the results for = 10 −2 and = 10 −3 , respectively.The failure probability is δ = 10 −2 in both cases.The last column contains the diagonalization times.

Table 5 .
Results for the probing method applied to test matrices with largeworld sparsity structure, using relative tolerance = 10 −4 .

Table 7 .
Results for Hutch++ applied to large test matrices, with relative tolerance = 10 −2 and failure probability δ = 10 −2 .The parameters N r and N H are defined in Section 3.2.