Skip to content

Stabilize pairwise covariance symmetrization - #4963

Closed
FlorianPfaff wants to merge 3 commits into
mainfrom
agent/fix-pairwise-covariance-symmetrization-overflow
Closed

Stabilize pairwise covariance symmetrization#4963
FlorianPfaff wants to merge 3 commits into
mainfrom
agent/fix-pairwise-covariance-symmetrization-overflow

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

  • replace overflow-prone batch covariance symmetrization in pairwise association features
  • scale each transposed entry pair before averaging, then restore its magnitude
  • add a public regression for maximum-finite float64 covariance scales

Root cause

_symmetrized_covariance_batch() used 0.5 * (P + P.T). For a finite covariance entry near np.finfo(np.float64).max, the intermediate addition overflows even though the mathematical average remains finite.

Impact

Accepted finite covariance stacks could become non-finite before trace normalization, eigendecomposition, or pseudoinversion. In particular, covariance-shape features could return NaN costs and similarities for representable inputs, which can contaminate association scores and assignment costs.

Fix

The helper now divides each entry pair by the largest absolute magnitude in that pair, averages values bounded by [-1, 1], and multiplies by the original scale. Zero pairs use a safe unit divisor. The implementation stays entirely in the active backend.

Validation

  • reproduced the pre-fix maximum-scale covariance becoming inf and yielding NaN shape features
  • verified the patched calculation returns shape cost 1, log-determinant cost 0, and similarity exp(-1)
  • exercised the scaled arithmetic with NumPy, PyTorch, and JAX float64
  • compared the branch with current main: only the covariance-feature source and focused regression file differ

The full supported backend and lint matrices are delegated to GitHub Actions.

@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 18.55s
✅ JSON prettier 7 0 0 0 0.73s
✅ JSON v8r 7 0 0 2.34s
✅ MARKDOWN markdownlint 68 0 0 0 1.27s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.36s
✅ PYTHON black 1809 56 0 0 66.84s
✅ PYTHON isort 1809 88 0 0 2.13s
✅ REPOSITORY betterleaks yes no no 1.57s
✅ REPOSITORY checkov yes no no 53.33s
✅ REPOSITORY gitleaks yes no no 14.1s
✅ REPOSITORY git_diff yes no no 0.11s
✅ REPOSITORY secretlint yes no no 58.16s
✅ REPOSITORY syft yes no no 3.29s
✅ REPOSITORY trivy-sbom yes no no 5.18s
✅ REPOSITORY trufflehog yes no no 18.68s
✅ YAML prettier 11 0 0 0 0.53s
✅ YAML v8r 11 0 0 9.91s
✅ YAML yamllint 11 0 0 0.68s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@9.6.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

Copy link
Copy Markdown
Owner Author

Closing as low value. The scale-normalized covariance symmetrization is dedicated to entries at or near the maximum finite float64 value, where covariance features and association calculations are not operationally meaningful. The extra per-entry machinery is not warranted for supported tracking scales.

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