Last active
March 7, 2019 12:12
-
-
Save DFoly/5937accc65afee7c1f119ee500d5cae3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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