Documentation
¶
Overview ¶
Package randommatrix implements the core objects of random matrix theory (RMT) using only the Go standard library.
Random matrix theory studies the statistical behaviour of the eigenvalues of matrices whose entries are drawn at random. Despite the randomness of the individual entries, the collective spectrum obeys sharp, universal laws. This package provides seeded generators for the classical Gaussian and Wishart ensembles together with the analytic machinery used to describe their spectra.
The package is organised around a small number of themes:
Dense real and complex matrix types (Matrix and CMatrix) with the linear algebra needed to extract spectra: a Jacobi eigensolver for real symmetric matrices and a Hermitian eigensolver built on the real symmetric embedding.
Seeded generators for the Gaussian ensembles GOE (beta = 1), GUE (beta = 2) and GSE (beta = 4), for the Wishart / Laguerre ensembles, and for the Ginibre ensembles. Every generator takes an explicit int64 seed and uses math/rand, so results are reproducible and never depend on the wall clock or on a cryptographic source.
The limiting spectral laws: the Wigner semicircle law for Wigner matrices and the Marchenko-Pastur law for sample covariance (Wishart) matrices, with densities, cumulative distributions, supports and moments.
Edge fluctuations described by the Tracy-Widom distributions for beta = 1, 2, 4, provided through the accurate shifted-gamma approximation of Chiani (2014) together with tabulated moments and the soft-edge rescaling of the largest eigenvalue.
Bulk fluctuations described by the nearest-neighbour level-spacing distributions: the Poisson law for uncorrelated spectra and the Wigner surmise for the Gaussian ensembles, plus the level-spacing ratio statistics that avoid the need for spectral unfolding.
Spectral moments and elementary free probability: the Stieltjes / Cauchy transform, the R-transform, free cumulants via non-crossing partitions and free additive convolution of the semicircle law.
All randomness is seeded by the caller. Only the packages math, math/big, math/cmplx, sort, errors, fmt and strings are imported; there is no cgo and no third-party dependency.
Index ¶
- Constants
- Variables
- func BinomialBig(n, k int) *big.Int
- func BinomialCoefficient(n, k int) float64
- func CatalanBig(n int) *big.Int
- func CatalanNumber(n int) float64
- func CentralSpectralMoment(eigs []float64, k int) float64
- func ConditionNumberSymmetric(m *Matrix) (float64, error)
- func ConsecutiveSpacingRatios(eigs []float64) []float64
- func DeterminantSymmetric(m *Matrix) (float64, error)
- func EigenvaluesHermitian(m *CMatrix) ([]float64, error)
- func EigenvaluesSymmetric(m *Matrix) ([]float64, error)
- func EmpiricalCDF(data []float64, x float64) float64
- func EmpiricalCauchy(eigs []float64, z complex128) complex128
- func EmpiricalStieltjes(eigs []float64, z complex128) complex128
- func FactorialBig(n int) *big.Int
- func FreeConvolutionMoments(momentsA, momentsB []float64) []float64
- func FreeConvolutionSemicircleRadius(r1, r2 float64) float64
- func FreeConvolutionSemicircleVariance(var1, var2 float64) float64
- func FreeCumulantsFromMoments(moments []float64) []float64
- func GOEMeanRatio() float64
- func GOESpacingCDF(s float64) float64
- func GOESpacingDensity(s float64) float64
- func GSEMeanRatio() float64
- func GSESpacingCDF(s float64) float64
- func GSESpacingDensity(s float64) float64
- func GUEMeanRatio() float64
- func GUESpacingCDF(s float64) float64
- func GUESpacingDensity(s float64) float64
- func GaussianVector(n int, mean, std float64, seed int64) []float64
- func KolmogorovSmirnovStatistic(data []float64, cdf func(float64) float64) float64
- func LargestEigenvalue(m *Matrix) (float64, error)
- func MarchenkoPasturAtomMass(c float64) float64
- func MarchenkoPasturCDF(x, c, sigma2 float64) float64
- func MarchenkoPasturDensity(x, c, sigma2 float64) float64
- func MarchenkoPasturHasAtom(c float64) bool
- func MarchenkoPasturMean(c, sigma2 float64) float64
- func MarchenkoPasturMoment(k int, c, sigma2 float64) float64
- func MarchenkoPasturStieltjes(z complex128, c float64) complex128
- func MarchenkoPasturSupport(c, sigma2 float64) (lo, hi float64)
- func MarchenkoPasturVariance(c, sigma2 float64) float64
- func Max(xs []float64) float64
- func Mean(xs []float64) float64
- func MeanConsecutiveRatio(eigs []float64) float64
- func MeanSpacing(eigs []float64) float64
- func Min(xs []float64) float64
- func MomentsFromFreeCumulants(kappa []float64) []float64
- func NearestNeighbourSpacings(eigs []float64) []float64
- func NonCrossingPartitionsCount(n int) float64
- func NormalizedSpacings(eigs []float64) []float64
- func PoissonMeanRatio() float64
- func PoissonRatioDensity(r float64) float64
- func PoissonSpacingCDF(s float64) float64
- func PoissonSpacingDensity(s float64) float64
- func RTransformSeries(kappa []float64) []float64
- func RatioSurmiseDensity(r, beta float64) float64
- func RescaleLargestEigenvalue(lambdaMax float64, n int) float64
- func SampleGOE(n int, seed int64, scale float64) ([]float64, error)
- func SampleGUE(n int, seed int64, scale float64) ([]float64, error)
- func SampleWishartReal(n, p int, seed int64) ([]float64, error)
- func SemicircleCDF(x, radius float64) float64
- func SemicircleDensity(x, radius float64) float64
- func SemicircleFreeCumulants(variance float64, N int) []float64
- func SemicircleMoment(k int, radius float64) float64
- func SemicirclePeak(radius float64) float64
- func SemicircleRadius(variance float64) float64
- func SemicircleStieltjes(z complex128, radius float64) complex128
- func SemicircleSupport(radius float64) (lo, hi float64)
- func SemicircleVariance(radius float64) float64
- func SmallestEigenvalue(m *Matrix) (float64, error)
- func SortSpacings(spacings []float64) []float64
- func SortedCopy(xs []float64) []float64
- func SpacingRatios(eigs []float64) []float64
- func SpectralGaps(eigs []float64) []float64
- func SpectralMean(eigs []float64) float64
- func SpectralMoment(eigs []float64, k int) float64
- func SpectralMoments(eigs []float64, kmax int) []float64
- func SpectralQuantile(eigs []float64, q float64) float64
- func SpectralRadius(m *Matrix) (float64, error)
- func SpectralVariance(eigs []float64) float64
- func TracyWidomApproxParams(beta int) (k, theta, shift float64, ok bool)
- func TracyWidomCDF(s float64, beta int) float64
- func TracyWidomDensity(s float64, beta int) float64
- func TracyWidomEdgeCenter(n int) float64
- func TracyWidomEdgeScale(n int) float64
- func TracyWidomExcessKurtosis(beta int) float64
- func TracyWidomMean(beta int) float64
- func TracyWidomSkewness(beta int) float64
- func TracyWidomStdDev(beta int) float64
- func TracyWidomSupportedBeta(beta int) bool
- func TracyWidomVariance(beta int) float64
- func Unfold(eigs []float64, cdf func(float64) float64) []float64
- func UnfoldedSpacings(eigs []float64, cdf func(float64) float64) []float64
- func WignerSurmise(s, beta float64) float64
- func WignerSurmiseCDF(s, beta float64) float64
- func WishartTracyWidomCenter(n, p int) float64
- func WishartTracyWidomScale(n, p int) float64
- type CMatrix
- func CIdentity(n int) *CMatrix
- func GSE(n int, seed int64) *CMatrix
- func GUE(n int, seed int64) *CMatrix
- func GaussianCMatrix(rows, cols int, std float64, seed int64) *CMatrix
- func GinibreComplex(n int, seed int64) *CMatrix
- func LaguerreUnitary(n, p int, seed int64) *CMatrix
- func NewCMatrix(rows, cols int) *CMatrix
- func NewCMatrixFrom(rows, cols int, data []complex128) *CMatrix
- func WishartComplex(n, p int, seed int64) *CMatrix
- func (m *CMatrix) At(i, j int) complex128
- func (m *CMatrix) Clone() *CMatrix
- func (m *CMatrix) Cols() int
- func (m *CMatrix) ConjugateTranspose() *CMatrix
- func (m *CMatrix) FrobeniusNorm() float64
- func (m *CMatrix) Hermitianize() *CMatrix
- func (m *CMatrix) ImagPart() *Matrix
- func (m *CMatrix) IsHermitian(tol float64) bool
- func (m *CMatrix) IsSquare() bool
- func (m *CMatrix) Minus(other *CMatrix) (*CMatrix, error)
- func (m *CMatrix) Mul(other *CMatrix) (*CMatrix, error)
- func (m *CMatrix) Plus(other *CMatrix) (*CMatrix, error)
- func (m *CMatrix) RealPart() *Matrix
- func (m *CMatrix) Rows() int
- func (m *CMatrix) Scale(s complex128) *CMatrix
- func (m *CMatrix) Set(i, j int, v complex128)
- func (m *CMatrix) Trace() complex128
- type EigenSym
- type Histogram
- type Matrix
- func Diag(d []float64) *Matrix
- func GOE(n int, seed int64) *Matrix
- func GaussianMatrix(rows, cols int, mean, std float64, seed int64) *Matrix
- func GinibreReal(n int, seed int64) *Matrix
- func Identity(n int) *Matrix
- func LaguerreOrthogonal(n, p int, seed int64) *Matrix
- func NewMatrix(rows, cols int) *Matrix
- func NewMatrixFrom(rows, cols int, data []float64) *Matrix
- func NewMatrixFromRows(rows [][]float64) *Matrix
- func SampleCovarianceReal(n, p int, seed int64) *Matrix
- func WignerMatrix(n int, offStd, diagStd float64, seed int64) *Matrix
- func WishartReal(n, p int, seed int64) *Matrix
- func Zeros(rows, cols int) *Matrix
- func (m *Matrix) Add(i, j int, v float64)
- func (m *Matrix) At(i, j int) float64
- func (m *Matrix) Clone() *Matrix
- func (m *Matrix) Col(j int) []float64
- func (m *Matrix) Cols() int
- func (m *Matrix) Data() []float64
- func (m *Matrix) Diagonal() []float64
- func (m *Matrix) Equals(other *Matrix, tol float64) bool
- func (m *Matrix) FrobeniusNorm() float64
- func (m *Matrix) IsSquare() bool
- func (m *Matrix) IsSymmetric(tol float64) bool
- func (m *Matrix) MaxAbs() float64
- func (m *Matrix) Minus(other *Matrix) (*Matrix, error)
- func (m *Matrix) Mul(other *Matrix) (*Matrix, error)
- func (m *Matrix) MulVec(v []float64) ([]float64, error)
- func (m *Matrix) Plus(other *Matrix) (*Matrix, error)
- func (m *Matrix) Row(i int) []float64
- func (m *Matrix) Rows() int
- func (m *Matrix) Scale(s float64) *Matrix
- func (m *Matrix) Set(i, j int, v float64)
- func (m *Matrix) String() string
- func (m *Matrix) SubMatrix(r0, r1, c0, c1 int) *Matrix
- func (m *Matrix) Symmetrize() *Matrix
- func (m *Matrix) Trace() float64
- func (m *Matrix) Transpose() *Matrix
Examples ¶
Constants ¶
const ( BetaOrthogonal = 1 BetaUnitary = 2 BetaSymplectic = 4 )
Beta values identify the three classical symmetry classes by their Dyson index: 1 for the orthogonal (real) class, 2 for the unitary (complex) class and 4 for the symplectic (quaternion) class.
Variables ¶
var ErrDimensionMismatch = errors.New("randommatrix: dimension mismatch")
ErrDimensionMismatch is returned when two matrices have incompatible shapes for the requested operation.
var ErrNotSquare = errors.New("randommatrix: matrix is not square")
ErrNotSquare is returned when a square matrix is required but a rectangular one was supplied.
var ErrNotSymmetric = errors.New("randommatrix: matrix is not symmetric")
ErrNotSymmetric is returned when a symmetric matrix is required.
Functions ¶
func BinomialBig ¶
BinomialBig returns the exact binomial coefficient C(n, k) as a big integer. It returns zero when k < 0 or k > n.
func BinomialCoefficient ¶
BinomialCoefficient returns C(n, k) as a float64, computed exactly with big integers and then converted. It returns zero for k < 0 or k > n.
func CatalanBig ¶
CatalanBig returns the n-th Catalan number C_n = C(2n, n)/(n+1) as an exact big integer for n >= 0.
func CatalanNumber ¶
CatalanNumber returns the n-th Catalan number as a float64.
func CentralSpectralMoment ¶
CentralSpectralMoment returns the k-th central moment (1/n) sum (lambda_i - mean)^k of the eigenvalue sample.
func ConditionNumberSymmetric ¶
ConditionNumberSymmetric returns the spectral condition number |lambda_max| / |lambda_min| of a real symmetric matrix. It returns +Inf when the smallest absolute eigenvalue is zero.
func ConsecutiveSpacingRatios ¶
ConsecutiveSpacingRatios returns the restricted ratios r_i = min(s_i, s_{i-1}) / max(s_i, s_{i-1}) in [0, 1], which need no spectral unfolding.
func DeterminantSymmetric ¶
DeterminantSymmetric returns the determinant of a real symmetric matrix as the product of its eigenvalues.
func EigenvaluesHermitian ¶
EigenvaluesHermitian returns the eigenvalues of a Hermitian matrix in ascending order. It uses the real symmetric embedding of the Hermitian matrix H = A + iB into [[A, -B], [B, A]], whose 2n eigenvalues are those of H each repeated twice; the duplicates are collapsed.
func EigenvaluesSymmetric ¶
EigenvaluesSymmetric returns the eigenvalues of a real symmetric matrix in ascending order.
func EmpiricalCDF ¶
EmpiricalCDF returns the value of the empirical cumulative distribution function of the sample at x, i.e. the fraction of samples not exceeding x.
func EmpiricalCauchy ¶
func EmpiricalCauchy(eigs []float64, z complex128) complex128
EmpiricalCauchy returns the Cauchy transform (1/n) sum 1/(z - lambda_i), the negative of the Stieltjes transform.
func EmpiricalStieltjes ¶
func EmpiricalStieltjes(eigs []float64, z complex128) complex128
EmpiricalStieltjes returns the Stieltjes transform (1/n) sum 1/(lambda_i - z) of the empirical spectral distribution at complex argument z.
func FactorialBig ¶
FactorialBig returns n! as an exact big integer for n >= 0 and nil for n < 0.
func FreeConvolutionMoments ¶
FreeConvolutionMoments returns the moments of the free additive convolution of two distributions given their moment sequences. Free cumulants add, so the result is obtained by adding cumulants and converting back. The shorter of the two inputs sets the number of returned moments.
func FreeConvolutionSemicircleRadius ¶
FreeConvolutionSemicircleRadius returns the radius of the semicircle law obtained as the free additive convolution of two semicircle laws of the given radii, namely sqrt(R1^2 + R2^2).
func FreeConvolutionSemicircleVariance ¶
FreeConvolutionSemicircleVariance returns the variance of the free additive convolution of two semicircle laws, which is the sum of their variances.
func FreeCumulantsFromMoments ¶
FreeCumulantsFromMoments returns the free cumulants kappa_1..kappa_N implied by the moments m_1..m_N by inverting the free moment-cumulant relation.
func GOEMeanRatio ¶
func GOEMeanRatio() float64
GOEMeanRatio returns the surmise value 0.5307 of the mean restricted spacing ratio for the GOE.
func GOESpacingCDF ¶
GOESpacingCDF returns the GOE spacing distribution 1 - exp(-pi s^2/4).
func GOESpacingDensity ¶
GOESpacingDensity returns the GOE (beta = 1) Wigner surmise density (pi/2) s exp(-pi s^2/4).
func GSEMeanRatio ¶
func GSEMeanRatio() float64
GSEMeanRatio returns the surmise value 0.6744 of the mean restricted spacing ratio for the GSE.
func GSESpacingCDF ¶
GSESpacingCDF returns the GSE spacing distribution, integrated numerically.
func GSESpacingDensity ¶
GSESpacingDensity returns the GSE (beta = 4) Wigner surmise density (2^18/(3^6 pi^3)) s^4 exp(-64 s^2/(9 pi)).
func GUEMeanRatio ¶
func GUEMeanRatio() float64
GUEMeanRatio returns the surmise value 0.5996 of the mean restricted spacing ratio for the GUE.
func GUESpacingCDF ¶
GUESpacingCDF returns the GUE spacing distribution, integrated numerically.
func GUESpacingDensity ¶
GUESpacingDensity returns the GUE (beta = 2) Wigner surmise density (32/pi^2) s^2 exp(-4 s^2/pi).
func GaussianVector ¶
GaussianVector returns n independent N(mean, std^2) samples.
func KolmogorovSmirnovStatistic ¶
KolmogorovSmirnovStatistic returns the maximum absolute difference between the empirical CDF of the sample and the reference CDF, evaluated at the sample points.
func LargestEigenvalue ¶
LargestEigenvalue returns the algebraically largest eigenvalue of a real symmetric matrix.
func MarchenkoPasturAtomMass ¶
MarchenkoPasturAtomMass returns the mass max(0, 1 - 1/c) of the atom at zero of the Marchenko-Pastur law with aspect ratio c.
func MarchenkoPasturCDF ¶
MarchenkoPasturCDF returns the cumulative distribution function of the Marchenko-Pastur law with aspect ratio c and variance sigma2 at x, including the atom at zero when c > 1. The continuous part is integrated numerically.
func MarchenkoPasturDensity ¶
MarchenkoPasturDensity returns the continuous part of the Marchenko-Pastur density with aspect ratio c and variance sigma2 at x. It is zero outside the bulk support and does not include the possible atom at zero when c > 1.
func MarchenkoPasturHasAtom ¶
MarchenkoPasturHasAtom reports whether the Marchenko-Pastur law with aspect ratio c places an atom at zero (which happens exactly when c > 1).
func MarchenkoPasturMean ¶
MarchenkoPasturMean returns the mean sigma2 of the Marchenko-Pastur law.
func MarchenkoPasturMoment ¶
MarchenkoPasturMoment returns the k-th moment of the Marchenko-Pastur law with aspect ratio c and variance sigma2. It uses the Narayana expansion m_k = sigma2^k * sum_{r=0}^{k-1} 1/(r+1) * C(k,r) * C(k-1,r) * c^r.
func MarchenkoPasturStieltjes ¶
func MarchenkoPasturStieltjes(z complex128, c float64) complex128
MarchenkoPasturStieltjes returns the Stieltjes transform of the standard (sigma2 = 1) Marchenko-Pastur law with ratio c at complex argument z, using the branch that behaves like -1/z at infinity.
func MarchenkoPasturSupport ¶
MarchenkoPasturSupport returns the edges lambda_minus and lambda_plus of the Marchenko-Pastur law with aspect ratio c and per-entry variance sigma2.
func MarchenkoPasturVariance ¶
MarchenkoPasturVariance returns the variance c*sigma2^2 of the Marchenko-Pastur law.
func MeanConsecutiveRatio ¶
MeanConsecutiveRatio returns the mean of the restricted spacing ratios of the eigenvalue sample.
func MeanSpacing ¶
MeanSpacing returns the mean nearest-neighbour spacing of the eigenvalue sample.
func MomentsFromFreeCumulants ¶
MomentsFromFreeCumulants returns the moments m_1..m_N implied by the free cumulants kappa_1..kappa_N via the free moment-cumulant relation m_n = sum over non-crossing partitions of products of cumulants.
func NearestNeighbourSpacings ¶
NearestNeighbourSpacings returns the consecutive gaps of the sorted eigenvalue sample.
func NonCrossingPartitionsCount ¶
NonCrossingPartitionsCount returns the number of non-crossing partitions of an n-element set, which equals the n-th Catalan number.
func NormalizedSpacings ¶
NormalizedSpacings returns the nearest-neighbour spacings rescaled by their mean, a crude global unfolding that produces unit mean spacing.
func PoissonMeanRatio ¶
func PoissonMeanRatio() float64
PoissonMeanRatio returns the mean restricted spacing ratio 2 ln 2 - 1 for a Poisson spectrum.
func PoissonRatioDensity ¶
PoissonRatioDensity returns the surmise density 1/(1+r)^2 of the unrestricted consecutive-spacing ratio for a Poisson spectrum.
func PoissonSpacingCDF ¶
PoissonSpacingCDF returns the cumulative distribution 1 - exp(-s) of Poisson level spacings.
func PoissonSpacingDensity ¶
PoissonSpacingDensity returns the density exp(-s) of nearest-neighbour level spacings for an uncorrelated (Poisson) spectrum with unit mean spacing.
func RTransformSeries ¶
RTransformSeries returns the coefficients of the R-transform power series R(z) = sum_{n>=1} kappa_n z^(n-1) from the free cumulants kappa_1..kappa_N. The returned slice holds the coefficient of z^0, z^1, ... .
func RatioSurmiseDensity ¶
RatioSurmiseDensity returns the Atas et al. surmise density for the restricted spacing ratio r in [0, 1] at Dyson index beta, P(r) = (1/Z) (r + r^2)^beta / (1 + r + r^2)^(1 + 3 beta/2), with Z fixed by numerical normalisation.
func RescaleLargestEigenvalue ¶
RescaleLargestEigenvalue maps the largest eigenvalue lambdaMax of an n-by-n Gaussian ensemble to the Tracy-Widom scale via (lambdaMax - 2 sqrt(n)) * n^(1/6).
func SampleGOE ¶
SampleGOE returns the eigenvalues of GOE(n)/scale in ascending order. Passing scale = sqrt(n) places the bulk on [-2,2].
func SampleWishartReal ¶
SampleWishartReal returns the eigenvalues of the real sample covariance matrix (1/p) G Gᵀ in ascending order.
func SemicircleCDF ¶
SemicircleCDF returns the cumulative distribution function of the semicircle law of radius R evaluated at x.
func SemicircleDensity ¶
SemicircleDensity returns the Wigner semicircle density (2/(pi R^2)) sqrt(R^2 - x^2) at x for radius R; it is zero outside [-R, R].
func SemicircleFreeCumulants ¶
SemicircleFreeCumulants returns the free cumulants of the semicircle law of the given variance up to order N. Only the second cumulant is non-zero and equals the variance.
func SemicircleMoment ¶
SemicircleMoment returns the k-th moment of the semicircle law of radius R. Odd moments vanish; the (2m)-th moment equals the m-th Catalan number times (R/2)^(2m).
Example ¶
// Even moments of the semicircle law of radius 2 are the Catalan numbers.
fmt.Printf("%.0f %.0f %.0f %.0f\n",
SemicircleMoment(0, 2), SemicircleMoment(2, 2),
SemicircleMoment(4, 2), SemicircleMoment(6, 2))
Output: 1 1 2 5
func SemicirclePeak ¶
SemicirclePeak returns the maximum value 2/(pi R) of the semicircle density, attained at x = 0.
func SemicircleRadius ¶
SemicircleRadius returns the radius R = 2*sqrt(variance) of the Wigner semicircle law whose second moment (variance) equals the given value.
func SemicircleStieltjes ¶
func SemicircleStieltjes(z complex128, radius float64) complex128
SemicircleStieltjes returns the Stieltjes transform m(z) of the semicircle law of radius R, the value of the integral of 1/(x-z) against the density. The branch of the square root is chosen so that m(z) ~ -1/z as z -> infinity.
func SemicircleSupport ¶
SemicircleSupport returns the endpoints (-R, R) of the semicircle law of radius R.
func SemicircleVariance ¶
SemicircleVariance returns the variance R^2/4 of the semicircle law of radius R.
func SmallestEigenvalue ¶
SmallestEigenvalue returns the algebraically smallest eigenvalue of a real symmetric matrix.
func SortSpacings ¶
SortSpacings returns the ascending-sorted spacings, convenient for building empirical spacing distributions.
func SortedCopy ¶
SortedCopy returns a sorted (ascending) copy of xs, leaving the input intact.
func SpacingRatios ¶
SpacingRatios returns the ratios s_{i+1}/s_i of consecutive nearest-neighbour spacings of the eigenvalue sample.
func SpectralGaps ¶
SpectralGaps returns the consecutive differences of the sorted eigenvalues.
func SpectralMean ¶
SpectralMean returns the mean of the eigenvalue sample.
func SpectralMoment ¶
SpectralMoment returns the k-th empirical spectral moment (1/n) sum lambda_i^k of the eigenvalue sample eigs.
func SpectralMoments ¶
SpectralMoments returns the empirical spectral moments of orders 1..kmax.
func SpectralQuantile ¶
SpectralQuantile returns the q-quantile (0 <= q <= 1) of the eigenvalue sample using linear interpolation between order statistics.
func SpectralRadius ¶
SpectralRadius returns the largest absolute eigenvalue of a real symmetric matrix.
func SpectralVariance ¶
SpectralVariance returns the population variance of the eigenvalue sample.
func TracyWidomApproxParams ¶
TracyWidomApproxParams returns the shifted-gamma approximation parameters (shape k, scale theta, location shift) for the Tracy-Widom distribution of Dyson index beta. The approximation, due to Chiani (2014), models TW_beta ~ theta * Gamma(k) - shift and is accurate to about 0.01 in distribution. It returns ok = false for an unsupported beta.
func TracyWidomCDF ¶
TracyWidomCDF returns the Chiani shifted-gamma approximation of the Tracy-Widom cumulative distribution function of Dyson index beta at s. It returns NaN for an unsupported beta.
func TracyWidomDensity ¶
TracyWidomDensity returns the Chiani shifted-gamma approximation of the Tracy-Widom probability density of Dyson index beta at s.
func TracyWidomEdgeCenter ¶
TracyWidomEdgeCenter returns the soft-edge centring 2*sqrt(n) for the largest eigenvalue of an n-by-n Gaussian ensemble in the normalisation where the bulk fills [-2 sqrt(n), 2 sqrt(n)].
func TracyWidomEdgeScale ¶
TracyWidomEdgeScale returns the soft-edge scaling n^(-1/6), so that (lambda_max - 2 sqrt(n)) / scale converges to the Tracy-Widom law.
func TracyWidomExcessKurtosis ¶
TracyWidomExcessKurtosis returns the excess kurtosis 6/k of the shifted-gamma approximation to the Tracy-Widom distribution of Dyson index beta.
func TracyWidomMean ¶
TracyWidomMean returns the tabulated mean of the Tracy-Widom distribution of Dyson index beta.
func TracyWidomSkewness ¶
TracyWidomSkewness returns the skewness 2/sqrt(k) of the shifted-gamma approximation to the Tracy-Widom distribution of Dyson index beta.
func TracyWidomStdDev ¶
TracyWidomStdDev returns the standard deviation of the Tracy-Widom distribution of Dyson index beta.
func TracyWidomSupportedBeta ¶
TracyWidomSupportedBeta reports whether beta is one of the supported Dyson indices 1, 2 or 4.
func TracyWidomVariance ¶
TracyWidomVariance returns the variance k*theta^2 of the shifted-gamma approximation, which matches the tabulated Tracy-Widom variance.
func Unfold ¶
Unfold maps each eigenvalue lambda to n*cdf(lambda), where n is the number of eigenvalues and cdf is the integrated limiting spectral density. The transformed levels have unit mean spacing.
func UnfoldedSpacings ¶
UnfoldedSpacings returns the nearest-neighbour spacings of the eigenvalues after unfolding with the given integrated spectral density.
func WignerSurmise ¶
WignerSurmise returns the Wigner surmise density for Dyson index beta at spacing s, normalised to unit total mass and unit mean spacing. The classical cases are beta = 1 (GOE), beta = 2 (GUE) and beta = 4 (GSE).
Example ¶
// The Wigner surmise for the GUE (beta=2) at unit spacing.
fmt.Printf("%.4f\n", WignerSurmise(1, 2))
Output: 0.9076
func WignerSurmiseCDF ¶
WignerSurmiseCDF returns the cumulative distribution of the Wigner surmise for Dyson index beta at spacing s, integrated numerically.
func WishartTracyWidomCenter ¶
WishartTracyWidomCenter returns the Johnstone centring (sqrt(n-1) + sqrt(p))^2 for the largest eigenvalue of a real Wishart matrix built from an n-by-p Gaussian data matrix.
func WishartTracyWidomScale ¶
WishartTracyWidomScale returns the Johnstone scaling (sqrt(n-1) + sqrt(p)) (1/sqrt(n-1) + 1/sqrt(p))^(1/3) for the largest eigenvalue of a real Wishart matrix, so that (lambda_max - center)/scale converges to the Tracy-Widom law with beta = 1.
Types ¶
type CMatrix ¶
type CMatrix struct {
// contains filtered or unexported fields
}
CMatrix is a dense, row-major matrix of complex128 values.
func GSE ¶
GSE returns a sample from the Gaussian Symplectic Ensemble as a 2n-by-2n Hermitian, self-dual complex matrix built from an n-by-n array of quaternions. Each quaternion is embedded as a 2-by-2 complex block. Diagonal quaternions are real N(0,1); the four components of each off-diagonal quaternion are independent N(0,1/2). Every eigenvalue is doubly degenerate (Kramers degeneracy).
func GUE ¶
GUE returns a sample from the Gaussian Unitary Ensemble: a Hermitian n-by-n matrix whose diagonal entries are real N(0,1) and whose off-diagonal entries have real and imaginary parts drawn independently from N(0,1/2). The eigenvalues of GUE(n)/sqrt(n) converge to the semicircle law on [-2,2].
func GaussianCMatrix ¶
GaussianCMatrix returns a rows-by-cols complex matrix whose real and imaginary parts are independent N(0, std^2) samples.
func GinibreComplex ¶
GinibreComplex returns an n-by-n complex matrix whose entries have real and imaginary parts drawn independently from N(0,1/2), so that each entry has unit expected squared modulus (the complex Ginibre ensemble).
func LaguerreUnitary ¶
LaguerreUnitary is a synonym for WishartComplex.
func NewCMatrix ¶
NewCMatrix returns a rows-by-cols complex matrix of zeros.
func NewCMatrixFrom ¶
func NewCMatrixFrom(rows, cols int, data []complex128) *CMatrix
NewCMatrixFrom builds a complex matrix from a flat row-major slice, which is copied.
func WishartComplex ¶
WishartComplex returns the complex Wishart matrix G G†, where G is an n-by-p complex matrix with real and imaginary parts drawn independently from N(0,1/2). The result is an n-by-n Hermitian positive semidefinite matrix (the Laguerre unitary ensemble).
func (*CMatrix) At ¶
func (m *CMatrix) At(i, j int) complex128
At returns the entry at row i, column j.
func (*CMatrix) ConjugateTranspose ¶
ConjugateTranspose returns the conjugate (Hermitian) transpose m†.
func (*CMatrix) FrobeniusNorm ¶
FrobeniusNorm returns the Frobenius norm of the complex matrix.
func (*CMatrix) Hermitianize ¶
Hermitianize returns (m + m†)/2, the Hermitian part of a square matrix.
func (*CMatrix) IsHermitian ¶
IsHermitian reports whether m is square and Hermitian to within tol.
func (*CMatrix) Scale ¶
func (m *CMatrix) Scale(s complex128) *CMatrix
Scale multiplies every entry by the complex scalar s.
func (*CMatrix) Set ¶
func (m *CMatrix) Set(i, j int, v complex128)
Set assigns v to the entry at row i, column j.
func (*CMatrix) Trace ¶
func (m *CMatrix) Trace() complex128
Trace returns the sum of the diagonal entries.
type EigenSym ¶
EigenSym holds the eigen-decomposition of a real symmetric matrix. Values holds the eigenvalues in ascending order and column j of Vectors is the unit eigenvector belonging to Values[j].
func EigSymmetric ¶
EigSymmetric computes the full eigen-decomposition of a real symmetric matrix using the cyclic Jacobi algorithm. It returns an error if the matrix is not square. The matrix is symmetrised internally, so the strictly lower triangle is ignored.
type Histogram ¶
Histogram is a fixed-width histogram of a real sample. Edges has NumBins+1 entries; Counts[i] counts samples in [Edges[i], Edges[i+1]) except the last bin, which is closed on the right.
func EmpiricalSpectralDensity ¶
EmpiricalSpectralDensity returns a histogram of the eigenvalue sample using the given number of bins over the observed spectral range. It is a synonym for NewHistogramAuto tailored to spectra.
func NewHistogram ¶
NewHistogram bins the data into the given number of equal-width bins spanning [lo, hi]. Values outside the range are ignored. It panics if bins < 1 or hi <= lo.
func NewHistogramAuto ¶
NewHistogramAuto bins the data into the given number of bins spanning its observed range [min, max]. It panics if the data is empty or degenerate.
func (*Histogram) BinCenters ¶
BinCenters returns the midpoint of each bin.
func (*Histogram) Density ¶
Density returns the empirical probability density: Counts[i] divided by (Total * BinWidth). The returned values integrate to one over the range when no samples were discarded.
func (*Histogram) Probabilities ¶
Probabilities returns the fraction of samples in each bin.
type Matrix ¶
type Matrix struct {
// contains filtered or unexported fields
}
Matrix is a dense, row-major matrix of float64 values.
func GOE ¶
GOE returns a sample from the Gaussian Orthogonal Ensemble: a real symmetric n-by-n matrix whose off-diagonal entries are independent N(0,1) and whose diagonal entries are independent N(0,2). With this normalisation the eigenvalues of GOE(n)/sqrt(n) converge to the semicircle law on [-2,2].
Example ¶
// GOE matrices are real symmetric, and generation is fully seeded. m := GOE(3, 42) fmt.Println(m.IsSymmetric(1e-12))
Output: true
func GaussianMatrix ¶
GaussianMatrix returns a rows-by-cols matrix of independent N(mean, std^2) entries.
func GinibreReal ¶
GinibreReal returns an n-by-n matrix of independent standard normal real entries (the real Ginibre ensemble).
func LaguerreOrthogonal ¶
LaguerreOrthogonal is a synonym for WishartReal, emphasising its role as the beta = 1 Laguerre ensemble.
func NewMatrix ¶
NewMatrix returns a rows-by-cols matrix whose entries are all zero. It panics if either dimension is negative.
func NewMatrixFrom ¶
NewMatrixFrom builds a rows-by-cols matrix from a flat, row-major slice. The slice is copied. It panics if len(data) != rows*cols.
func NewMatrixFromRows ¶
NewMatrixFromRows builds a matrix from a slice of equal-length rows.
func SampleCovarianceReal ¶
SampleCovarianceReal returns (1/p) G Gᵀ where G is n-by-p standard normal. With ratio c = n/p its eigenvalues follow the Marchenko-Pastur law with variance one and ratio c, supported on [(1-sqrt(c))^2, (1+sqrt(c))^2] when c <= 1.
func WignerMatrix ¶
WignerMatrix returns a real symmetric n-by-n Wigner matrix with independent off-diagonal entries of standard deviation offStd and diagonal entries of standard deviation diagStd.
func WishartReal ¶
WishartReal returns the real Wishart matrix G Gᵀ, where G is an n-by-p matrix of independent standard normal entries. The result is an n-by-n symmetric positive semidefinite matrix (the Laguerre orthogonal ensemble).
func (*Matrix) FrobeniusNorm ¶
FrobeniusNorm returns the Frobenius norm, sqrt of the sum of squared entries.
func (*Matrix) IsSymmetric ¶
IsSymmetric reports whether m is square and symmetric to within tol.
func (*Matrix) Plus ¶
Plus returns the entrywise sum m + other. It returns an error on shape mismatch.
func (*Matrix) Symmetrize ¶
Symmetrize returns (m + mᵀ)/2, the symmetric part of a square matrix.