Skip to content

Validate Gaussian mixture covariance shapes - #5238

Open
FlorianPfaff wants to merge 2 commits into
mainfrom
agent/fix-gaussian-mixture-covariance-shape
Open

Validate Gaussian mixture covariance shapes#5238
FlorianPfaff wants to merge 2 commits into
mainfrom
agent/fix-gaussian-mixture-covariance-shape

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Bug

GaussianMixture.mixture_parameters_to_gaussian_parameters(...) accepted a plain covariance matrix with shape (dim, dim) without checking how many mixture components were supplied.

For one two-dimensional component, NumPy broadcasting changed a covariance such as

[[4.0, 1.5],
 [1.5, 9.0]]

into a three-axis intermediate with the wrong orientation. Summing over axis 2 produced [5.5, 10.5], which was then broadcast into the returned covariance

[[5.5, 10.5],
 [5.5, 10.5]]

instead of preserving the component covariance. For multiple components, the same unvalidated layout could likewise produce shape-dependent broadcasting or failures unrelated to the actual input contract.

Fix

Normalize and validate the mixture parameter layout before moment conversion:

  • normalize scalar and one-dimensional mean inputs to the established (n_components, dim) representation;
  • require covariance tensors to have shape (dim, dim, n_components);
  • accept a natural (dim, dim) matrix only for a single component and reshape it explicitly;
  • preserve scalar/vector variance shorthand for one-dimensional mixtures;
  • reject ambiguous multi-component covariance matrices with a clear ValueError instead of allowing broadcasting.

Regression coverage

The constructor test module now verifies that:

  • a single two-dimensional covariance matrix is preserved exactly;
  • a single (dim, dim) matrix is rejected when two component means are supplied;
  • the existing two-component one-dimensional conversion still returns mean 1.5 and covariance 3.25.

Validation

  • independently reproduced the pre-fix corrupted covariance [[5.5, 10.5], [5.5, 10.5]];
  • exercised the patched shape normalization and recovered the exact input covariance [[4.0, 1.5], [1.5, 9.0]];
  • verified the existing one-dimensional mixture calculation remains unchanged;
  • verified the ambiguous multi-component matrix is rejected;
  • branch comparison: 2 commits ahead, 0 behind main;
  • final diff is limited to the Gaussian-mixture converter and its focused constructor tests.

GitHub Actions provides the authoritative full backend, lint, packaging, documentation, and integration validation.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 26.44s
✅ JSON prettier 7 0 0 0 1.14s
✅ JSON v8r 7 0 0 4.73s
✅ MARKDOWN markdownlint 68 0 0 0 1.82s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.69s
✅ PYTHON black 1865 89 0 0 91.25s
✅ PYTHON isort 1865 141 0 0 2.68s
✅ REPOSITORY betterleaks yes no no 2.26s
✅ REPOSITORY checkov yes no no 53.15s
✅ REPOSITORY gitleaks yes no no 17.26s
✅ REPOSITORY git_diff yes no no 0.33s
✅ REPOSITORY secretlint yes no no 81.56s
✅ REPOSITORY syft yes no no 6.16s
✅ REPOSITORY trivy-sbom yes no no 6.13s
✅ REPOSITORY trufflehog yes no no 31.38s
✅ YAML prettier 11 0 0 0 0.79s
✅ YAML v8r 11 0 0 12.23s
✅ YAML yamllint 11 0 0 0.5s

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 marked this pull request as ready for review August 7, 2026 17:58
@FlorianPfaff
FlorianPfaff enabled auto-merge (squash) August 7, 2026 17:58
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