Skip to content

Reject nonsymmetric Wasserstein covariance matrices - #5348

Merged
FlorianPfaff merged 2 commits into
mainfrom
fix/wasserstein-covariance-symmetry
Aug 18, 2026
Merged

Reject nonsymmetric Wasserstein covariance matrices#5348
FlorianPfaff merged 2 commits into
mainfrom
fix/wasserstein-covariance-symmetry

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

  • Reject materially nonsymmetric covariance and extent matrices before Gaussian/extent Wasserstein evaluation.
  • Keep the existing numerical-noise behavior by allowing relative asymmetry up to 1e-12, then symmetrizing only that tiny residual.
  • Add focused regressions for both covariance arguments and both extent arguments.

Bug

_as_covariance_matrix() currently calls _symmetrize() before validating positive semidefiniteness. As a result, an invalid input such as

np.array([[2.0, 1.0], [0.0, 2.0]])

is silently replaced by [[2.0, 0.5], [0.5, 2.0]], which is positive semidefinite, and a finite Wasserstein distance is returned for a matrix that was never a valid covariance matrix.

This is also inconsistent with the NEES/NIS covariance-stack validation, which already rejects material asymmetry.

Fix

Validate covariance symmetry before _symmetrize() using the same relative 1e-12 asymmetry policy already used for covariance stacks. Tiny floating-point skew remains tolerated and is still removed by _symmetrize(); material asymmetry now raises a ValueError naming the offending argument.

Validation

  • Regression coverage added to tests/test_metrics_wasserstein_validation.py.
  • Branch is based on fc15bed910b324cd0619a2f2b71abc887bc09747 and is 2 commits ahead / 0 behind that base.
  • Diff is limited to 13 production additions and 19 test additions across 2 files.
  • Full repository CI is left to GitHub Actions because this execution environment cannot clone/install the repository dependencies.

@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.25s
✅ JSON prettier 7 0 0 0 0.65s
✅ JSON v8r 7 0 0 5.13s
✅ MARKDOWN markdownlint 68 0 0 0 2.16s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.76s
✅ PYTHON black 1983 10 0 0 68.0s
✅ PYTHON isort 1983 20 0 0 2.93s
✅ REPOSITORY betterleaks yes no no 1.25s
✅ REPOSITORY checkov yes no no 37.07s
✅ REPOSITORY git_diff yes no no 0.08s
✅ REPOSITORY secretlint yes no no 106.99s
✅ REPOSITORY syft yes no no 2.82s
✅ REPOSITORY trivy-sbom yes no no 2.53s
✅ YAML prettier 11 0 0 0 0.61s
✅ YAML v8r 11 0 0 18.61s
✅ YAML yamllint 11 0 0 1.12s

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 merged commit ce2001c into main Aug 18, 2026
13 of 24 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