WOLFRAM NOTEBOOK

In[]:=
(*deployswithcanonicalname*)
CompoundExpression[
]
deploy
Fri 4 Aug 2023 22:58:26

What does product of random matrices converge to?

Use formula 3.61 of Ipsen’s thesis -- https://arxiv.org/pdf/1510.06128.pdf
In[]:=
ClearAll["Global`*"];x[t_]:=
n+1
Sin[(n+1)t]
Sin[t]
n
Sin[nt]
;y[t_]:=
2
Sin[t]
n-1
Sin[nt]
π
n
Sin[(n+1)t]
x[t];scale[a_]:=a*
Pi
n+1
;(*horizontalscaling,sincetin0..
Pi
n+1
*)xlim=
n
1+
1
n
(1+n);(*verticalscaling,Assuming[{n>1},Limit[x[t],t->0]]*)xScaled[t_]:=x[scale[t]]/xlim;yScaled[t_]:=y[scale[t]]*xlim;nmax=200;nvals=Exp/@Subdivide[Log@1,Log@nmax,40];(*nvals={20
17/20
2
9/10
5
};nvals=20
17/20
2
9/10
5
,20
37/40
2
19/20
5
;*)pr={{0,1.05},{0,2.5}};trange={t,0,99/100};funcs=Table[{xScaled[t],yScaled[t]},{n,nvals}];parametricStart=ParametricPlot@@{First@funcs,trange,PlotRange->pr,AspectRatio->1,PlotLabel->"Limiting density",PlotStyle->{{Gray}},PlotLegends->{"n=1"},WorkingPrecision->10,Exclusions->{0}};parametric=ParametricPlot@@{Rest@funcs,trange,PlotRange->pr,AspectRatio->1,PlotLabel->"Limiting density",PlotStyle->{{Thin,Gray}},WorkingPrecision->10,Exclusions->{0}};parametric0=Block[{n=20
37/40
2
19/20
5
},ParametricPlot@@{{xScaled[t],yScaled[t]},trange,PlotRange->pr,AspectRatio->1,PlotLabel->"Eigenvalue density for product of random matrices",PlotStyle->{Bold},WorkingPrecision->30,PlotLegends->{"n=100"},Exclusions->{0}}];Show[parametricStart,parametric0,parametric,Ticks->{Automatic,None}]
General
:
80.1316
0.000063473
is too small to represent as a normalized machine number; precision may be lost.
General
:
91.339
0.000063473
is too small to represent as a normalized machine number; precision may be lost.
General
:
104.134
0.000063473
is too small to represent as a normalized machine number; precision may be lost.
General
:Further output of General::munfl will be suppressed during this calculation.
General
:
176.188
0.000063473
is too small to represent as a normalized machine number; precision may be lost.
Out[]=
n=1
n=100

Different distributions

In[]:=
n=400;depth=100;genWeightedCDF[coefs_]:={#1,#1#2}&@@@genCDF[coefs];center[dist_]:=TransformedDistribution[x-Mean[dist],xdist];svals2[mat_]:=
2
SingularValueList[mat]
;distPairs={{"normal",NormalDistribution[]},{"uniform",UniformDistribution[{-1,1}]},{"bernoulli",center@BernoulliDistribution[.5]}};getDensity[dist_]:=(sample:=RandomVariate[dist,{n,n}]/Sqrt[n];sampled:=Nest[sample.#&,sample,depth-1];spectralNormalize[evals_]:=evals/Max[evals];genCDF[coefs_]:={spectralNormalize@Sort@coefs,Range[Length@coefs]/Length[coefs]};genWeightedCDF[svals2@sampled]);sf={"Log","Log"};SF=StringForm;observedPlot=ListPlot[getDensity[Last[#]]&/@distPairs,PlotLegends->(First/@distPairs),PlotRange->All,ScalingFunctions->sf,PlotStyle->PointSize[Small]];predictedPlot=Plot[x,{x,
-50
10
,1},PlotStyle->{Opacity[.5],Gray},PlotLegends->{"y=x"},ScalingFunctions->sf];Show[observedPlot,predictedPlot,ImageSize->Large,ScalingFunctions->sf,PlotLabel->SF["Weighted spectral density CDF, product of `` random matrices, n=``",depth,n],AxesLabel->{"
2
σ
","cdf value"}]
Out[]=
normal
uniform
bernoulli
y=x

Density after ReLU layers

In[]:=
ClearAll["Global`*"];n=400;depth=50;sample:=RandomVariate[NormalDistribution[],{n,n}];spectralNormalize[evals_]:=evals/Max[evals];genCDF[coefs_]:={spectralNormalize@Sort@coefs,Range[Length@coefs]/Length[coefs]};genWeightedCDF[coefs_]:={#1,#1#2}&@@@genCDF[coefs];svals2[mat_]:=
2
SingularValueList[mat]
;center[mat_]:=(mat-Mean[Flatten@mat]);relu[mat_]:=Clip[mat,{0,}];rotate[mat_]:=RandomVariate[CircularRealMatrixDistribution[n]].mat;permute[mat_]:=RandomSample[mat];mats=NestList[#.sample&,sample,depth-1];ListLinePlot[genWeightedCDF[svals2[#]]&/@mats,PlotRange->All,PlotHighlighting->Directive[Red,Thickness[.02]],PlotLegends->Range[depth],PlotLabel->"Gaussian products"]
Out[]=
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.