Skip to content

Fix double-counted hyperspherical moment Jacobian - #5455

Merged
FlorianPfaff merged 2 commits into
mainfrom
fix/hypersphere-moment-jacobian
Aug 28, 2026
Merged

Fix double-counted hyperspherical moment Jacobian#5455
FlorianPfaff merged 2 commits into
mainfrom
fix/hypersphere-moment-jacobian

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Bug

AbstractHypersphereSubsetDistribution.moment_numerical() explicitly multiplied its hyperspherical-coordinate integrand by the surface-element factors (for example sin(phi2) on S2), then passed that already-weighted function to integrate_fun_over_domain(). The latter delegates to integrate_fun_over_domain_part(), which applies the hyperspherical surface-element Jacobian again.

This computes second moments against the wrong measure for dimensions >= 2. In particular, for a uniform distribution on S2, trace(E[x x^T]) should be 1 because ||x|| = 1, but the double Jacobian yields pi/4 instead.

Fix

Pass the Cartesian moment integrand in hyperspherical coordinates directly to integrate_fun_over_domain() and let the integration helper apply the surface Jacobian exactly once.

Regression test

Add a uniform-S2 identity check:

  • E[x x^T] = I / 3
  • trace(E[x x^T]) = 1

The test is skipped on JAX, consistent with the existing numerical hyperspherical integration limitation.

@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 7.27s
✅ JSON prettier 7 0 0 0 0.69s
✅ JSON v8r 7 0 0 4.85s
✅ MARKDOWN markdownlint 68 0 0 0 2.25s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.39s
✅ PYTHON black 2034 1 0 0 65.68s
✅ PYTHON isort 2034 4 0 0 2.96s
✅ REPOSITORY betterleaks yes no no 1.33s
✅ REPOSITORY checkov yes no no 33.79s
✅ REPOSITORY git_diff yes no no 0.19s
✅ REPOSITORY secretlint yes no no 105.49s
✅ REPOSITORY syft yes no no 2.73s
✅ REPOSITORY trivy-sbom yes no no 3.05s
✅ YAML prettier 11 0 0 0 0.61s
✅ YAML v8r 11 0 0 16.81s
✅ YAML yamllint 11 0 0 0.92s

Notices

⚠️ Your configuration references items that have been removed from MegaLinter and are ignored: MAKEFILE_CHECKMAKE. See Removed linters to find their replacements.

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@10.0.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_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

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

@FlorianPfaff
FlorianPfaff enabled auto-merge (squash) August 28, 2026 19:12
@FlorianPfaff
FlorianPfaff merged commit c11e4ea into main Aug 28, 2026
25 checks passed
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