---
abstract: |
    This article is concerned with Monte-Carlo methods for the estimation of the trace of an implicitly given matrix $A$ whose information is only available through matrix-vector products. Such a method approximates the trace by an average of $N$ expressions of the form ${ {\bf w} }^t (A{ {\bf w} })$, with random vectors ${ {\bf w} }$ drawn from an appropriate distribution. We prove, discuss and experiment with bounds on the number of realizations $N$ required in order to guarantee a probabilistic bound on the relative error of the trace estimation upon employing Rademacher (Hutchinson), Gaussian and uniform unit vector (with and without replacement) probability distributions.

    In total, one necessary bound and six sufficient bounds are proved, improving upon and extending similar estimates obtained in the seminal work of Avron and Toledo (2011) in several dimensions. We first improve their bound on $N$ for the Hutchinson method, dropping a term that relates to $rank(A)$ and making the bound comparable with that for the Gaussian estimator.

    We further prove new sufficient bounds for the Hutchinson, Gaussian and the unit vector estimators, as well as a necessary bound for the Gaussian estimator, which depend more specifically on properties of the matrix $A$. As such they may suggest for what type of matrices one distribution or another provides a particularly effective or relatively ineffective stochastic estimation method.
author:
- 'Farbod Roosta-Khorasani and Uri Ascher [^1]'
bibliography:
- 'biblio.bib'
title: Improved bounds on sample size for implicit matrix trace estimators
---

**Keywords**: randomized algorithms, trace estimation, Monte-Carlo methods, implicit linear operators

**Mathematics Subject Classification (2010)**: 65C20, 65C05, 68W20

