.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/rmt/paper_replications/tracy_widom_demo.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_rmt_paper_replications_tracy_widom_demo.py: Tracy-Widom Soft-Edge Laws ========================== For the Gaussian beta-ensembles GOE (:math:`\beta=1`), GUE (:math:`\beta=2`), and GSE (:math:`\beta=4`), the bulk of the :math:`n`-eigenvalue spectrum fills the semicircle :math:`[-2, 2]`, but the largest eigenvalue :math:`\lambda_{\max}` fluctuates *above* the edge :math:`2` on a much finer scale than the bulk spacing: rescaling .. math:: s = n^{2/3}(\lambda_{\max} - 2) \;\;(\beta=1,2), \qquad s = (2n)^{2/3}(\lambda_{\max} - 2) \;\;(\beta=4) converges in distribution to the Tracy-Widom law :math:`F_\beta(s)`, the universal "soft edge" statistic shared by a wide class of random matrix and growth-process models. All three laws are built from :math:`q(x)`, the Hastings-McLeod solution of the Painleve II equation :math:`q''(x) = x q(x) + 2 q(x)^3` with :math:`q(x) \sim \mathrm{Ai}(x)` as :math:`x \to +\infty`, via .. math:: F_2(s) = \exp\left(-\int_s^\infty (x-s)\, q(x)^2\, dx\right), .. math:: F_1(s) = \sqrt{F_2(s)}\, \exp\left(-\tfrac{1}{2}\int_s^\infty q(x)\, dx\right), \qquad F_4(s) = \sqrt{F_2(s)}\, \cosh\left(\tfrac{1}{2}\int_s^\infty q(x)\, dx\right). This example draws :math:`\lambda_{\max}` from Monte Carlo GOE/GUE/GSE samples, rescales it as above, and overlays the resulting histogram against the corresponding :math:`F_1`, :math:`F_2`, or :math:`F_4` density obtained by numerically integrating the Painleve II equation. References: C. A. Tracy, H. Widom, Commun. Math. Phys. 159 (1994) 151. C. A. Tracy, H. Widom, Commun. Math. Phys. 177 (1996) 727. Run: python examples/paper_replications/tracy_widom_demo.py .. GENERATED FROM PYTHON SOURCE LINES 47-90 .. image-sg:: /api/gallery/rmt/paper_replications/images/sphx_glr_tracy_widom_demo_001.png :alt: Tracy-Widom soft edge -- N=500, 400 samples per ensemble, GOE (beta=1) KS=0.0414, GUE (beta=2) KS=0.0480, GSE (beta=4) KS=0.0486 :srcset: /api/gallery/rmt/paper_replications/images/sphx_glr_tracy_widom_demo_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Saved tracy_widom_replication.png | .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import physicskit.rmt as rmt N = 500 N_SAMPLES = 400 SEED = 2026 fig, axes = plt.subplots(1, 3, figsize=(13, 4), sharey=True) s_grid = np.linspace(-5, 3, 400) for ax, (label, cls, beta) in zip( axes, [("GOE (beta=1)", rmt.ensembles.GOE, 1), ("GUE (beta=2)", rmt.ensembles.GUE, 2), ("GSE (beta=4)", rmt.ensembles.GSE, 4)], strict=True, ): ensemble = cls(n=N, seed=SEED) spectrum = ensemble.sample(n_samples=N_SAMPLES) benchmark = rmt.validation.TracyWidom(beta=beta) result = benchmark.validate(spectrum, seed=SEED) lam_max = rmt.stats.largest_eigenvalues(spectrum) scale = rmt.stats.tracy_widom_edge_scale(N, beta) edge_stat = scale * (lam_max - 2.0) ax.hist(edge_stat, bins=40, density=True, alpha=0.5, color="steelblue", label="empirical") theory_cdf = rmt.stats.tracy_widom_cdf(s_grid, beta) theory_pdf = np.gradient(theory_cdf, s_grid) tw_index = {1: 1, 2: 2, 4: 4}[beta] ax.plot(s_grid, theory_pdf, "k-", lw=2, label=f"Tracy-Widom F{tw_index}") ax.set_title(f"{label}\nKS={result.ks_statistic:.4f}") xlabel = r"$N^{2/3}(\lambda_{max} - 2)$" if beta != 4 else r"$(2N)^{2/3}(\lambda_{max} - 2)$" ax.set_xlabel(xlabel) ax.legend(fontsize=8) axes[0].set_ylabel("density") fig.suptitle(f"Tracy-Widom soft edge -- N={N}, {N_SAMPLES} samples per ensemble") fig.tight_layout() out_path = "tracy_widom_replication.png" fig.savefig(out_path, dpi=150) print(f"Saved {out_path}") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.063 seconds) .. _sphx_glr_download_api_gallery_rmt_paper_replications_tracy_widom_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: tracy_widom_demo.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: tracy_widom_demo.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: tracy_widom_demo.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_