In[]:=
(*deployswithcanonicalname*)deploy
Fri 4 Aug 2023 22:58:26
What does product of random matrices converge to?
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_]:=;y[t_]:=x[t];scale[a_]:=a*;(*horizontalscaling,sincetin0..*)xlim=(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};nvals=20,20;*)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},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}]
n+1
Sin[(n+1)t]
Sin[t]
n
Sin[nt]
2
Sin[t]
n-1
Sin[nt]
π
n
Sin[(n+1)t]
Pi
n+1
Pi
n+1
n
1+
1
n
17/20
2
9/10
5
17/20
2
9/10
5
37/40
2
19/20
5
37/40
2
19/20
5
80.1316
0.000063473
91.339
0.000063473
104.134
0.000063473
176.188
0.000063473
Out[]=
Different distributions
Different distributions
In[]:=
n=400;depth=100;genWeightedCDF[coefs_]:={#1,#1#2}&@@@genCDF[coefs];center[dist_]:=TransformedDistribution[x-Mean[dist],xdist];svals2[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,,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->{"","cdf value"}]
2
SingularValueList[mat]
-50
10
2
σ
Out[]=
Density after ReLU layers
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_]:=;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"]
2
SingularValueList[mat]
Out[]=