Introduction {#sec:int}
============

The need to estimate the trace of an implicit square matrix is of fundamental importance @sdr and arises in many applications; see for instance @hutchinson [@bafago; @avto; @HaberChungHermann2010; @doas3; @yori; @rodoas1; @learhe; @gohewa; @avron] and references therein. By "implicit" we mean that the matrix of interest is not available explicitly: only probes in the form of matrix-vector products for any appropriate vector are available. The standard approach for estimating the trace of such a matrix $A$ is based on a Monte-Carlo method, where one generates $N$ random vector realizations ${ {\bf w} }_{i}$ from a suitable probability distribution $D$ and computes $$tr_{D}^{N}(A) {\mathrel{\mathop:}=}\frac{1}{N} \sum_{i=1}^{N} { {\bf w} }_{i}^{t} A { {\bf w} }_{i} .
\label{tr_moncar}$$ For the popular case where $A$ is symmetric positive semi-definite (SPSD), the original method for estimating its trace, $tr(A)$, is due to Hutchinson @hutchinson and uses the Rademacher distribution for $D$.

Until the work by Avron and Toledo @avto, the main analysis and comparison of such methods was based on the variance of one sample. It is known that compared to other methods the Hutchinson method has the smallest variance, and as such it has been extensively used in many applications. In @avto so-called $({\varepsilon},\delta)$ bounds are derived in which, using Chernoff-like analysis, a lower bound is obtained on the number of samples required to achieve a probabilistically guaranteed relative error of the estimated trace. More specifically, for a given pair $({\varepsilon},\delta)$ of small (say, $< 1$) positive values and an appropriate probability distribution $D$, a lower bound on $N$ is provided such that $$Pr\left(| tr_{D}^{N}(A) - tr(A) | \leq {\varepsilon}~ tr(A) \right) \geq 1-\delta .
\label{prob_tr}$$ These authors further suggest that minimum-variance estimators may not be practically best, and conclude based on their analysis that the method with the best bound is the one using the Gaussian distribution. Let us denote

$$\begin{aligned}
c &=& c( {\varepsilon},\delta) {\mathrel{\mathop:}=}{\varepsilon}^{-2} \ln (2/\delta), \label{common_factor_c} \\
r &=& rank(A). \label{common_factor_r}\end{aligned}$$

\[common\_factor\]

Then @avto showed that, provided $A$ is real SPSD, holds for the Hutchinson method if $N \geq 6(c+ {\varepsilon}^{-2}\ln r )$ and for the Gaussian distribution if $N \geq 20c$. In the present paper we continue to consider the same objective as in @avto, and our first task is to improve on these bounds. Specifically, in Theorems \[hutch\_thm\_01\] and \[gauss\_thm\_01\] we show that holds for the Hutchinson method if $$\begin{aligned}
N \geq 6 c ({\varepsilon},\delta), \label{hutch_bd_01}\end{aligned}$$ and for the Gaussian distribution if $$\begin{aligned}
N \geq 8 c({\varepsilon},\delta). \label{gauss_bd_01}\end{aligned}$$ The bound  removes a previous factor involving the rank of the matrix $A$, conjectured in @avto to be indeed redundant. Note that these two bounds are astoundingly simple and general: they hold for any SPSD matrix, regardless of size or any other matrix property. Thus, we cannot expect them to be tight in practice for many specific instances of $A$ that arise in applications.

Although practically useful, the bounds on $N$ given in  and do not provide insight into how different types of matrices are handled with each probability distribution. Our next contribution is to provide different bounds for the Gaussian and Hutchinson trace estimators which, though generally not computable for implicit matrices, do shed light on this question. Furthermore, for the Gaussian estimator we prove a practically useful <span>*necessary lower*</span> bound on $N$, for a given pair $({\varepsilon}, \delta)$.

A third probability distribution we consider was called the unit vector distribution in @avto. Here, the vectors ${ {\bf w} }_{i}$ in  are uniformly drawn from the columns of a scaled identity matrix, $\sqrt{n} I$, and $A$ need not be SPSD. We slightly generalize the bound in @avto, obtained for the case where the sampling is done with replacement. Our bound, although not as simply computed as or , can be useful in determining which types of matrices this distribution works best on. We then give a tighter bound for the case where the sampling is done without replacement, suggesting that when the difference between the bounds is significant (which happens when $N$ is large), a uniform random sampling of unit vectors without replacement may be a more advisable distribution to estimate the trace with.

This paper is organized as follows. Section \[hutch\] gives two bounds for the Hutchinson method as advertised above, namely the improved bound  and a more involved but potentially more informative bound. Section \[gauss\] deals likewise with the Gaussian method and adds also a necessary lower bound, while Section \[randsamp\] is devoted to the unit vector sampling methods.

In Section \[numer\] we give some numerical examples verifying that the trends predicted by the theory are indeed realized. Conclusions and further thoughts are gathered in Section \[concl\].

In what follows we use the notation $tr_{H}^{N}(A)$, $tr_{G}^{N}(A)$, $tr_{U_{1}}^{N}(A)$, and $tr_{U_{2}}^{N}(A)$ to refer, respectively, to the trace estimators using Hutchinson, Gaussian, and uniform unit vector with and without replacement, in lieu of the generic notation $tr_{D}^{N}(A)$ in  and . We also denote for any given random vector of size $n$, ${ {\bf w} }_i = (w_{i1}, w_{i2}, \ldots , w_{in})^t$. We restrict attention to real-valued matrices, although extensions to complex-valued ones are possible, and employ the $2$-norm by default.

Hutchinson estimator bounds {#hutch}
===========================

In this section we consider the Hutchinson trace estimator, $tr_{H}^{N}(A)$, obtained by setting $D=H$ in , where the components of the random vectors ${ {\bf w} }_{i}$ are i.i.d Rademacher random variables (i.e., $Pr(w_{ij} = 1) = Pr(w_{ij} = -1) = \frac{1}{2}$).

Improving the bound in @avto {#hutch1}
----------------------------

Let $A$ be an $n \times n$ SPSD matrix. Given a pair $({\varepsilon},\delta)$, the inequality   holds with $D=H$ if $N$ satisfies . \[hutch\_thm\_01\]

Since $A$ is SPSD, it can be diagonalized by a unitary similarity transformation as $A = U^{t} \Lambda U$. Consider $N$ random vectors ${ {\bf w} }_{i}, \; i = 1, \ldots , N$, whose components are i.i.d and drawn from the Rademacher distribution, and define ${ {\bf z} }_{i} = U { {\bf w} }_{i}$ for each. We have

$$\begin{aligned}
Pr\left( tr_{H}^{N}(A) \leq (1-{\varepsilon})tr(A) \right) &=& Pr\left( \frac{1}{N} \sum_{i=1}^{N} { {\bf w} }_{i}^{t} A { {\bf w} }_{i}  \leq (1-{\varepsilon})tr(A)\right) 
\nonumber \\
&=& Pr\left( \frac{1}{N} \sum_{i=1}^{N} { {\bf z} }_{i}^{t} \Lambda { {\bf z} }_{i}  \leq (1-{\varepsilon})tr(A)\right) \nonumber \\
&=& Pr\left( \sum_{i=1}^{N} \sum_{j=1}^{r} \lambda_{j} z_{ij}^{2}  \leq N(1-{\varepsilon})tr(A)\right) \nonumber \\
&=& Pr\left( \sum_{j=1}^{r} \frac{\lambda_{j}}{tr(A)} \sum_{i=1}^{N} z_{ij}^{2} \leq N(1-{\varepsilon})\right) \nonumber \\
&\leq& \exp \{t N (1-{\varepsilon}) \} \mathbb{E}\left( \exp\{\sum_{j=1}^{r} \frac{\lambda_{j}}{tr(A)} \sum_{i=1}^{N} -t z_{ij}^{2}\}\right),\end{aligned}$$

where the last inequality holds for any $t >0$ by Markov's inequality.

Next, using the convexity of the $\exp$ function and the linearity of expectation, we obtain $$\begin{aligned}
\mathbb{E}\left(\exp\{\sum_{j=1}^{r} \frac{\lambda_{j}}{tr(A)} \sum_{i=1}^{N} -t z_{ij}^{2}\}\right) &\leq& 
\sum_{j=1}^{r} \frac{\lambda_{j}}{tr(A)} \mathbb{E}\left(\exp\{\sum_{i=1}^{N} -t z_{ij}^{2}\}\right) \\
&=& 
\sum_{j=1}^{r} \frac{\lambda_{j}}{tr(A)} \mathbb{E}\left( \prod_{i=1}^{N} \exp\{-t z_{ij}^{2}\}\right) \\
&=& 
\sum_{j=1}^{r} \frac{\lambda_{j}}{tr(A)} \prod_{i=1}^{N}\mathbb{E}\left(\exp\{-t z_{ij}^{2}\}\right),\end{aligned}$$ where the last equality holds since, for a given $j$, $z_{ij}$'s are independent with respect to $i$.

Now, we want to have that $\exp\{t N (1-{\varepsilon}) \} \prod_{i=1}^{N}\mathbb{E}\left( \exp\{-t z_{ij}^{2}\}\right) \leq \delta / 2$. For this we make use of the inequalities in the end of the proof of Lemma 5.1 of @achlioptas. Following inequalities (15)–(19) in @achlioptas and letting $t = {\varepsilon}/ (2(1+{\varepsilon}))$, we get $$\begin{aligned}
\exp\{t N (1-{\varepsilon}) \} \prod_{i=1}^{N}\mathbb{E}\left(\exp\{-t z_{ij}^{2}\}\right) < \exp\{-\frac{N}{2}(\frac{{\varepsilon}^2}{2}-\frac{{\varepsilon}^3}{3})\}.\end{aligned}$$ Next, if $N$ satisfies then $\exp\{-\frac{N}{2}(\frac{{\varepsilon}^2}{2}-\frac{{\varepsilon}^3}{3})\} < \delta/2$, and thus it follows that $$Pr \left(tr_{H}^{N}(A) \leq (1-{\varepsilon})tr(A)\right) < \delta/2 .$$

By a similar argument, making use of inequalities (11)–(14) in @achlioptas with the same $t$ as above, we also obtain with the same bound for $N$ so that $Pr\left(tr_{H}^{N}(A) \geq (1+{\varepsilon})tr(A)\right) \leq \delta/2$. So finally using the union bound yields the desired result. $\blacksquare$

It can be seen that is the same bound as the one in @avto with the important exception that the factor $r=rank(A)$ does not appear in the bound. Furthermore, the same bound on $N$ holds for any SPSD matrix.

A matrix-dependent bound {#hutch2}
------------------------

Here we derive another bound for the Hutchinson trace estimator which may shed light as to what type of matrices the Hutchinson method is best suited for.

Let us denote by $a_{k,j}$ the $(k,j)$th element of $A$ and by ${\bf a}_j$ its $j$th column, $k, j = 1, \ldots , n$.

Let $A$ be an $n \times n$ symmetric positive semi-definite matrix, and define $${ {\mathcal K}_H }^{j} {\mathrel{\mathop:}=}\frac{\| {\bf a}_j \|^{2} - a_{j,j}^{2}}{a_{j,j}^{2}}  =  \sum_{k \neq j} a_{k,j}^2 ~/~ a_{j,j}^2,
\quad { {\mathcal K}_H }{\mathrel{\mathop:}=}\max_{j} { {\mathcal K}_H }^{j} .
\label{hutch_energy_dist}$$ Given a pair of positive small values $({\varepsilon},\delta)$, the inequality  holds with $D=H$ if $$N > 2 { {\mathcal K}_H }c({\varepsilon},\delta) .
\label{hutch_bd_02}$$

\[hutch\_thm\_02\]

Elementary linear algebra implies that since $A$ is SPSD, $a_{j,j} \geq 0$ for each $j$. Furthermore, if $a_{j,j} = 0$ then the $j$th row and column of $A$ identically vanish, so we may assume below that $a_{j,j} > 0$ for all $j = 1, \ldots , n$. Note that $$tr_{H}^{N}(A) - tr(A) = \frac{1}{N} \sum_{j=1}^{n} \sum_{i=1}^{N}  \sum_{\substack{k=1 \\ k\neq j}}^{n} a_{j,k}w_{ij} w_{ik}.$$ Hence $$\begin{aligned}
Pr\left(tr_{H}^{N}(A) \leq (1-{\varepsilon})tr(A)\right) 
&=& Pr\left(\sum_{j=1}^{n} \sum_{i=1}^{N}  \sum_{\substack{k=1 \\ k\neq j}}^{n} -a_{j,k} w_{ij} w_{ik}  \geq N {\varepsilon}~ tr(A)\right) \\
&=& Pr\left(\sum_{j=1}^{n} \frac{a_{j,j}}{tr(A)} \sum_{i=1}^{N} \sum_{\substack{k=1 \\ k\neq j}}^{n} -\frac{a_{j,k}}{a_{j,j}} w_{ij} w_{ik}  \geq N {\varepsilon}\right) \\
&\leq& \exp\{-t N {\varepsilon}\} \mathbb{E}\left(\exp \{ \sum_{j=1}^{n} \frac{a_{j,j}}{tr(A)} \sum_{i=1}^{N} \sum_{\substack{k=1 \\ k\neq j}}^{n} -\frac{a_{j,k} t}{a_{j,j}} w_{ij} w_{ik}\}\right),\end{aligned}$$ where the last inequality is again obtained for any $t > 0$ by using Markov's inequality. Now, again using the convexity of the $\exp$ function and the linearity of expectation, we obtain $$\begin{aligned}
Pr\left(tr_{H}^{N}(A) \leq (1-{\varepsilon})tr(A)\right) &\leq& \exp\{-t N {\varepsilon}\} \sum_{j=1}^{n} \frac{a_{j,j}}{tr(A)} 
\mathbb{E}\left(\exp \{ \sum_{i=1}^{N} \sum_{\substack{k=1 \\ k\neq j}}^{n} -\frac{a_{j,k} t}{a_{j,j}} w_{ij} w_{ik}\}\right)  \\
&=& \exp\{-t N {\varepsilon}\} \sum_{j=1}^{n} \frac{a_{j,j}}{tr(A)} \prod_{i=1}^{N} \mathbb{E}\left(\exp \{\sum_{\substack{k=1 \\ k\neq j}}^{n} -\frac{a_{j,k} t}{a_{j,j}} w_{ij} w_{ik}\}\right) \end{aligned}$$ by independence of $w_{ij} w_{ik}$ with respect to the index $i$.

Next, note that $$\begin{aligned}
\mathbb{E}\left(\exp \{\sum_{\substack{k=1 \\ k\neq j}}^{n} \frac{a_{j,k} t}{a_{j,j}} w_{ik} \}\right) = 
\mathbb{E}\left(\exp \{\sum_{\substack{k=1 \\ k\neq j}}^{n} -\frac{a_{j,k} t}{a_{j,j}} w_{ik} \}\right).\end{aligned}$$ Furthermore, since $Pr( w_{ij} = -1) = Pr( w_{ij} = 1) = \frac{1}{2}$, and using the law of total expectation, we have $$\begin{aligned}
\mathbb{E}\left(\exp \{\sum_{\substack{k=1 \\ k\neq j}}^{n} -\frac{a_{j,k} t}{a_{j,j}} w_{ij} w_{ik} \}\right) =  
\mathbb{E}\left(\exp \{ \sum_{\substack{k=1 \\ k\neq j}}^{n} \frac{a_{j,k} t}{a_{j,j}} w_{ik} \}\right) = \prod_{\substack{k=1 \\ k\neq j}}^{n} \mathbb{E}\left(\exp \{\frac{a_{j,k} t}{a_{j,j}} w_{ik} \}\right) ,\end{aligned}$$ so $$\begin{aligned}
Pr\left(tr_{H}^{N}(A) \leq (1-{\varepsilon})tr(A)\right) &\leq& \exp \{-t N {\varepsilon}\} \sum_{j=1}^{n} \frac{a_{j,j}}{tr(A)} \prod_{i=1}^{N} 
\prod_{\substack{k=1 \\ k\neq j}}^{n} \mathbb{E}\left(\exp \{\frac{a_{j,k} t}{a_{j,j}} w_{ik} \}\right) .\end{aligned}$$ We want to have the right hand side expression bounded by $\delta / 2$.

Applying Hoeffding's lemma we get $\mathbb{E}\left(\exp \{ \frac{a_{j,k} t}{a_{j,j}} w_{ik} \}\right) \leq \exp\{ \frac{a_{j,k}^{2} t^{2}}{2 a_{j,j}^{2}} \}$, hence

$$\begin{aligned}
\exp \{-t N {\varepsilon}\} \prod_{i=1}^{N} \prod_{\substack{k=1 \\ k\neq j}}^{n} \mathbb{E}\left(\exp \{ \frac{a_{j,k} t}{a_{j,j}} w_{ik} \}\right) &\leq& \exp \{-t N {\varepsilon}+ { {\mathcal K}_H }^{j} N t^{2}/2 \} \label{K_H_j_dist}\\
&\leq& \exp \{ -t N {\varepsilon}+ { {\mathcal K}_H }N t^{2}/2 \} \label{K_H_j_max}.\end{aligned}$$

The choice $$\begin{aligned}
t = {\varepsilon}/ { {\mathcal K}_H }$$ minimizes the right hand side. Now if holds then $$\begin{aligned}
\exp(-t N {\varepsilon}) \prod_{i=1}^{N} \prod_{\substack{k=1 \\ k\neq j}}^{n} \mathbb{E}\left(\exp \{\frac{a_{j,k} t}{a_{j,j}} w_{ik} \}\right) \leq \delta / 2 ,\end{aligned}$$ hence we have $$\begin{aligned}
Pr(tr_{H}^{N}(A) \leq (1-{\varepsilon})tr(A)) &\leq& \delta / 2.\end{aligned}$$ Similarly, we obtain that $$\begin{aligned}
Pr(tr_{H}^{N}(A) \geq (1+{\varepsilon})tr(A)) &\leq& \delta/2,\end{aligned}$$ and using the union bound finally gives desired result. $\blacksquare$

Comparing to , it is clear that the bound of the present subsection is only worthy of consideration if ${ {\mathcal K}_H }< 3$. Note that Theorem \[hutch\_thm\_02\] emphasizes the relative $\ell_2$ energy of the off-diagonals: the matrix does not necessarily have to be diagonally dominant (i.e., where a similar relationship holds in the $\ell_1$ norm) for the bound on $N$ to be moderate. Furthermore, a matrix need not be "nearly" diagonal for this method to require small sample size. In fact a matrix can have off-diagonal elements of significant size that are far away from the main diagonal without automatically affecting the performance of the Hutchinson method. However, note also that our bound can be pessimistic, especially if the average value or the mode of ${ {\mathcal K}_H }^{j}$ in is far lower than its maximum, ${ {\mathcal K}_H }$. This can be seen in the above proof where the estimate  is obtained from . Simulations in Section \[numer\] show that the Hutchinson method can be a very efficient estimator even in the presence of large outliers, so long as the bulk of the distribution is concentrated near small values.

The case ${ {\mathcal K}_H }=0$ corresponds to a diagonal matrix, for which the Hutchinson method yields the trace with one shot, $N=1$. In agreement with the bound , we expect the actual required $N$ to grow when a sequence of otherwise similar matrices $A$ is envisioned in which ${ {\mathcal K}_H }$ grows away from $0$, as the energy in the off-diagonal elements grows relatively to that in the diagonal elements.

Gaussian estimator bounds {#gauss}
=========================

In this section we consider the Gaussian trace estimator, $tr_{G}^{N}(A)$, obtained by setting $D=G$ in , where the components of the random vectors ${ {\bf w} }_{i}$ are i.i.d standard normal random variables. We give two sufficient and one necessary lower bounds for the number of Gaussian samples required to achieve an $({\varepsilon}, \delta)$ trace estimate. The first sufficient bound improves the result in @avto by a factor of $2.5$. Our bound is only worse than by a fraction, and it is an upper limit of the potentially more informative (if less available) bound , which relates to the properties of the matrix $A$. The bound  provides an indication as to what matrices may be suitable candidates for the Gaussian method. Then we present a practically computable, necessary bound for the sample size $N$.

Sufficient bounds {#gauss1}
-----------------

The proof of the following theorem closely follows the approach in @avto.

Let $A$ be an $n \times n$ SPSD matrix and denote its eigenvalues by $\lambda_1, \ldots , \lambda_n$. Further, define $${ {\mathcal K}_G }^{j} {\mathrel{\mathop:}=}\frac{\lambda_{j}}{tr(A)} , \quad { {\mathcal K}_G }{\mathrel{\mathop:}=}\max_j { {\mathcal K}_G }^{j} = \frac{\| A \|}{tr(A)} . 
\label{gauss_energy_dist}$$ Then, given a pair of positive small values $({\varepsilon},\delta)$, the inequality  holds with $D=G$ provided that holds. This estimate also holds provided that $$N > 8 { {\mathcal K}_G }c({\varepsilon},\delta) .
\label{gauss_bd_02}$$ \[gauss\_thm\_01\]

Since $A$ is SPSD, we have $\| A \| \leq tr(A)$, so if holds then so does . We next concentrate on proving the result assuming the tighter bound on the actual $N$ required in a given instance.

Writing as in the previous section $A = U^{t} \Lambda U$, consider $N$ random vectors ${ {\bf w} }_{i}, \; i = 1, \ldots , N$, whose components are i.i.d and drawn from the normal distribution, and define ${ {\bf z} }_{i} = U { {\bf w} }_{i}$. Since $U$ is orthogonal, the elements $z_{ij}$ of ${ {\bf z} }_{i}$ are i.i.d Gaussian random variables. We have as before, $$\begin{aligned}
Pr \left( tr_{G}^{N}(A) \leq (1-{\varepsilon})tr(A)\right) 
&=& Pr\left(\sum_{i=1}^{N} \sum_{j=1}^{r} \lambda_{j} z_{ij}^{2}  \leq N(1-{\varepsilon})tr(A)\right)  \\
&\leq& \exp\{t N (1-{\varepsilon}) tr(A)\} \mathbb{E}\left(\exp\{\sum_{i=1}^{N} \sum_{j=1}^{r} -t \lambda_{j} z_{ij}^{2}\}\right)  \\
&\leq& \exp\{t N (1-{\varepsilon}) tr(A)\} \prod_{i=1}^{N} \prod_{j=1}^{r} \mathbb{E}\left(\exp\{ -t \lambda_{j} z_{ij}^{2}\}\right) .\end{aligned}$$

Here $z_{ij}^{2}$ is a $\chi^2$ random variable of degree 1 (see  @mogrbo), and hence for the characteristics we have $$\mathbb{E}\left(\exp\{ -t \lambda_{j} z_{ij}^{2}\}\right) = (1 + 2 \lambda_{j} t)^{-\frac{1}{2}} .$$ This yields the bound $$Pr\left(tr_{G}^{N}(A) \leq (1-{\varepsilon})tr(A)\right) \leq \exp\{t N (1-{\varepsilon}) tr(A)\} \prod_{j=1}^{r} (1 + 2 \lambda_{j} t)^{-\frac{N}{2}} .$$

Next, it is easy to prove by elementary calculus that given any $0 < \alpha < 1$, the following holds for all $0 \leq x \leq \frac{1-\alpha}{\alpha}$, $$\ln(1+x) \geq \alpha x .
\label{lemma2}$$ Setting $\alpha = 1-{\varepsilon}/2$, then by  and for all $t \leq (1-\alpha)/( 2 \alpha \| A \| )$, we have that $(1 + 2 \lambda_{j} t) > \exp \{2 \alpha \lambda_{j}\} t$, so $$\begin{aligned}
Pr\left(tr_{G}^{N}(A) \leq (1-{\varepsilon})tr(A)\right) &\leq& \exp \{t N (1-{\varepsilon}) tr(A)\} \prod_{j=1}^{r} \exp( - N \alpha \lambda_{j} t) \\
&=& \exp\{t N (1 - {\varepsilon}- \alpha) tr(A)\} .\end{aligned}$$

We want the latter right hand side to be bounded by $\delta /2$, i.e., we want to have $$\begin{aligned}
N &\geq& \frac{\ln\big(2 /\delta\big)}{(\alpha-(1-{\varepsilon})) tr(A) t} 
= \frac{2 {\varepsilon}c({\varepsilon},\delta)}{tr(A) t},\end{aligned}$$ where $t \leq (1-\alpha )/( 2 \alpha \| A \| )$. Now, setting $t = (1-\alpha)/( 2 \alpha \| A \|) = {\varepsilon}/( 2 (2 - {\varepsilon}) \| A \| )$, we obtain $$N \geq 4 (2-{\varepsilon}) c({\varepsilon},\delta)  { {\mathcal K}_G },$$ so if holds then $$Pr\left(tr_{G}^{N}(A) \leq (1-{\varepsilon})tr(A)\right) \leq \delta /2 .$$

Using a similar argument we also obtain $$Pr\left(tr_{G}^{N}(A) \geq (1+{\varepsilon})tr(A)\right) \leq \delta / 2 ,$$ and subsequently the union bound yields the desire result. $\blacksquare$

The matrix-dependent bound , proved to be sufficient in Theorem \[gauss\_thm\_01\], provides additional information over  about the type of matrices for which the Gaussian estimator is (probabilistically) guaranteed to require only a small sample size: if the eigenvalues of an SPSD matrix are distributed such that the ratio $\|A\| / tr(A)$ is small (e.g., if they are all of approximately the same size), then the Gaussian estimator bound requires a small number of realizations. This observation is reaffirmed by looking at the variance of this estimator, namely $2 \| A \|^{2}_{F}$. It is easy to show that among all the matrices with a fixed trace and rank, those with equal eigenvalues have the smallest Frobenius norm.

Furthermore, it is easy to see that the <span>*stable rank*</span> (see @tropp and references therein) of any real rectangular matrix $C$ which satisfies $A = C^t C$ equals $1 / { {\mathcal K}_G }$. Thus, the bound constant in  is inversely proportional to this stable rank, suggesting that estimating the trace using the Gaussian distribution may become inefficient if the stable rank of the matrix is low. Theorem \[gauss\_thm\_02\] in Section \[gauss2\] below further substantiates this intuition.

As an example of an application of the above results, let us consider finding the minimum number of samples required to compute the rank of a projection matrix using the Gaussian estimator @avto [@bekosa]. Recall that a projection matrix is SPSD with only 0 and 1 eigenvalues. Compared to the derivation in @avto, here we use Theorem \[gauss\_thm\_01\] directly to obtain a similar bound with a slightly better constant.

Let $A$ be an $n \times n$ projection matrix with rank $r > 0$, and denote the rounding of any real scalar $x$ to the nearest integer by $round(x)$. Then, given a positive small value $\delta$, the estimate

$$\begin{aligned}
Pr\left(round(tr_{G}^{N}(A)) \neq r\right) \leq \delta
\label{11a}\end{aligned}$$

holds if $$\begin{aligned}
N \geq 8 \; r \ln\big(2 /\delta\big) .
\label{11b}\end{aligned}$$ \[11\]

The result immediately follows using Theorem \[gauss\_thm\_01\] upon setting ${\varepsilon}= 1/r, 
\|A\| = 1$ and $tr(A) = r$. $\blacksquare$

A necessary bound {#gauss2}
-----------------

Below we provide a rank-dependent, almost tight necessary condition for the minimum sample size required to obtain . This bound is easily computable in case that $r=rank(A)$ is known.

Before we proceed, recall the definition of the regularized Gamma functions $$\begin{aligned}
P \left(\alpha,\beta\right) {\mathrel{\mathop:}=}\frac{\gamma \left( \alpha , \beta \right)}{\Gamma \left( \alpha \right)}, \quad
Q \left(\alpha,\beta\right) {\mathrel{\mathop:}=}\frac{\Gamma \left( \alpha , \beta \right)}{\Gamma \left( \alpha \right)},\end{aligned}$$ where $\gamma \left(\alpha,\beta\right), \Gamma \left(\alpha,\beta\right)$ and $\Gamma \left(\alpha\right)$ are, respectively, the lower incomplete, the upper incomplete and the complete Gamma functions, see @abramowitz. We also have that $\Gamma \left(\alpha\right) = \Gamma \left(\alpha,\beta\right) + \gamma \left(\alpha,\beta\right) $. Further, define

$$\begin{aligned}
\Phi_{\theta}(x) {\mathrel{\mathop:}=}P \left(\frac{x}{2},\frac{\tau (1-\theta) x}{2}\right) + 
Q \left(\frac{x}{2},\frac{\tau (1+\theta) x}{2}\right) ,
\label{gamma_fun}\end{aligned}$$

where $$\begin{aligned}
\tau = \frac{\ln(1+\theta)-\ln(1-\theta)}{2 \theta}.
\label{factor}\end{aligned}$$ \[12\]

Let $A$ be a rank-$r$ SPSD $n \times n$ matrix, and let $({\varepsilon},\delta)$ be a tolerance pair. If the inequality  with $D = G$ holds for some $N$, then necessarily $$\Phi_{{\varepsilon}}(Nr) \leq \delta.
\label{gauss_bd_03}$$ \[gauss\_thm\_02\]

As in the proof of Theorem \[gauss\_thm\_01\] we have $$\begin{aligned}
Pr\left(| tr_{G}^{N}(A) - tr(A) | \leq {\varepsilon}~ tr(A) \right) &=& Pr\left(| \sum_{i=1}^{N} \sum_{j=1}^{r} \lambda_{j} z_{ij}^{2}  - N tr(A) | \leq {\varepsilon}N tr(A)\right) \\
&=& Pr\left((1-{\varepsilon}) \leq  \sum_{i=1}^{N} \sum_{j=1}^{r} \frac{\lambda_{j}}{tr(A)~N} z_{ij}^{2}  \leq (1+{\varepsilon}) \right) .\end{aligned}$$ Next, applying Theorem 3 of @szba gives $$Pr \left(| tr_{G}^{N}(A) - tr(A) | \leq {\varepsilon}~ tr(A) \right) \leq 
Pr \left(c (1-{\varepsilon}) \leq  \frac{1}{Nr} \mathcal{X}_{Nr}^{2}  \leq c(1+{\varepsilon}) \right) ,$$ where $\mathcal{X}_{M}^{2}$ denotes a chi-squared random variable of degree $M$ with the cumulative distribution function $$CDF_{\mathcal{X}_{M}^{2}}(x) = Pr \left( \mathcal{X}_{M}^{2} \leq x \right) = \frac{\gamma \left( \frac{M}{2},\frac{x}{2} \right)}{\Gamma \left( \frac{M}{2}\right)} .$$ A further straightforward manipulation yields the stated result. $\blacksquare$

Having a computable necessary condition is practically useful: given a pair of fixed sample size $N$ and error tolerance ${\varepsilon}$, the failure probability $\delta$ cannot be smaller than $\delta_{0} = \Phi_{{\varepsilon}}(Nr)$.

Since our sufficient bounds are not tight, it is not possible to make a direct comparison between the Hutchinson and Gaussian methods based on them. However, using this necessary condition can help for certain matrices. Consider a low rank matrix with a rather small ${ {\mathcal K}_H }$ in . For such a matrix and a given pair $({\varepsilon},\delta)$, the condition  will probabilistically necessitate a rather large $N$, while  may give a much smaller sufficient bound for $N$. In this situation, using Theorem \[gauss\_thm\_02\], the Hutchinson method is indeed guaranteed to require a smaller sample size than the Gaussian method.

The condition in Theorem \[gauss\_thm\_02\] is almost tight in the following sense. Note that in , $\tau \approx 1$ for $\theta = {\varepsilon}$ sufficiently small. So, $1-\Phi_{{\varepsilon}}(Nr)$ would be very close to $Pr\left( (1-{\varepsilon}) \leq tr_{G}^{N}(A^{*}) \leq (1+{\varepsilon}) \right)$, where $A^{*}$ is an SPD matrix of the same rank as $A$ whose eigenvalues are all equal to $1/r$. Next note that the condition  should hold for all matrices of the same rank; hence it is almost tight. Figures \[Nec\_N\_Rank\] and \[fig:thetas\] demonstrate this effect.

Notice that for a very low rank matrix and a reasonable pair $({\varepsilon},\delta)$, the necessary $N$ given by  could be even larger than the matrix size $n$, rendering the Gaussian method useless for such instances; see Figure \[Nec\_N\_Rank\].

Random unit vector bounds, with and without replacement, for general square matrices {#randsamp}
====================================================================================

An alternative to the Hutchinson and Gaussian estimators is to draw the vectors ${ {\bf w} }_i$ from among the $n$ columns of the scaled identity matrix $\sqrt{n} I$. Note that if ${ {\bf w} }_i$ is the $i$th (scaled) unit vector then ${ {\bf w} }_i^tA{ {\bf w} }_i = n a_{ii}$. Hence the trace can be recovered in $N=n$ deterministic steps upon setting in $i=j,\ j=1, 2, \ldots , n$. However, our hope is that for some matrices a good approximation for the trace can be recovered in $N \ll n$ such steps, with ${ {\bf w} }_i$'s drawn as mentioned above.

There are typically two ways one can go about drawing such samples: with or without replacement. The first of these has been studied in @avto. However, in view of the exact procedure, we may expect to occasionally require smaller sample sizes by using the strategy of sampling without replacement. In this section we make this intuitive observation more rigorous.

In what follows, $U_{1}$ and $U_{2}$ refer to the uniform distribution of unit vectors with and without replacement, respectively. We first find expressions for the mean and variance of both strategies, obtaining a smaller variance for $U_2$.

Let $A$ be an $n \times n$ matrix and let $N$ denote the sample size. Then

$$\begin{aligned}
                    \mathbb{E} \left( tr^{N}_{U_{1}}(A) \right ) &=& \mathbb{E} \left( tr^{N}_{U_{2}}(A) \right ) = tr(A)  \label{mean_R1} , \\
                    Var \left( tr^{N}_{U_{1}}(A) \right ) &=& \frac{1}{N} \left( n \sum_{j=1}^{n} a^{2}_{jj}  - tr (A)^2 \right) \label{var_R1} ,\\
                                        Var \left( tr^{N}_{U_{2}}(A) \right ) &=& \frac{(n-N)}{N (n-1)} \left( n \sum_{j=1}^{n} a^{2}_{jj} - tr (A)^2 \right), \quad N \leq n .\label{var_R2} 
            \end{aligned}$$

\[randsamp\_lem\]

The results for $U_1$ are proved in @avto. Let us next concentrate on $U_2$, and group the randomly selected unit vectors into an $n \times N$ matrix $W$. Then $$\begin{aligned}
\mathbb{E} \left( tr^{N}_{U_{2}}(A) \right )  = \frac{1}{N}  \mathbb{E} \left( tr\left( W^t A W \right) \right) = \frac{1}{N}  \mathbb{E} \left( tr\left( A \; W W^{t} \right) \right) = \frac{1}{N}  tr \left( A \; \mathbb{E} \left( W W^{t} \right) \right) .\nonumber \\
$$ Let $y_{ij}$ denote the $(i,j)$th element of the random matrix $W W^{t}$. Clearly, $y_{ij} = 0$ if $i \neq j$. It is also easily seen that $y_{ii}$ can only take on the values $0$ or $n$. We have $$\begin{aligned}
\mathbb{E} \left( y_{ii}  \right) = n Pr\left(y_{ii} = n \right) = n \frac{\binom{n-1}{N-1}}{\binom{n}{N}} = N,\end{aligned}$$ so $\mathbb{E} ( W W^{t} ) = N \cdot I$, where $I$ stands for the identity matrix. This, in turn, gives $\mathbb{E} \left( tr^{N}_{U_{2}}(A) \right ) = tr(A)$.

For the variance, we first calculate $$\begin{aligned}
&& \mathbb{E} \left [ \left( tr^{N}_{U_{2}}(A) \right )^2 \right ] = \frac{1}{N^2} \mathbb{E} \left( \sum_{i=1}^{N} \sum_{j=1}^{N} \left( { {\bf w} }^{t}_{i} A { {\bf w} }_{i} \right) \left({ {\bf w} }^{t}_{j} A { {\bf w} }_{j} \right) \right) \nonumber \\
&=& \frac{1}{N^{2}} \left(\sum_{i=1}^{N} \mathbb{E} \left[ \left( { {\bf w} }^{t}_{i} A { {\bf w} }_{i} \right)^{2} \right] + \sum_{i=1}^{N} \sum_{\substack{j=1 \\ j\neq i}}^{N} \mathbb{E} \left[ \left( { {\bf w} }^{t}_{i} A { {\bf w} }_{i} \right) \left( { {\bf w} }^{t}_{j} A { {\bf w} }_{j} \right) \right]\right) .
\label{tr_U_2_temp}\end{aligned}$$

Let ${ {\bf e} }_{j}$ denote the $j^{th}$ column of the scaled identity matrix, $\sqrt{n} I$. Using the law of total expectation (i.e., the tower rule), we have for any two random vectors ${ {\bf w} }_{i}$ and ${ {\bf w} }_{j}$ with $i \neq j$, $$\begin{aligned}
\mathbb{E} \left[ \left( { {\bf w} }^{t}_{i} A { {\bf w} }_{i} \right) \left( { {\bf w} }^{t}_{j} A { {\bf w} }_{j} \right) \right] &=& \sum_{k=1}^{n} \mathbb{E} \left[ \left( { {\bf w} }^{t}_{i} A { {\bf w} }_{i} \right) \left( { {\bf w} }^{t}_{j} A { {\bf w} }_{j} \right)  | { {\bf w} }_{i} = { {\bf e} }_{k} \right] \cdot Pr \left( { {\bf w} }_{i} = { {\bf e} }_{k} \right) \nonumber \\
&=& \sum_{k=1}^{n} n a_{kk} \cdot \mathbb{E} \left[ \left( { {\bf w} }^{t}_{j} A { {\bf w} }_{j} \right)  | { {\bf w} }_{i} = { {\bf e} }_{k} \right] \cdot \frac{1}{n} \nonumber \\
&=& \sum_{k=1}^{n} a_{kk} \sum_{\substack{l=1 \\ l\neq k}}^{n} \mathbb{E} \left[ \left( { {\bf w} }^{t}_{j} A { {\bf w} }_{j} \right)  | { {\bf w} }_{j} = { {\bf e} }_{l} \right] \cdot Pr \left( { {\bf w} }_{j} = { {\bf e} }_{l} \right | { {\bf w} }_{i} = { {\bf e} }_{k}) \nonumber \\
&=& \sum_{k=1}^{n} a_{kk} \sum_{\substack{l=1 \\ l\neq k}}^{n} n a_{ll} \frac{1}{n-1} 
= \frac{n}{n-1}  \sum_{k=1}^{n} \sum_{\substack{l=1 \\ k\neq l}}^{n} a_{kk} a_{ll} \\
&=& \frac{n}{n-1}   ( tr(A)^{2} - \sum_{j=1}^{n} a^{2}_{jj} ).\end{aligned}$$ Substituting this in  gives $$\begin{aligned}
\mathbb{E} \left [ \left( tr^{N}_{U_{2}}(A) \right )^2 \right ] &=& \frac{1}{N^{2}} \left( n N \sum_{j=1}^{n} a^{2}_{jj} + \frac{n N (N-1)}{n-1} ( tr(A)^{2} - \sum_{j=1}^{n} a^{2}_{jj} ) \right) .\end{aligned}$$ Next, the variance is $$Var \left( tr^{N}_{U_{2}}(A) \right ) = \mathbb{E} \left [ \left( tr^{N}_{U_{2}}(A) \right )^2 \right ] - \left [\mathbb{E} \left( tr^{N}_{U_{2}}(A) \right ) \right ]^{2} ,$$ which gives . $\blacksquare$

Note that $Var \left( tr^{N}_{U_{2}}(A) \right ) = \frac{n-N}{n-1} Var \left( tr^{N}_{U_{1}}(A) \right )$. The difference in variance between these sampling strategies is small for $N \ll n$, and they coincide if $N=1$. Moreover, in case that the diagonal entries of the matrix are all equal, the variance for both sampling strategies vanishes.

We now turn to the analysis of the sample size required to ensure  and find a slight improvement over the bound given in @avto for $U_1$. A similar analysis for the case of sampling without replacement shows that the latter may generally be a somewhat better strategy.

Let $A$ be a real $n \times n$ matrix, and denote $${ {\mathcal K}_U }^{(i,j)} =  \frac{n}{tr(A)} \left| a_{ii} - a_{jj} \right| ,\quad { {\mathcal K}_U }= \max_{\substack{1 \leq i,j \leq n \\ i \neq j}} { {\mathcal K}_U }^{(i,j)}.
\label{randsamp1_energy_dist}$$ Given a pair of positive small values $({\varepsilon},\delta)$, the inequality  holds with $D=U_{1}$ if $$N > \frac{{ {\mathcal K}_U }^{2}}{2} c({\varepsilon},\delta) \equiv \mathcal{F} ,
\label{randsamp1_bd}$$ and with $D=U_{2}$ if $$N \geq \frac{n+1}{1+\frac{n-1}{\mathcal{F}}} .
\label{randsamp2_bd}$$ \[randsamp\_thm\]

This proof is refreshingly short. Note first that every sample of these estimators takes on a Rayleigh value in $[n \min_{j} a_{jj} , n \max_{j} a_{jj}]$. The proof of , for the case with replacement, uses Hoeffding's inequality in exactly the same way as the corresponding theorem in @avto. We obtain directly that if  is satisfied then holds with $D = U_1$. For the case without replacement we use Serfling's inequality @serf to obtain $$Pr\left(| tr_{U_{2}}^{N}(A) - tr(A) | \geq {\varepsilon}tr(A) \right ) \leq 2 \exp \left\{ \frac{-2 N {\varepsilon}^2 }{\left(1-f_{N-1}\right) { {\mathcal K}_U }^{2}}  \right\} ,$$ where $f_N$ is the sampling fraction defined as $$f_{N} = \frac{N-1}{n-1} .$$ Now, for the inequality  to hold, we need $$2 \exp \left\{ \frac{-2 N {\varepsilon}^2 }{\left(1-f_{N-1}\right) { {\mathcal K}_U }^{2}} \right\} \leq \delta ,$$ so we require that $$\frac{N}{1-f_{N-1}} \geq \mathcal{F} .$$ The stated result is obtained following some straightforward algebraic manipulation. $\blacksquare$

Looking at the bounds  for $U_1$ and  for $U_2$ and observing the expression for ${ {\mathcal K}_U }$, one can gain insight as to the type of matrices which are handled efficiently using this estimator: this would be the case if the diagonal elements of the matrix all have similar values. In the extreme case where they are all the same, we only need one sample. The corresponding expression in @avto does not reflect this result. An illustration of the relative behaviour of the two bounds is given in Figure \[N\_randsamp\_comp\].

Numerical Examples {#numer}
==================

In this section we experiment with several examples, comparing the performance of different methods with regards to various matrix properties and verifying that the bounds obtained in our theorems indeed agree with the numerical experiments.

\[examp0\]

In this example we do not consider $\joshua43@example.org. Rather, we check numerically for various values of ${\varepsilon}$ what value of $N$ is required to achieve a result respecting this relative tolerance. We have calculated maximum and average values for $N$ over 100 trials for several special examples, verifying numerically the following considerations.

-   The matrix of all $1$s (in <span>Matlab</span>, <span>A=ones(n,n)</span>) has been considered in @avto. Here $tr(A) = n, \ { {\mathcal K}_H }= n-1$, and a very large $N$ is often required if ${\varepsilon}$ is small for both Hutchinson and Gauss methods. For the unit vector method, however, ${ {\mathcal K}_U }= 0$ in , so the latter method converges in one iteration, $N = 1$. This fact yields an example where the unit vector estimator is far better than either Hutchinson or Gaussian estimators; see Figure \[fig:all1s\].

-   Another extreme example, where this time it is the Hutchinson estimator which requires only one sample whereas the other methods may require many more, is the case of a diagonal matrix $A$. For a diagonal matrix, ${ {\mathcal K}_H }= 0$, and the result follows from Theorem \[hutch\_thm\_02\].

-   If $A$ is a multiple of the identity then, since ${ {\mathcal K}_U }= { {\mathcal K}_H }= 0$, only the Gaussian estimator from among the methods considered requires more than one sample; thus, it is worst.

-   Examples where the unit vector estimator is consistently (and significantly) worst are obtained by defining $A = Q^tDQ$ for a diagonal matrix $D$ with different positive elements which are of the same order of magnitude and a nontrivial orthogonal matrix $Q$.

-   We have not been able to come up with a simple example of the above sort where the Gaussian estimator shines over both others, although we have seen many occasions in practice where it slightly outperforms the Hutchinson estimator with both being significantly better than the unit vector estimators.

\[examp1\]

Consider the matrix $A = { {\bf x} }{ {\bf x} }^{t}/\|{ {\bf x} }\|^{2}$, where ${ {\bf x} }\in \mathbb{R}^{n}$, and for some $\theta > 0$, $x_{j} = \exp(-j \theta ), \ 1 \leq j \leq n$. This extends the example of all 1s of Figure \[fig:all1s\] (for which $\theta = 0$) to instances with rapidly decaying elements.

It is easy to verify that $$\begin{aligned}
& & tr(A) = 1, \quad r = 1, \quad { {\mathcal K}_G }= 1, \\ 
& & { {\mathcal K}_H }^{j} = \| { {\bf x} }\|^{2} x_{j}^{-2} - 1, \quad { {\mathcal K}_H }= \| { {\bf x} }\|^{2} x_{n}^{-2} - 1, \\ 
& & { {\mathcal K}_U }^{(i,j)} = \frac{n}{\| { {\bf x} }\|^{2}} |x_{i}^{2} - x_{j}^{2}| , \quad  
{ {\mathcal K}_U }= \frac{n}{\| { {\bf x} }\|^{2}} ( x_1^2 - x_n^2), \\
& & \| { {\bf x} }\|^{2} = \frac{\exp(-2 \theta) - \exp(-2 (n+1) \theta)}{1- \exp(-2 \theta)}.\end{aligned}$$

Figure \[fig:thetas\] displays the "actual sample size" $N$ for a particular pair $({\varepsilon}, \delta )$ as a function of $\theta$ for the three distributions. The values $N$ were obtained by running the code 100 times for each $\theta$ to calculate the empirical probability of success.

In this example the distribution of ${ {\mathcal K}_H }^{j}$ values gets progressively worse with heavier tail values as $\theta$ gets larger. However, recall that this matters in terms of the sufficient bounds and only so long as ${ {\mathcal K}_H }< 3$. Here the crossover point happens roughly when $\theta \sim 1/(2n)$. Indeed, for large values of $\theta$ the required sample size actually drops when using the Hutchinson method: Theorem \[hutch\_thm\_02\], being only a sufficient condition, merely distinguishes types of matrices for which Hutchinson is expected to be <span>*efficient*</span>, while making no claim regarding those matrices for which it is an inefficient estimator.

On the other hand, Theorem \[gauss\_thm\_02\] clearly distinguishes the types of matrices for which the Gaussian method is expected to be <span>*inefficient*</span>, because its condition is necessary rather than sufficient. Note that $N$ (the red curve in Figure \[fig:thetas\]) does not change much as a function of $\theta$, which agrees with the fact that the matrix rank stays fixed and low at $r=1$.

The unit vector estimator, unlike Hutchinson, deteriorates steadily as $\theta$ is increased, because this estimator ignores off-diagonal elements. However, for small enough values of $\theta$ the ${ {\mathcal K}_U }^{(i,j)}$'s are spread tightly near zero, and the unit vector method, as predicted by Theorem \[randsamp\_thm\], requires a very small sample size.

For Examples \[exp\_practical\] and \[exp\_properties\] below, given $({\varepsilon},\delta)$, we plot the probability of success, i.e., $Pr\left(| tr_{D}^{N}(A) - tr(A) | \leq {\varepsilon}~ tr(A) \right)$ for increasing values of $N$, starting from $N=1$. We stop when for a given $N$, the probability of success is greater than or equal to $1-\delta$. In order to evaluate this for each $N$, we run the experiments 500 times and calculate the empirical probability. In the figures below, 'With Rep.' and 'Without Rep.' refer to uniform unit sampling with and without replacement, respectively. In all cases, by default, ${\varepsilon}= \delta = .05$. We also provide distribution plots of the quantities ${ {\mathcal K}_H }^{j}, \ { {\mathcal K}_G }^{j}$ and ${ {\mathcal K}_U }^{(i,j)}$ appearing in , and , respectively. These quantities are indicators for the performance of the Hutchinson, Gaussian and unit vector estimators, respectively, as evidenced not only by Theorems \[hutch\_thm\_02\], \[gauss\_thm\_01\] and \[randsamp\_thm\], but also in Examples \[examp0\] and \[examp1\], and by the fact that the performance of the Gaussian and unit vector estimators is not affected by the energy of the off-diagonal matrix elements.

\[Data fitting with many experiments\] \[exp\_practical\]

A major source of applications where trace estimation is central arises in problems involving least squares data fitting with many experiments. In its simplest, linear form, we look for ${ {\bf m} }\in {{\rm I\!R}}^l$ so that the misfit function

$$\begin{aligned}
\phi ({ {\bf m} }) =  \sum_{i=1}^n \| J_i{ {\bf m} }- { {\bf d} }_i \|^2,
\label{misfita}\end{aligned}$$

for given data sets ${ {\bf d} }_i$ and sensitivity matrices $J_i$, is either minimized or reduced below some tolerance level. The $m \times l$ matrices $J_i$ are very expensive to calculate and store, so this is avoided altogether, but evaluating $J_i{ {\bf m} }$ for any suitable vector ${ {\bf m} }$ is manageable. Moreover, $n$ is large. Next, writing using the Frobenius norm as $$\begin{aligned}
\phi ({ {\bf m} }) =  \| C \|_F^2,
\label{misfitb}\end{aligned}$$ where $C$ is $m \times n$ with the $j$th column $C_j =  J_j{ {\bf m} }- { {\bf d} }_j$, and defining the SPSD matrix $A = C^tC$, we have $$\begin{aligned}
\phi ({ {\bf m} }) =  tr(A).
\label{misfitc}\end{aligned}$$ Cheap estimates of the misfit function $\phi({ {\bf m} })$ are then sought by approximating the trace in using only $N$ (rather than $n$) linear combinations of the columns of $C$, which naturally leads to expressions of the form . Hutchinson and Gaussian estimators in a similar or more complex context were considered in @HaberChungHermann2010 [@learhe; @yori]. \[misfit\]

Drawing the ${ {\bf w} }_i$ as random unit vectors instead is a method proposed in @doas3 and compared to others in @rodoas1, where it is called "random subset": this latter method can have efficiency advantages that are beyond the scope of the presentation here. Typically, $m \ll n$, and thus the matrix $A$ is dense and often has low rank.

Furthermore, the signs of the entries in $C$ can be, at least to some extent, considered random. Hence we consider below matrices $A = C^tC$ whose entries are Gaussian random variables, obtained using the <span>Matlab</span> command <span>C = randn(m,n)</span>. We use $m = 200$ and hence the rank is, almost surely, $r=200$.

It can be seen from Figure \[exp\_app\_fig\](a) that the Hutchinson and the Gaussian methods perform similarly here. The sample size required by both unit vector estimators is approximately twice that of the Gaussian and Hutchinson methods. This relative behaviour agrees with our observations in the context of actual application as described above, see @rodoas1. From Figure \[exp\_app\_fig\](d), the eigenvalue distribution of the matrix is not very badly skewed, which helps the Gaussian method perform relatively well for this sort of matrix. On the other hand, by Figure \[exp\_app\_fig\](b) the relative $\ell_{2}$ energies of the off-diagonals are far from being small, which is not favourable for the Hutchinson method. These two properties, in combination, result in the similar performance of the Hutchinson and Gaussian methods despite the relatively low rank. The contrast between ${ {\mathcal K}_U }^{(i,j)}$'s is not too large according to Figure \[exp\_app\_fig\](c), hence a relatively decent performance of both unit vector (or, random sampling) methods is observed. There is no reason to insist on avoiding repetition here either.

\[Effect of rank and ${ {\mathcal K}_G }$ on the Gaussian estimator\] \[exp\_rank\]

In this example we plot the actual sample size $N$ required for  to hold. In order to evaluate , we repeat the experiments 500 times and calculate the empirical probability. In all experiments, the sample sizes predicted by  and  were so pessimistic compared with the true $N$ that we simply did not include them in the plots.

In order to concentrate only on rank and ${ {\mathcal K}_G }$ variation, we make sure that in all experiments ${ {\mathcal K}_H }\ll 1$. For the results displayed in Figure \[Rank\_N\_G12\_H\](a), where $r$ is varied for each of two values of ${ {\mathcal K}_G }$, this is achieved by playing with <span>Matlab</span>'s normal random generator function <span>sprandn</span>. For Figure \[Rank\_N\_G12\_H\](b), where ${ {\mathcal K}_G }$ is varied for each of two values of $r$, diagonal matrices are utilized: we start with a uniform distribution of the eigenvalues and gradually make this distribution more skewed, resulting in an increased ${ {\mathcal K}_G }$. The low ${ {\mathcal K}_H }$ values cause the Hutchinson method to look very good, but that is not our focus here.

It can be clearly seen from Figure \[Rank\_N\_G12\_H\](a) that as the matrix rank gets lower, the sample size required for the Gaussian method grows significantly. For a given rank, the matrix with a smaller ${ {\mathcal K}_G }$ requires smaller sample size. From Figure \[Rank\_N\_G12\_H\](b) it can also be seen that for a fixed rank, the matrix with more skewed ${ {\mathcal K}_G }^{j}$'s distribution (marked here by a larger ${ {\mathcal K}_G }$) requires a larger sample size.

\[Method performance for different matrix properties\] \[exp\_properties\] Next we consider a much more general setting than that in Example \[exp\_rank\], and compare the performance of different methods with respect to various matrix properties. The matrix $A$ is constructed as in Example \[exp\_practical\], except that also a uniform distribution is used. Furthermore, a parameter $d$ controlling denseness of the created matrix is utilized. This is achieved in <span>Matlab</span> using the commands <span>C=sprandn(m,n,d)</span> or <span>C=sprand(m,n,d)</span>. By changing <span>m</span> and <span>d</span> we can change the matrix properties ${ {\mathcal K}_H }$, ${ {\mathcal K}_G }$ and ${ {\mathcal K}_U }$ while keeping the rank $r$ fixed across experiments. We maintain $n=1000, \, tr(A) = 1$ and ${\varepsilon}= \delta = .05$ throughout. In particular, the four figures related to this example are comparable to Figure \[exp\_app\_fig\] but for a lower rank.

By comparing Figures \[exp\_prop\_fig03\] and \[exp\_prop\_fig04\], as well as \[exp\_prop\_fig05\] and \[exp\_prop\_fig06\], we can see how not only the values of ${ {\mathcal K}_H }, \, { {\mathcal K}_G }$ and ${ {\mathcal K}_U }$, but also the distribution of the quantities they maximize matters. Note how the performance of both unit vector strategies is negatively affected with increasing average values of ${ {\mathcal K}_U }^{(i,j)}$'s. From the eigenvalue (or ${ {\mathcal K}_G }^{j}$) distribution of the matrix, it can also be seen that the Gaussian estimator is heavily affected by the skewness of the distribution of the eigenvalues (or ${ {\mathcal K}_G }^{j}$'s): given the same $r$ and $n$, as this eigenvalue distribution becomes increasingly uneven, the Gaussian method requires larger sample size.

Note that comparing the performance of the methods on different matrices solely based on their values ${ {\mathcal K}_H }$, ${ {\mathcal K}_G }$ or ${ {\mathcal K}_U }$ can be misleading. This can be seen for instance by considering the performance of the Hutchinson method in Figures \[exp\_prop\_fig03\], \[exp\_prop\_fig04\], \[exp\_prop\_fig05\] and \[exp\_prop\_fig06\] and comparing their respective ${ {\mathcal K}_H }^{j}$ distributions as well as ${ {\mathcal K}_H }$ values. Indeed, none of our $6$ sufficient bounds can be guaranteed to be generally tight. As remarked also earlier, this is an artifact of the generality of the proved results.

Note also that rank and eigenvalue distribution of a matrix have no direct effect on the performance of the Hutchinson method: by Figures \[exp\_prop\_fig05\] and \[exp\_prop\_fig06\] it appears to only depend on the ${ {\mathcal K}_H }^{j}$ distribution. In these figures, one can observe that the Gaussian method is heavily affected by the low rank and the skewness of the eigenvalues. Thus, if the distribution of ${ {\mathcal K}_H }^{j}$'s is favourable to the Hutchinson method and yet the eigenvalue distribution is rather skewed, we can expect a significant difference between the performance of the Gaussian and Hutchinson methods.

Conclusions and further thoughts {#concl}
================================

In this article we have proved six sufficient bounds for the minimum sample size $N$ required to reach, with probability $1-\delta$, an approximation for $tr(A)$ to within a relative tolerance ${\varepsilon}$. Two such bounds apply to each of the three estimators considered in Sections \[hutch\], \[gauss\] and \[randsamp\], respectively. In Section \[gauss\] we have also proved a necessary bound for the Gaussian estimator. These bounds have all been verified numerically through many examples, some of which are summarized in Section \[numer\].

Two of these bounds, namely, for Hutchinson and for Gaussian, are immediately computable without knowing anything else about the SPSD matrix $A$. In particular, they are independent of the matrix size $n$. As such they may be very pessimistic. And yet, in some applications (for instance, in exploration geophysics) where $n$ can be very large and ${\varepsilon}$ need not be very small due to uncertainty, these bounds may indeed provide the comforting assurance that $N \ll n$ suffices (say, $n$ is in the millions and $N$ in the thousands). Generally, these two bounds have the same quality.

The underlying objective in this work, which is to seek a small $N$ satisfying , is a natural one for many applications and follows that of other works. But when it comes to comparing different methods, it is by no means the only performance indicator. For example, variance can also be considered as a ground to compare different methods. However, one needs to exercise caution to avoid basing the entire comparison solely on variance: it is possible to generate examples where a linear combination of $\mathcal{X}^2$ random variables has smaller variance, yet higher tail probability. The lower bound that is available only for the Gaussian estimator may allow better prediction of the actual required $N$, in cases where the rank $r$ is known. At the same time it also implies that the Gaussian estimator can be inferior in cases where $r$ is small. The Hutchinson estimator does not enjoy a similar theory, but empirically does not suffer from the same disadvantage either.

The matrix-dependent quantities ${ {\mathcal K}_H }$, ${ {\mathcal K}_G }$ and ${ {\mathcal K}_U }$, defined in , and , respectively, are not easily computable for any given implicit matrix $A$. However, the results of Theorems \[hutch\_thm\_02\], \[gauss\_thm\_01\] and \[randsamp\_thm\] that depend on them can be more indicative than the general bounds. In particular, examples where one method is clearly better than the others can be isolated in this way. At the same time, the sufficient conditions in Theorems \[hutch\_thm\_02\], \[gauss\_thm\_01\] and \[randsamp\_thm\], merely distinguish the types of matrices for which the respective methods are expected to be efficient, and make no claims regarding those matrices for which they are inefficient estimators. This is in direct contrast with the necessary condition in Theorem \[gauss\_thm\_02\].

It is certainly possible in some cases for the required $N$ to go over $n$. In this connection it is important to always remember the deterministic method which obtains $tr(A)$ in $N$ applications of unit vectors: if $N$ grows above $n$ in a particular stochastic setting then it may be best to abandon ship and choose the safe, deterministic way.

exline

<span>**Acknowledgment**</span> We thank our three anonymous referees for several valuable comments which have helped to improve the text.\
Part of this work was completed while the second author was visiting IMPA, Rio de Janeiro, supported by a Brazilian "Science Without Borders" grant and hosted by Prof. J. Zubelli. Thank you all.

[^1]: Dept. of Computer Science, University of British Columbia, Vancouver, Canada <span>joshua43@example.org</span> . This work was supported in part by NSERC Discovery Grant 84306.

{'source': 'arXiv_out/1308'}