Mathematically rigorous ML model diagnostics: stationarity verdict, effective dimension, barrier certificate
Project description
spectraldiag
Mathematically rigorous ML model diagnostics.
Answers not "what happened" (that's W&B) but "why it happened and what to do" — with mathematical proof, not empirical guessing.
pip install spectraldiag
Three core functions
stationarity_verdict(ntk_eigs, target_coeffs, s=-1, d_star=-1)
Is your model's feature learning done, or still evolving?
from spectraldiag import stationarity_verdict
# Without d_star: measures the source exponent r only.
result = stationarity_verdict(ntk_eigs, target_coeffs)
print(result.reason)
# STATIONARY. Source exponent r_hat=0.491 (±0.031) is consistent with r=0.5
# (self-organised criticality). The learned kernel has reached the stationary
# attractor. Provide d_star to obtain the data-scaling barrier β₀.
# With the measured data intrinsic dimension, you also get the barrier:
result = stationarity_verdict(ntk_eigs, target_coeffs, s=1.0, d_star=8.2)
# ... With d*=8.2, the Sobolev minimax barrier is β₀=0.196: asymptotically,
# loss improves no faster than D^{-0.196} in the data-rich regime.
What it computes: fits the realised source exponent r from the empirical
NTK spectrum. r ≈ 0.5 certifies the model reached the stationary attractor.
The data-scaling barrier β₀ = 2s/(2s+d*) is a separate quantity that needs
the data intrinsic dimension d* — so it is only reported when you pass
d_star. Without it, beta_0 is returned as -1 (undefined) rather than
guessed. If s is omitted, it is inferred from the kernel decay via the Weyl
law s = b·d*/2.
effective_dimension(laplacian_eigs, approx_errors, model_sizes, s=1.0)
Does your data have compositional structure your model could exploit?
from spectraldiag import effective_dimension
result = effective_dimension(laplacian_eigs, approx_errors, model_sizes, s=1.0)
print(result.verdict)
# COMPOSITIONAL STRUCTURE DETECTED. Data intrinsic dimension d*=8.2 but
# effective task dimension d_loc=2.1. Compositional approximation exponent
# α=0.95 vs Sobolev baseline α=0.24 — 3.9× compression gain available.
d* comes from the graph-Laplacian spectrum; d_loc from the model-side
approximation exponent α = 2s/d_loc, which is why the smoothness s is a
parameter (default 1.0).
What it computes: estimates d* from the graph-Laplacian spectrum of your data, d_loc from the model-side approximation exponent. If d_loc < d*, genuine compositional structure exists — and the phase transition theorem says emergence is real.
barrier_certificate(d_star, d_loc, s, current_loss, current_N, current_D)
Where is your model relative to the theoretical ceiling?
from spectraldiag import barrier_certificate
result = barrier_certificate(
d_star=8.0, d_loc=2.0, s=1.25,
current_loss=0.42, current_N=1e8, current_D=1e11
)
print(result.verdict)
# BARRIER CERTIFICATE. Theoretical ceiling β₀=0.238. With compositional
# structure (d_loc=2.0), barrier rises to β'=0.556 — 2.3× faster data
# scaling. Training budget D=1e11 has NOT passed the crossover D_cross≈...
One-line integration
from spectraldiag.callbacks import make_hf_callback
trainer = Trainer(
...,
callbacks=[make_hf_callback(eval_data=(X_val, y_val))]
)
Works with HuggingFace Trainer and PyTorch Lightning out of the box.
Graph-Laplacian protocol (for real data)
from spectraldiag.graph_lap import graph_laplacian_eigs, estimate_d_star, double_dimension_consistency
eig_vals, eig_vecs = graph_laplacian_eigs(X_data, knn=10)
d_star = estimate_d_star(eig_vals)
consistency = double_dimension_consistency(d_star_data=d_star, d_loc_model=d_loc_from_model)
print(consistency["verdict"])
Mathematical foundation
This library implements the three-paper programme:
- TR — Boundaries of Stationary Feature Learning: the Sobolev minimax barrier
β₀, self-organised criticalityr=½, approximation exponentα=2s/d* - AB — Foundations of a Theory of Composable Abstractions: defect as projection, effective dimension
d_loc, subspace gap as the order parameter - BM — Spectral Scaling Benchmark: the decisive-test protocol, source exponent measurement, graph-Laplacian intrinsic dimension estimation
The decisive invariant: d_loc < d* ⟺ emergence is real ⟺ the phase transition theorem applies.
Build from source
pip install -e ".[all]"
Requires only a C++17 compiler. The C++ core is a standard CPython extension built automatically by setuptools — no CMake, no pybind11, no extra build dependencies.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file spectraldiag-0.2.0.tar.gz.
File metadata
- Download URL: spectraldiag-0.2.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
530292e518080d00b5f7ceccef479a206ae9e2dd8b76342d379aa0975ac1c75f
|
|
| MD5 |
b0a0140572bfbfe71afd959386d57702
|
|
| BLAKE2b-256 |
9c964e599a535817f9421560879055860c34b8827846bff1ac82dc35558e03d8
|
File details
Details for the file spectraldiag-0.2.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 39.1 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c60e809554d603574bde271ca599dca3ff1891572cec3b688feeb03465c5d5f
|
|
| MD5 |
2dc0d35caa351ba4b6ede7e53d7333ee
|
|
| BLAKE2b-256 |
815f9400f00cc466e8794dac78162cb2397a2a2675246f8e7b811261d774c23e
|
File details
Details for the file spectraldiag-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 209.5 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5061bf06fc5bd68dd853f4746093b524189685dd1e65c2909411761ed93d331d
|
|
| MD5 |
1dc3647753f3c6330e65007ca85dd00d
|
|
| BLAKE2b-256 |
d15c8182566bb15a3c95320a2512d27a49f084648b9a0eb25eff0e970b576399
|
File details
Details for the file spectraldiag-0.2.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 33.6 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bc62f00a6d3f54670cf0c047541ba597fae817d68321f7b84ed9f62a59e857c
|
|
| MD5 |
4fbc71dd5413c43e967d3362d5c6f90d
|
|
| BLAKE2b-256 |
9a36815b942ec33445a69214ed7a33617e6a9221d3dba070b832fb7706956e73
|
File details
Details for the file spectraldiag-0.2.0-cp312-cp312-macosx_10_9_x86_64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp312-cp312-macosx_10_9_x86_64.whl
- Upload date:
- Size: 33.7 kB
- Tags: CPython 3.12, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
596ad5e76beef8da9e49564c6ebfd1519ecc0c3d682830bb60694c8c6bebb22b
|
|
| MD5 |
b96f205397579981ccbac700b19d3377
|
|
| BLAKE2b-256 |
d9012e03ba1059cdf920578e7345a542b47ac8726039dd6a1be7de04131f5372
|
File details
Details for the file spectraldiag-0.2.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 39.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93e8b3ec98ad04bfde37c0cc7a767fee94380c8ecfc91276302032941e7f2c4e
|
|
| MD5 |
9938892b406e706122b9e3dec662091d
|
|
| BLAKE2b-256 |
fb43d33e9c4f45f83d939bbf196831073b88da42092772bddd7b0a521092b47d
|
File details
Details for the file spectraldiag-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 209.1 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ded65c0d3b0d2ebc87003f9752ea3088d5ddbe7302958f51c3ad9de4d8237872
|
|
| MD5 |
7da36dd39502074ce130ee7540f23361
|
|
| BLAKE2b-256 |
55c6cd586e46613389f8f8d93ff89227d63e5936dbb3a418b0dd5d671886881c
|
File details
Details for the file spectraldiag-0.2.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 33.6 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f4be0aa3ec92f73c4aa0c6f947da82350643060f2abf59cef4a584982e025e6
|
|
| MD5 |
17f0930924499d0457ea4c8dbdfcf893
|
|
| BLAKE2b-256 |
f609bd6387fdac405c3b14f0bfeb744ed0773b7172d3d789cadb0a60b5f79bd2
|
File details
Details for the file spectraldiag-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp311-cp311-macosx_10_9_x86_64.whl
- Upload date:
- Size: 33.7 kB
- Tags: CPython 3.11, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c21c2eaa4c408c20e21cae319a2ca7f3bddbdae97dd0eb236147eaa916e0877d
|
|
| MD5 |
e155071c49553639fd617d14a36ebb9a
|
|
| BLAKE2b-256 |
fbba09fde2076ca7968a670c50c9561c1ac3f58c1461cf23bdc614342dbd7f44
|
File details
Details for the file spectraldiag-0.2.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 39.1 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e83396446ec2cdd042a3a10a0fb222ff799d47bf20b01a8055848dc79471db62
|
|
| MD5 |
7cc097802490ced97c69f4b4b36684e2
|
|
| BLAKE2b-256 |
70a90a6debd12efde5c6ab54b7dc4b5aa2e782a2543ce8d5a96710ce73dd77b2
|
File details
Details for the file spectraldiag-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 208.6 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
605258ca6fa0bafa9ee45e3ecda9604bb82067b71b274e6b5c1ef7e563115d1e
|
|
| MD5 |
c376ce05cad2a292bf82551a5f6dd592
|
|
| BLAKE2b-256 |
d088d178c2ce5a7745aac58beeebd4f7b603fd2486167388cb2abdea80f58534
|
File details
Details for the file spectraldiag-0.2.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 33.6 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18f4bfa7428b7004430b2eb34da1876f0b12b44381f49b7ec8bf6145ff7b03a0
|
|
| MD5 |
832d77c0720c8213c21e0709c3307d44
|
|
| BLAKE2b-256 |
244485463fcfe372944f3254c8f194b597d80341cc1e216deb27c1f0d76fd9d4
|
File details
Details for the file spectraldiag-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 33.7 kB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d89e4c1f80ce26297d4060b03d9efec9d4f98fe0f112942272dc3d44e3fc144
|
|
| MD5 |
b387256abb4cf1ea0d1153838c4204ad
|
|
| BLAKE2b-256 |
7152cd800c1641354343423f3ede4663d8d8c7580263a98694a145a690a39e42
|
File details
Details for the file spectraldiag-0.2.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 39.1 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27cbd14e2b7757dcf7e47c103d2ff96bb985cff36df03de05c32fbe1efa70536
|
|
| MD5 |
fcfed6dd4b0bf067463ba59f2f23804b
|
|
| BLAKE2b-256 |
192646cb0d94aa64441309dcb860ff36539c51fc69a5e7024dab3a3af980ee85
|
File details
Details for the file spectraldiag-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 208.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e271ebffe5977a557e8a434f67946a3995e5ee2d49d2311d891e13275fbebd80
|
|
| MD5 |
27700dbde10b202e4bc491f4288e9a4a
|
|
| BLAKE2b-256 |
52e13c449067163f38208ffebfe5f7ea39367b806e5d85feb509e5cdd49b9a3c
|
File details
Details for the file spectraldiag-0.2.0-cp39-cp39-macosx_11_0_arm64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 33.6 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f58335e615b250536a58c5f173dd44951d7773d58e0f4b089d75f62c25eecf3
|
|
| MD5 |
24ec08367c2c0044ba2a0959a612c8b2
|
|
| BLAKE2b-256 |
757c134d40e44440d675fd5a5c7220d04d1b18428a2fb4d31336bbfe6c9a0372
|
File details
Details for the file spectraldiag-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl.
File metadata
- Download URL: spectraldiag-0.2.0-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 33.7 kB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aacf0ba5a5e86e0a55ab9228a71122ca8d94d4e43d98cf2d524dc25adc81acc4
|
|
| MD5 |
86d8b343f52e9b6d89a483f32d643684
|
|
| BLAKE2b-256 |
a55d93556bf7802e096a8910c93a544bf490c3e7b65eda2c55f3d8fc55681f65
|