Skip to content

Commit 507c432

Browse files
ogriselmekleo
andauthored
Simplify estimate gaussian covariances diag (scikit-learn#30414)
Co-authored-by: mekleo <[email protected]>
1 parent fc9295a commit 507c432

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
- Simplified redundant computation when estimating covariances in
2+
:class:`~mixture.GaussianMixture` with a `covariance_type="spherical"` or
3+
`covariance_type="diag"`.
4+
By :user:`Leonce Mekinda <mekleo>` and :user:`Olivier Grisel <ogrisel>`

sklearn/mixture/_gaussian_mixture.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ def _estimate_gaussian_covariances_diag(resp, X, nk, means, reg_covar):
228228
"""
229229
avg_X2 = np.dot(resp.T, X * X) / nk[:, np.newaxis]
230230
avg_means2 = means**2
231-
avg_X_means = means * np.dot(resp.T, X) / nk[:, np.newaxis]
232-
return avg_X2 - 2 * avg_X_means + avg_means2 + reg_covar
231+
return avg_X2 - avg_means2 + reg_covar
233232

234233

235234
def _estimate_gaussian_covariances_spherical(resp, X, nk, means, reg_covar):

0 commit comments

Comments
 (0)