Skip to content

Avoid cancellation in Merwe sigma-point scaling - #4289

Closed
FlorianPfaff wants to merge 17 commits into
mainfrom
agent/avoid-merwe-scale-cancellation-20260713
Closed

Avoid cancellation in Merwe sigma-point scaling#4289
FlorianPfaff wants to merge 17 commits into
mainfrom
agent/avoid-merwe-scale-cancellation-20260713

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

  • compute the Merwe sigma-point scale directly as alpha**2 * (n + kappa)
  • stop reconstructing that small positive quantity through n + (scale - n)
  • validate underflowed or overflowed scale values with a clear ValueError
  • add a regression for alpha=1e-9

Bug

MerweScaledSigmaPoints first computed

lambda_ = alpha**2 * (n + kappa) - n
scale = n + lambda_

For valid small positive alpha, the subtraction can round lambda_ to exactly -n. Adding n back then produces 0.0, even though the direct scale remains finite and positive. With n=1, kappa=0, and alpha=1e-9, the old implementation computes lambda_ == -1.0 and scale == 0.0, causing division by zero during weight construction.

Fix

Use the mathematically equivalent direct expression for both weight construction and covariance scaling. A shared helper also rejects genuine scale underflow or overflow explicitly.

Validation

  • isolated reproduction confirms the old reconstruction yields 0.0 while the direct expression yields 1e-18
  • isolated execution verifies finite weights and sigma points [0, +1e-9, -1e-9]
  • existing two-dimensional Merwe moment reconstruction still recovers the original mean and covariance
  • modified source and regression modules pass python -m py_compile
  • branch is two commits ahead of main and zero behind

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 25.05s
✅ JSON prettier 7 0 0 0 1.18s
✅ JSON v8r 7 0 0 3.63s
✅ MARKDOWN markdownlint 68 0 0 0 2.12s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.56s
✅ PYTHON black 1490 182 0 0 95.22s
✅ PYTHON isort 1490 327 0 0 2.67s
✅ REPOSITORY betterleaks yes no no 2.75s
✅ REPOSITORY checkov yes no no 55.06s
✅ REPOSITORY gitleaks yes no no 14.35s
✅ REPOSITORY git_diff yes no no 0.48s
✅ REPOSITORY secretlint yes no no 63.15s
✅ REPOSITORY syft yes no no 5.89s
✅ REPOSITORY trivy-sbom yes no no 6.8s
✅ REPOSITORY trufflehog yes no no 32.22s
✅ YAML prettier 11 0 0 0 0.8s
✅ YAML v8r 11 0 0 10.98s
✅ YAML yamllint 11 0 0 0.64s

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

@FlorianPfaff
FlorianPfaff force-pushed the agent/avoid-merwe-scale-cancellation-20260713 branch from 3e9d9e6 to 2e1b34b Compare July 13, 2026 16:33
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