Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

mekleo
Copy link
Contributor

@mekleo mekleo commented Dec 2, 2024

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
Copy link

github-actions bot commented Dec 2, 2024

✔️ Linting Passed

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

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

@ogrisel
Copy link
Member

ogrisel commented Dec 5, 2024

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.

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