Repository navigation
Make the linear-algebra epsilons relative, so estimates stop depending on units - #79
Merged
Merged
Conversation
…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>
This was referenced Sep 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two absolute epsilons in
_linalg.pydecided 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_corrcoefAdded
+ EPS(1e-12) tosqrt(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: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_defClipped eigenvalues up to an absolute 1e-8. Below a data scale of ~1e-4 every eigenvalue is under that, so
BlockCovariance,SchurCovarianceandSchurLedoitWolfCovariancereturned1e-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 remainingp−1eigenvalues 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;
ruffandmypyclean.🤖 Generated with Claude Code