Skip to content
nonconvexcard

Simulate the Marchenko–Pastur law

CodingIntermediate⏱ 1 hourRandom Matricessimulationmarchenko-pasturuniversalitycovariance

Problem

Generate X∈Rn×pX\in\R^{n\times p} with i.i.d. unit-variance entries, form Σ^=1nX⊤X\hat\Sigma = \frac1nX^\top X, and compare the eigenvalue histogram with the Marchenko–Pastur density.

  1. Sweep λ=p/n\lambda = p/n and check the edges.
  2. Replace Gaussian entries with Rademacher and with a heavy-tailed unit-variance law; comment on the bulk and on the extreme eigenvalues.
  3. Add a rank-one spike Σ=I+h vv⊤\Sigma = I + h\,vv^\top and find empirically the value of hh at which the top eigenvalue separates from the bulk. Compare with λ\sqrt\lambda.

Implement it, then check the implementation against something you can verify independently.

Write it

Solve it here5 tests · Python runs in your browser
⌘/Ctrl + ↵ to run · limit 30s · draft saved in this browser
5 tests will run against your code. The first run downloads the Python runtime — several megabytes, once per browser.

Solution

Opening this before you have a real attempt on paper is the fastest way to feel like you understand something you cannot reproduce.

Related problems

All problems
SolvedProblemFieldTypeDifficultyTime
Marchenko–Pastur edges and conditioningRandom MatricesNumericalBeginner15 min
Simulate distance contrast runClassical MLCodingBeginner30 min
Balls into bins, with one choice and with two runAI SystemsCodingIntermediate1 hour
Cache hit rates under Zipf popularity runAI SystemsCodingIntermediate1 hour
Measure anisotropy in an embedding space runRAGCodingIntermediate1 hour