Skip to content

FIX gaussian mixture diagonal covariance must result from float64 operands - #30383

Open
mekleo wants to merge 6 commits into
scikit-learn:mainfrom
mekleo:patch-1
Open

mekleo wants to merge 6 commits into
scikit-learn:mainfrom
mekleo:patch-1

Conversation

@mekleo

@mekleo mekleo commented Dec 2, 2024 •

Copy link
Copy Markdown
Contributor

Squaring float32 numbers leads to a significant loss of precision the regularization term reg_covar might not mitigate.
Moreover, as avgX_means is equal to avg_means2, the returned expression can be simplified.

Reference Issues/PRs

Fixes #30382

What does this implement/fix? Explain your changes.

This commit sums the input array with an array of zeros (implicit np.float64 conversion on 64-bit platforms) before squaring it in-place. Overall, it does not require more memory than the former implementation,
_estimate_gaussian_covariances_diag being further optimized as computing avg_X_means is not needed.

…rands

Squaring float32 numbers leads to a significant loss of precision the regularization term reg_covar might not mitigate.

Moreover, as avgX_means is equal to avg_means2, the returned expression can be simplified
@github-actions

github-actions Bot commented Dec 2, 2024 •

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 73d331a. Link to the linter CI: here

@ogrisel

ogrisel commented Dec 5, 2024

Copy link
Copy Markdown
Member

Sorry, @mekleo. I completely missed that you had already opened a PR linked to your issue.

For the record, I extracted the term simplification in #30414. This can be merged irrespective of the resolution of the numerical problem.

I will update the commit to credit co-authorship in that PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gaussian Mixture: Diagonal covariance vectors might contain unreasonably negative values when the input datatype is np.float32

2 participants