Repository navigation
Use numerically stable centering and scaling in trait_covariance and trait_correlation - #3518
Open
chenyangsu wants to merge 1 commit into
Open
chenyangsu wants to merge 1 commit into
chenyangsu wants to merge 1 commit into
Conversation
|
🤖 AI generated message Thanks for your interest in tskit, @chenyangsu, and for the work you have put into this. We have just adopted a contribution policy (#3521), because maintainer time for review is limited. We now expect contributions to come from your own use of tskit, or from wanting to get involved in the project and learn how it works. Could you read the policy and let us know how this pull request fits with it? It would help most to know what you were doing with tskit when you needed this change. |
This branch has not been deployed
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.
Description
On
ts_10_mut_recomb_fixture,ts.trait_correlation(W + 1e9)returns[0.00902, 0.000882]instead of[0.111953, 0.361111]from cancellation insum(x^2) - n * mean^2. Scaling by1e200returnsNaN, scaling by1e-200raisesValueErrorasnp.stdunderflows to zero, andts.trait_covarianceon constant1e308weights returnsNaNinstead of0.Both C functions now scale each column by a power of two (
frexp/ldexp), shift by the first sample, and sum two-pass squared deviations (Chan, Golub, and LeVeque 1983).TreeSequence.trait_correlationchecks constancy directly. Happy to use Welford's update instead if you prefer.Testing:
pytest tests/test_tree_stats.py -k "TraitCovariance or TraitCorrelation"(109 passed, 6 new regression tests failed before the fix),pytest tests/test_python_c.py tests/test_tree_stats.py -m "not slow"(1480 passed),clang-format --dry-run -Werrorandruff check/ruff format --checkclean.Fixes #3495
PR Checklist: