\documentclass{article} \usepackage[margin=1in]{geometry} \usepackage{parskip} \usepackage{float} \usepackage{xcolor} \usepackage{graphicx} \graphicspath{{./figures/} {./figures/tracy-widom-approx/}} \usepackage{amsmath} \usepackage{booktabs} \usepackage{longtable} \usepackage{caption} \captionsetup{margin=0.5cm} % Sets a 1cm margin on both sides \captionsetup{labelfont=bf} \usepackage{hyperref} \hypersetup{colorlinks=true, linkcolor=black, urlcolor=blue, citecolor=black, pdftitle={Reconstructing the Tracy-Widom Distribution}, pdfpagemode=FullScreen} \usepackage{listings} \usepackage{algorithm} \usepackage{algpseudocode} \title{Reconstructing the Tracy-Widom Distribution\vspace{-0.75em}} \author{Connor Moore, 100826701. \today{}} \date{} \begin{document} \maketitle \section{Introduction} Random numbers form the basis of various studies in mathematics and the sciences. One strong example of this is \emph{Random Matrix Theory}, or the study of the construction and properties of random matrices. One of the first applications of random matrix theory was proposed by Eugene Wigner (1902-1995) in his application to model the nuclei and spectrum of various heavy atom \cite{anderson2009An_Int, wigner1955Charac}. It has since found different applications including work in computational mechanics, control theory, systems engineering, and others. Random matrix theory borrows some distributions from statistics to construct matrices. This includes the Gaussian (normal) distribution, which is used to make various matrices depending on which number system is used. Wigner's work included Orthogonal (real symmetric), Unitary (Complex Hermitian), and Symplectic (Quaternion Hermitian) matrices and their eigenvalues. This work considers Gaussian orthogonal ensembles (GOEs) specifically and attempts to reconstruct the Tracy-Widom distribution directly by computing eigenvalues. An overview of relevant theory, the necessary methods, and implementation details is provided before results are presented. The distribution is examined as a function of matrix dimension and sample size, and statistical testing is performed to support a Tracy-Widom being observed as opposed to a normal distribution. \section{Relevant Theory} \subsection{Random Ensembles} The GOE-based random matrix has some properties that go beyond simply being normally distributed. Namely, the matrix is square, symmetric, and the standard deviation $\sigma$ is unity except for elements on the diagonal where $\sigma=2$. The mean $\mu$ is considered as zero for all elements. Consider the normal distribution with notation $N(\mu, \sigma$). Then, the matrix is constructed using: \begin{equation*} \mathbf{A}(i,j) \sim \begin{cases} N(0, 1) & \forall (i \neq j) \\ N(0, 2) & \forall (i = j) \end{cases} \end{equation*} The diagonal standard deviation of 2 is what makes this ensemble orthogonal. Note that the representation above does not explicitly state the symmetry, but $\mathbf{A}(i,j) = \mathbf{A}(j,i)\, \forall(i,j)$. \subsection{The Tracy-Widom Distributions} Various distributions can be reconstructed from the eigenvalues of a GOE. For example, the case of the global eigenvalues yields a semicircle distribution \cite{anderson2009An_Int}. Consider the $N$ eigenvalues of a vector $|\lambda_1| \ge |\lambda_2| \ge |\lambda_3\| \ge ... \ge |\lambda_N|$. In this case, $\lambda_1$ is considered the \emph{dominant} eigenvalue so long as $|\lambda_1| > |\lambda_2|$. Taking the distribution of the dominant eigenvalues $\lambda_1$ yields an entirely different result that is known as the \emph{Tracy-Widom} distribution. This distribution can be parametrized in terms of which division algebra is used in its definition. Wigner's work considered real, complex, and Quaternion cases, shown below in Figure \ref{fig:tracy-widoms}: \begin{figure}[H] \centering \input{figures/tracy-widom-approx/tracy_widom.tex} \caption{Various Tracy-Widom distributions for $\beta=1,2,4$. The different values of $\beta$ depend on which division algebra is used for the Gaussian ensemble (real/complex/quaternion). This work considers only the TW\textsubscript{1} distribution defined for real numbers, shown in red as the shallowest peak compared with the complex and quaternion versions.} \label{fig:tracy-widoms} \end{figure} Compared with a normal distribution, it is also difficult to distinguish between the two visually. Figure \ref{fig:tracy-widom-vs-normal} shows a comparison between a Tracy-Widom and a normal distribution: \begin{figure}[H] \centering \input{figures/tracy-widom-approx/tracy_widom_compare.tex} \caption{The TW\textsubscript{1} distribution compared with a normal distribution of arbitrary mean and standard deviation. Note that while the peaks are centered, the Tracy-Widom has a `fatter' tail on the $+x$ side and a slimmer one on the $-x$ side. Both distributions are quite similar visually, so this asymmetry will play an important role in quantifying their differences.} \label{fig:tracy-widom-vs-normal} \end{figure} Because of their similarities, a smart approach to validating the generation of a Tracy-Widom distribution should include some type of quantifiable, statistical assurance that a normal distribution was not generated. \subsection{Statistical Differentiation} There are various ways to go about discerning a Tracy-Widom distribution from a normal one. Perhaps the most elegant is to exploit some basic differences in properties between the two. As mentioned earlier, the Tracy-Widom has a fatter side and a slimmer side, which makes it asymmetric. This is not the case with the normal distribution which is identical on either side of the mean value $\mu$. It turns out that the symmetry of a distribution is readily quantifiable using existing statistical tools, and as such that will be the backbone of the statistical analysis. First consider the \emph{expected value} of a probability density function (PDF) $p(x)$, defined as \cite{siegrist2021}: \begin{equation} E[x] = \int_s x p(x)\, dx \approx \left(\sum_i x_i\,p(i)\right) \Delta x \label{eqn:expected} \end{equation} where the approximation applies for a discrete PDF with equi-distance bins along $x$. The expected value has \emph{moments} that give quantifiable insights into the behaviour and shape of a PDF. The general equation for the $n$th central moment of $E(x)$ is given as: \begin{equation} E\left[(x-a_n)^n\right] \end{equation} where $a_n$ is some constant. The first moment (taken as a so-called \emph{raw moment} with $a=0$) simply reduces to \ref{eqn:expected}. The second moment is the variance of the function and is taken with $a=\mu$: \begin{equation} \sigma^2 = E\left[(x - E[x])^2\right] = E\left[ (x - \mu)^2\right] \end{equation} The next two moments are of particular value for this project as they quantify the symmetry of the distribution. The third moment is the \emph{skewness} of the distribution, which deviates from the central moments above and is normalized by the standard deviation $\sigma$: \begin{equation} \mathrm{Skewness} = E\left[\frac{(x-\mu)^3}{\sigma}\right] \end{equation} Lastly, the 4th moment is the kurtosis of the distribution. Kurtosis comes from the Greek word for \emph{bulging}, and as a parameter it quantifies the `sharpness' of the PDF. A larger value of kurtosis implies that the distribution has fatter tails \cite{siegrist2021}. Note that kurtosis is always a positive value and is equal to 3 for a standard normal distribution. Therefore, the \emph{excess} kurtosis is considered by subtracting 3. The relation is given as: \begin{equation} \mathrm{Excess\ Kurtosis} = E\left[ \frac{(x - \mu)^4}{\sigma} \right] - 3 \end{equation} These tests, while perhaps simple, will do a fine job in the strict context of differentiating a Tracy-Widom distribution from a normal distribution. In the case of the normal distribution, the skewness and excess kurtosis are both zero. For comparison, the approximate Tracy-Widom has a skewness of $\approx 0.2935$ and an excess kurtosis of $\approx 0.1292$.This was calculated using an Octave script\footnote{\href{https://git.hhmoore.ca/mcsc-6030g/p3-tracy-widom/tree/report/figures/tracy-widom-approx/plot_tracy_widom.m}{Available online} as part of the Git repository for the project.} that sampled 50,000 bins in the range $[-9,9]$ for both distributions. This also verified the calculations as it properly reconstructed the exact mean and standard deviation for the normal distribution sampled from its the closed-form equation. \section{Numerical Methods} The natural extension of defining the prerequisite statistical tests to confirm a Tracy-Widom is to actually sample a Tracy-Widom. The issue with this, however, is that it can be quite computationally demanding. The Tracy-Widom is quite similar to the normal except for near the very tails, meaning that most samples (occurring near the peaks) will show agreement between the two. Additionally, it is theorized that the dimension of the matrix $N$ has to be on the order of thousands to get a very Tracy-Widom distribution. The combination of these two points motivates finding a convenient way to calculate the maximum eigenvalue of a large matrix repeated such that thousands of calculations can be performed in a meaningfully short amount of time. \subsection{The Power Method} One relatively cheap way to find the maximum eigenvalue is through the so-called power method. The power method is an iterative approach to finding the maximum eigenvalue of a matrix that exploits the spectral gap ($\lambda_1 - \lambda_2$). Consider an initial guess in the form of a vector of length $N$ given as $\mathbf{x_0}$. Then, perform the multiplication: \begin{equation} \mathbf{x}_{k+1} = \mathbf{A}\mathbf{x}_k \end{equation} After multiplying, then normalize the vector such that $\left| \mathbf{x}_{k+1} \right|$ is unity: \begin{equation} \mathbf{x}_{k+1} = \frac{\mathbf{x}_{k+1}}{\left| \mathbf{x}_{k+1} \right|} \end{equation} Or, more compactly written as one step: \begin{equation} \mathbf{x}_{k+1} = \frac{\mathbf{A}\mathbf{x}_{k}}{\left|\mathbf{A}\mathbf{x}_{k}\right|} \end{equation} Repeating this will converge to the dominant eigenvalue $\lambda_1$ so long as $\mathbf{x}_0$ is not orthogonal to the dominant eigenvector \cite{novak2022}. The convergence of the method is $\mathcal{O}\left( \left| \lambda_1 / \lambda_2 \right|^k \right)$ and is largely dependent on the spectral gap. The main advantage of this method is that computationally it consists of only a matrix multiplication ($\mathcal{O}(n^2)$) and normalization ($\mathcal{O}(n)$) which is rather inexpensive compared with other methods per iteration \cite{watkins2002}. Worth noting, however, is that in cases where $\mathbf{A}$ has a small spectral gap it is not guaranteed to converge in an acceptable number of iterations. This poses an issue as it would bias the calculations for reconstructing the Tracy-Widom by not including random ensembles specifically with lower spectral gaps. To ratify this, more expensive methods exist which guarantee a solution that are used as a fallback. \subsection{Schur Decomposition} One method that guarantees a solution $\forall \mathbf{A}$ is Schur Decomposition. Named after the late Russian mathematician Issai Schur (1875-1941), Schur Decomposition involves decomposing the matrix $\mathbf{A}$ into a combination of some unitary matrix $\mathbf{U}$ and upper-triangular matrix $\mathbf{T}$ \cite{watkins2002}: \begin{equation} \mathbf{A} = \mathbf{U} \mathbf{T} \mathbf{U}^\mathrm{T} \end{equation} In this case, the diagonal entries in $\mathbf{T}$ are then the eigenvalues of the original matrix $\mathbf{A}$. The proof in Schur's theorem is non-constructive and does not provide a solution without knowing the eigenvectors of $\mathbf{A}$, but it can be still be used in combination with the so-called QR algorithm developed independently by John Francis (1934-present) and Vera Kublanovskaya (1920-2012) starting from 1959 \cite{golub2009The_QR}. Essentially, the QR algorithm is the computational scheme that provides the matrices $\mathbf{U}$ and $\mathbf{T}$ from the input $\mathbf{A}$. It does so with a complexity of $\mathcal{O}(n^3)$, which for larger values of $N$ deviates significantly from the $\mathcal{O}(n^2)$ of the power method. For this reason it is used only when the power method fails. \section{Implementation and MPI Parallelization} The last remaining hurdle to computing the eigenvalues is the magnitude of memory required to store such large matrices. Because the requirements will be in the gigabytes range for most calculations, shared-memory parallelism can have issues supporting large-scale calculations needed to accurately define the Tracy-Widom. Because of this, the solution is designed around MPI parallelism with distributed and independent memory between ranks. There are fewer opportunities for race conditions and threads `overstepping' each other in MPI, however care must be taken that the now independent workers can communicate with each other properly. \subsection{Worker-Manager Structure} The program used in this project employed a worker-manager structure to drive the eigenvalue calculations. The first worker is assigned to be a manager and handle the seeding and results collection for the other workers. Everyone else is focused solely on calculating eigenvalues and reporting their results to the manager when finished. This setup allows for the independent calculation of as many eigenvalues as MPI ranks are supported at once, which can approach the order of hundreds or even thousands if compute resources are available on a respectable cluster. \subsection{The Manager Process} The manager process is relatively straightforward and focuses more on the `book keeping' side of the eigenvalue calculations. To demonstrate this, a pseudocode explaining the behaviour of the manager MPI rank is presented below in Algorithm \ref{alg:manager}: \begin{algorithm}[H] \caption{MPI Manager Process} \begin{algorithmic}[1] % [1] enables line numbers \State N,L $\gets$ Matrix size and number of data points \State Open logfile and write $N$, $L$ for reference \While{Workers not finished} \For{$i=1:N_{workers}$} \If{Worker $i$ is ready and needed} \State seed $\gets$ \texttt{/dev/urandom} \State \texttt{MPI Broadcast}: send the worker seed \EndIf \EndFor \If{All workers are finished} \State Break loop and finish managing \EndIf \State \texttt{MPI Receive}: wait for a worker to finish calculating... \State Identify which worker is finished calculating and their result \If{Eigenvalue was calculated successfully} \State Tally to the number of successful eigenvalue calculations \State Write the worker number and eigenvalue to logfile \Else \State Tally to the number of failed eigenvalue calculations \State Print a warning message \EndIf \If{Worker is still needed} \State Set worker flag to `Ready' \Else \State Tell worker to conclude \EndIf \EndWhile \end{algorithmic} \label{alg:manager} \end{algorithm} Note that the actions labelled with involving MPI communication that is blocking, i.e., the worker/manager will wait to receive a broadcast before continuing at all. \subsection{The Calculation (Worker) Process} The worker process involves calculating the eigenvalues and is more complicated than the manager process. Various sub-processes are included in different algorithms, namely for building the matrix, computing the eigenvalue, and applying the power method. The overview of the whole process is outlined in Algorithm \ref{alg:worker}: \begin{algorithm}[H] \caption{MPI Worker Process} \begin{algorithmic}[1] % [1] enables line numbers \State size $\gets$ \texttt{MPI Receive}: matrix size \State Initialize matrix space in memory \While{Worker not Finished} \State seed $\gets$ \texttt{MPI Receieve}: new matrix seed \State Call \texttt{open\_prng\_seed}(seed) \State matrix $\gets$ \texttt{build\_random\_matrix}(size) \State eig $\gets$ \texttt{calculate\_eigenvalue}(matrix) \State \texttt{MPI Send}: eig and relevant information \EndWhile \end{algorithmic} \label{alg:worker} \end{algorithm} The algorithm for assembling the random matrix given a size is provided below in Algorithm \ref{alg:random-matrix}: \begin{algorithm}[H] \caption{MPI Worker: Random Matrix Building} \begin{algorithmic}[1] % [1] enables line numbers \Procedure{build\_random\_matrix}{size} \For{$i = 1:$ size} \State \textbf{A}(i,i) = N(0,2) \For{$j = 1:i-1$} \State \textbf{A}(i,j) = N(0,1) \State \textbf{A}(j,i) = \textbf{A}(i,j) \EndFor \EndFor \State \Return \textbf{A} \EndProcedure \end{algorithmic} \label{alg:random-matrix} \end{algorithm} And likewise for the eigenvalue calculation in Algorithm \ref{alg:eigenvalue-calculation}: \begin{algorithm}[H] \caption{MPI Worker: Eigenvalue Calculation} \begin{algorithmic}[1] % [1] enables line numbers \Procedure{calculate\_eigenvalue}{matrix} \State Initialize convergence tolerance $\varepsilon$ and maximum iterations for power iteration \State Call \texttt{power\_iteration}(matrix, shift=0) \If{power iteration converged} \If{$\lambda < 0$} \State Call \texttt{power\_iteration}(matrix, shift=$\lambda$) \EndIf \Else \State call \texttt{MKL\_schur\_decomposition}(matrix) \If{decomposition successful} \State eig $\gets$ Largest eigenvalue from decomposition \State Set `converged' flag to `true' \Else \State Print warning message \Comment{Not touching the converged flag leaves it `false'} \EndIf \EndIf \EndProcedure \end{algorithmic} \label{alg:eigenvalue-calculation} \end{algorithm} So far the structure has involved a minimal amount of math. This is only because it has been hidden behind abstraction and by using the MKL library to call pre-made functions for computing eigenvalues. The power iteration method was implemented by hand and involves more math as shown in Algorithm \ref{alg:power-iteration}: \begin{algorithm}[H] \caption{MPI Worker: Power Iteration} \begin{algorithmic}[1] % [1] enables line numbers \Procedure{power\_iteration}{matrix, shift=0} \State Initialize a random vector $\mathbf{x}_o$ = N(0,1) \State $\mathbf{x}_0 \gets \frac{\mathbf{x}_0}{\left|\mathbf{x}_0\right|}$ \Comment{Normalize} \State mem $\gets$ $-100$ \For{$i = 1:$ max\_iterations} \State $\mathbf{y} \gets \mathbf{A}\mathbf{x}_{i-1}$ \State $\mathbf{y} \gets \mathbf{y} + $shift$\times\mathbf{x}_{i-1}$ \State eig $\gets$ \texttt{dot\_product}($\mathbf{x}_{i}$,$\mathbf{x}_{i-1}$) - shift \State error $\gets\ \frac{\left| \mathrm{mem} - \mathrm{eig}\right|}{\left| \mathrm{mem} \right|}$ \If{err $< \varepsilon$} \State Set `converged' flag to `true' \State \Return{eig} \Else \State $\mathbf{x}_i \gets \frac{\mathbf{x}_i}{\left| \mathbf{x}_i \right|}$ \State mem $\gets$ eig \EndIf \EndFor \EndProcedure \end{algorithmic} \label{alg:power-iteration} \end{algorithm} These algorithms compose the entirety of the program for reconstructing the Tracy-Widom distributions discussed earlier. \section{Results} \bibliographystyle{ieeetr} \bibliography{refs.bib} \end{document}