Skip to content

Stabilize UKF covariance symmetrization - #4962

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

Stabilize UKF covariance symmetrization#4962
FlorianPfaff wants to merge 3 commits into
mainfrom
agent/fix-ukf-covariance-symmetrization-overflow

Conversation

@FlorianPfaff

@FlorianPfaff FlorianPfaff commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • symmetrize UKF prediction and update covariances with a scale-normalized average
  • avoid overflow for finite covariance entries near the float64 limit
  • add a focused regression for maximum-finite process covariance

Root cause

src/pyrecest/filters/_ukf.py used 0.5 * (P + P.T). For a symmetric covariance containing np.finfo(np.float64).max, the intermediate sum overflows even though the mathematical average remains finite.

Impact

A valid finite process covariance could raise FloatingPointError under strict NumPy error handling or become non-finite during UKF prediction. The update path used the same vulnerable expression.

Fix

The new helper scales each transposed entry pair by its largest magnitude before averaging, then restores the scale. This keeps finite pairs within [-1, 1] during the intermediate addition and also preserves subnormal values.

Validation

  • reproduced the original FloatingPointError: overflow encountered in add
  • focused patched harness preserves np.finfo(np.float64).max exactly and regenerates finite sigma points
  • helper edge cases cover same-sign maxima, opposite-sign extremes, zeros, and the minimum positive subnormal
  • both modified Python files pass python -m py_compile
  • full GitHub Actions matrix passes on NumPy 3.11–3.14, JAX 3.11–3.13, and PyTorch 3.11–3.13
  • lint, packaging, minimal installation, documentation, MegaLinter, CodeQL, dependency review, security, and release-preview workflows pass
  • comparison with the latest main remains limited to exactly two changed files

@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 26.52s
✅ JSON prettier 7 0 0 0 1.29s
✅ JSON v8r 7 0 0 4.13s
✅ MARKDOWN markdownlint 68 0 0 0 2.16s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.83s
✅ PYTHON black 1808 55 0 0 95.99s
✅ PYTHON isort 1808 86 0 0 2.74s
✅ REPOSITORY betterleaks yes no no 2.58s
✅ REPOSITORY checkov yes no no 55.85s
✅ REPOSITORY gitleaks yes no no 17.39s
✅ REPOSITORY git_diff yes no no 0.31s
✅ REPOSITORY secretlint yes no no 84.22s
✅ REPOSITORY syft yes no no 6.89s
✅ REPOSITORY trivy-sbom yes no no 7.57s
✅ REPOSITORY trufflehog yes no no 32.97s
✅ YAML prettier 11 0 0 0 0.8s
✅ YAML v8r 11 0 0 13.36s
✅ YAML yamllint 11 0 0 0.61s

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 despite the green matrix. It adds a specialized symmetrization algorithm solely to preserve covariance entries near the maximum finite float64 value. Such covariances are not a meaningful UKF operating regime, and the added numerical path would burden core filter code.

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