MCPcopy Create free account
hub / github.com/rushter/MLAlgorithms / _M_step

Method _M_step

mla/gaussian_mixture.py:98–107  ·  view source on GitHub ↗

Maximization (M-step) for Gaussian Mixture.

(self)

Source from the content-addressed store, hash-verified

96 self.responsibilities = weighted_likelihoods
97
98 def _M_step(self):
99 """Maximization (M-step) for Gaussian Mixture."""
100 weights = self.responsibilities.sum(axis=0)
101 for assignment in range(self.K):
102 resp = self.responsibilities[:, assignment][:, np.newaxis]
103 self.means[assignment] = (resp * self.X).sum(axis=0) / resp.sum()
104 self.covs[assignment] = (self.X - self.means[assignment]).T.dot(
105 (self.X - self.means[assignment]) * resp
106 ) / weights[assignment]
107 self.weights = weights / weights.sum()
108
109 def _is_converged(self):
110 """Check if the difference of the latest two likelihood is less than the tolerance."""

Callers 1

fitMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected