An efficient algorithm for sampling from $\\sin^k(x)$ for generating\n random correlation matrices

Enes Makalic, Daniel F. Schmidt · DOI

Abstract

In this note, we develop a novel algorithm for generating random numbers from a distribution with a probability density function proportional to $\sin^k(x)$, $x \in (0,\pi)$ and $k \geq 1$. Our algorithm is highly efficient and is based on rejection sampling where the envelope distribution is an appropriately chosen beta distribution. An example application illustrating how the new algorithm can be used to generate random correlation matrices is discussed.

Introduction

In modern statistics and data science, the generation of random correlation matrices is a fundamental task used for stress-testing financial models, simulating high-dimensional biological data, and validating Bayesian priors. A widely adopted method for this task is the "hyperspherical parameterization," which decomposes the correlation matrix into a series of angles. To ensure the resulting matrix is uniformly distributed (or follows a specific distribution over the space of correlation matrices), one must sample these angles from a probability density function (PDF) proportional to $\sin^k(x)$ for $x \in (0, \pi)$.

As the dimensionality of the matrix increases, the exponent $k$ also increases. This creates a significant computational bottleneck when using traditional sampling methods, particularly in high-dimensional settings where $k$ can reach into the thousands.

The Computational Bottleneck

The standard approach to sampling from $\sin^k(x)$ is inverse transform sampling. This method requires calculating the cumulative distribution function (CDF) and its inverse. However, the CDF for $\sin^k(x)$ is recursive in nature, requiring $O(k)$ operations to evaluate for a single sample.

For a $d \times d$ correlation matrix, the algorithm must generate $d(d-1)/2$ such samples. For a $1,000 \times 1,000$ matrix, this necessitates nearly 500,000 samples. When each sample requires $O(k)$ operations and $k$ scales with $d$, the total complexity becomes $O(d^3)$. This leads to significant latency and potential numerical instability as $k$ grows large.

Proposed Methodology: Rejection Sampling with a Beta Envelope

To overcome the $O(k)$ limitation, the authors propose a rejection sampling algorithm. Rejection sampling functions by drawing candidates from a simpler "envelope" distribution that covers the target distribution and then accepting or rejecting them based on a specific ratio.

The core innovation of this paper is the identification of a symmetric Beta distribution, specifically $Beta(k+1, k+1)$ scaled to the interval $(0, \pi)$, as a near-perfect envelope for $\sin^k(x)$.

The Algorithm

  1. Candidate Generation: Generate a candidate value $X$ from the symmetric Beta distribution.
  2. Uniform Draw: Generate a uniform random number $U \in [0, 1]$.
  3. Acceptance Criterion: Accept $X$ if a specific log-likelihood ratio condition is met, comparing the $\sin^k(x)$ density to the Beta PDF.
  4. Iteration: If rejected, repeat the process.

The authors utilize a proof involving interpolation polynomials to demonstrate that the Beta distribution is a mathematically valid envelope, ensuring that the target density never exceeds the scaled envelope density.

Efficiency and Key Insights

The efficiency of a rejection sampler is determined by how closely the envelope matches the target. The authors provide several key insights into why this approach is superior:

  • The Beta Match: As $k$ increases, the shape of the symmetric Beta distribution converges toward the shape of the $\sin^k(x)$ distribution. This ensures that the "wasted" samples (rejections) remain minimal.
  • Constant-Time Performance: Unlike the $O(k)$ inverse transform method, the computational cost of this rejection sampler is nearly independent of $k$. The authors prove that the maximum expected number of iterations required to produce a single valid sample is bounded by $\pi / (2\sqrt{2}) \approx 1.11$.
  • Predictability: Because the iterations are capped at a low constant, the algorithm's performance is highly predictable even as dimensionality scales to the thousands.

Empirical Results

The algorithm was implemented and tested in Matlab and R (the latter available via the randcorr package). The performance gains over the traditional inverse transform method are substantial:

  • Speedup: For a $600 \times 600$ correlation matrix, the traditional method requires approximately 42 seconds. The new rejection sampling algorithm completes the same task in roughly 0.5 seconds.
  • High-Dimensional Scaling: Generating the ~500,000 samples required for a $1,000 \times 1,000$ matrix takes only about 0.5 seconds on standard hardware.

Conclusion

By replacing a recursive $O(k)$ evaluation with a highly efficient rejection sampling scheme, the authors have removed a primary bottleneck in the generation of random correlation matrices. While the application is specific to the $\sin^k(x)$ distribution, its impact on high-dimensional simulation and Bayesian modeling is significant. The algorithm provides a robust, fast, and numerically stable solution for researchers working with large-scale covariance and correlation structures.

Summary updated

BibTeX
@article{makalic2022efficient,
  author = {Enes Makalic and Daniel F. Schmidt},
  title = {{An efficient algorithm for sampling from $\textbackslash\{\}\textbackslash\{\}sin^k(x)$ for generating\textbackslash\{\}n random correlation matrices}},
  journal = {Commun. Stat. Simul. Comput.},
  year = {2022},
  doi = {10.1080/03610918.2019.1700277},
}
Figure