Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccabfa1

Browse files
authored
Update em_mog.py
1 parent 4504625 commit ccabfa1

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

em_mog.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ def em_mog(X, k, max_iter=20):
3333
# Initialize the means of the gaussians. You can use K-means! #
3434
#######################################################################
3535
kmeans = KMeans(n_clusters=k, random_state=0, max_iter=20).fit(X)
36-
mu = kmeans.cluster_centers_
37-
#######################################################################
38-
# END OF YOUR CODE #
39-
#######################################################################
36+
mu = kmeans.cluster_centers_
4037

4138
for l in range(max_iter):
4239
# E-Step: compute the probabilities p(z==j|x; mu, sigma, phi)
@@ -48,8 +45,7 @@ def em_mog(X, k, max_iter=20):
4845
# Check convergence
4946
ll = log_likelihood(X, mu, sigma, phi)
5047
print('Iter: {}/{}, LL: {}'.format(l+1, max_iter, ll))
51-
if ll/ll_prev > 0.999:
52-
#if ll/ll_prev > 0.999:
48+
if ll/ll_prev > 0.999:
5349
print('EM has converged...')
5450
break
5551
ll_prev = ll
@@ -58,12 +54,14 @@ def em_mog(X, k, max_iter=20):
5854
exec_time = time.time()-start
5955
print('Number of iterations: {}, Execution time: {}s'.format(l+1, exec_time))
6056

61-
# Compute final assignment
57+
# Computes final assignment
6258
w = e_step(X, mu, sigma, phi)
6359

6460
return phi, mu, sigma, w
6561

66-
62+
#######################################################################
63+
# END OF YOUR CODE #
64+
#######################################################################
6765

6866
def log_likelihood(X, mu, sigma, phi):
6967
"""

0 commit comments

Comments
 (0)