Skip to content

Instantly share code, notes, and snippets.

@DFoly
Last active March 7, 2019 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DFoly/5937accc65afee7c1f119ee500d5cae3 to your computer and use it in GitHub Desktop.
Save DFoly/5937accc65afee7c1f119ee500d5cae3 to your computer and use it in GitHub Desktop.
def fit(self, X):
"""Compute the E-step and M-step and
Calculates the lowerbound
Parameters:
-----------
X: (N x d), data
Returns:
----------
instance of GMM
"""
d = X.shape[1]
self.mu, self.sigma, self.pi = self._initialise_parameters(X)
try:
for run in range(self.n_runs):
self.gamma = self._e_step(X, self.mu, self.pi, self.sigma)
self.pi, self.mu, self.sigma = self._m_step(X, self.gamma)
loss = self._compute_loss_function(X, self.pi, self.mu, self.sigma)
if run % 10 == 0:
print("Iteration: %d Loss: %0.6f" %(run, loss))
except Exception as e:
print(e)
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment