Skip to content

Make the linear-algebra epsilons relative, so estimates stop depending on units - #79

Merged
microprediction merged 1 commit into
mainfrom
relative-eigenvalue-floor
Sep 14, 2026
Merged

microprediction merged 1 commit into
mainfrom
relative-eigenvalue-floor

Conversation

@microprediction

Copy link
Copy Markdown
Owner

Two absolute epsilons in _linalg.py decided the answer whenever the data was small. Both have units of variance, so both stop being negligible at exactly the scale a user in basis points or log-returns works at. Found by audit; reproduced independently.

cov_to_corrcoef

Added + EPS (1e-12) to sqrt(v_i · v_j). At variances of 1e-12 that halved every entry, so the correlation diagonal — one by definition — came back as 0.5:

variance diagonal error
1e+00 1.000000 1e-12
1e-11 0.909091 9.1e-02
1e-12 0.500000 5.0e-01
1e-13 0.090909 9.1e-01

Off-diagonals scale by the same factor, so a true correlation of 0.5 read as 0.045. Each variance is now floored at a fraction of the largest, which keeps the unit diagonal at every scale and still avoids dividing by a genuinely zero variance.

make_pos_def

Clipped eigenvalues up to an absolute 1e-8. Below a data scale of ~1e-4 every eigenvalue is under that, so BlockCovariance, SchurCovariance and SchurLedoitWolfCovariance returned 1e-8 · I — up to nine thousand times the true variance, carrying no correlation information at all. At a data scale of 1e-6 the diagonal now returns 0.81 of truth rather than 4,400× it.

One correction to the audit

It attributed GeodesicEwaCovariance's collapse to this same floor. Making the floor relative fixes that estimator's scale equivariance but not the collapse — the trace still falls to 7.5e-06 against a true 5.99 within ~40 observations. The cause is the geodesic step interpolating toward a rank-one target whose remaining p−1 eigenvalues carry no information, with that direction rotating every step. Filed separately rather than claimed fixed here.

327 tests pass, plus new scale-equivariance regressions across five estimators and four scales; ruff and mypy clean.

🤖 Generated with Claude Code

…g on units

Two absolute epsilons in _linalg.py decided the answer whenever the data was
small. Both have units of variance, so both stop being negligible at exactly the
scale a user in basis points or log-returns works at. Found by audit.

cov_to_corrcoef added `+ EPS` (1e-12) to `sqrt(v_i v_j)`. At variances of 1e-12
that halved every entry, so the correlation diagonal -- one by definition -- came
back as 0.5; at 1e-13 it came back as 0.09, and a true correlation of 0.5 read as
0.045. Each variance is now floored at a fraction of the largest, which keeps the
unit diagonal at every scale and still avoids dividing by a genuinely zero
variance.

make_pos_def clipped eigenvalues up to an absolute 1e-8. Below a data scale of
about 1e-4 every eigenvalue is under that, so BlockCovariance, SchurCovariance
and SchurLedoitWolfCovariance returned `1e-8 * I` -- up to nine thousand times
the true variance and carrying no correlation information at all. Measured at a
data scale of 1e-6, the diagonal now comes back at 0.81 of truth rather than
4,400x it.

One correction to the audit that prompted this. It attributed
GeodesicEwaCovariance's collapse to this same floor. Making the floor relative
fixes the estimator's scale equivariance but NOT the collapse: the trace still
falls to 7.5e-06 against a true 5.99 within about forty observations. The cause
is the geodesic step interpolating toward a rank-one target whose remaining p-1
eigenvalues carry no information, with the rank-one direction rotating every
step. Filed separately rather than claimed fixed here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant