In[]:=
deploy
Sat 29 May 2021 20:46:14
(*normalizematrixsothatithas1'sondiagonal*)​​normalizeDiag[mat_]:=Module[{},​​factors=DiagonalMatrix[1/Diagonal@mat];​​Sqrt[factors].mat.Sqrt[factors]​​];​​​​(*normalizematrixtohavetrace1*)​​traceNormalize[mat_]:=mat/Tr[mat];​​​​n=500;​​nMats=100;​​randMat:=RandomVariate[NormalDistribution[],{n,n}];​​randCov:=With[{m=RandomVariate[NormalDistribution[],{n,n}]},m.m];​​A=randMat;​​mat=A.Transpose[A];​​rank[m_]:=
Tr[m]
Norm[m]
;​​data={rank[#],rank[normalizeDiag[#]]}&/@Table[randCov,nMats];​​plot1=ListPlot[data,AxesLabel{"original","normalized"},PlotLabel"effective rank"];​​plot2=Plot[x,{x,Min[data],Max[data]},PlotStyleRed];​​Show[plot1,plot2]
Out[]=
In[]:=
(*createsomeill-conditionedmatrices*)​​(*returnrandomrotation/reflection*)​​randomRotation[n_]:=Module[{M,z,q,r,d,ph},​​​​z=RandomVariate[NormalDistribution[0,1],{n,n}];​​{q,r}=QRDecomposition[z];​​d=Diagonal[r];​​ph=d/Abs[d];​​M=q*ph​​];​​​​n=300;​​hess=DiagonalMatrix[Table[1/i,{i,1,n}]];​​​​eigs=Table[Eigenvalues[​​rot=randomRotation[n];​​normalizeDiag[rot.hess.rot]​​],{200}];​​​​plot1=ListPlot[Total[#]/Max[#]&/@eigs];​​plot2=Plot[Total[Diagonal@hess],{x,0,Length[eigs]},PlotStyleRed];​​Show[plot1,plot2,PlotRangeAll]
Out[]=
50
100
150
200
6.5
7.0
7.5
8.0

Measure effect on trace-normalized matrices

In[]:=
n=500;​​hess=DiagonalMatrix[Table[1./i,{i,1,n}]];​​hess=n*traceNormalize[hess];​​​​eigs=Table[Eigenvalues[​​rot=randomRotation[n];​​normalizeDiag[rot.hess.rot]​​],{200}];​​​​plot1=ListPlot[Max[#]&/@eigs];​​plot2=Plot[Max@hess,{x,0,Length[eigs]},PlotStyleRed];​​Show[plot1,plot2,PlotRangeAll]
Out[]=
50
100
150
200
60
62
64
66
68
70
72
74