Skip to content

Commit ec3d034

Browse files
committed
update
1 parent 34d5293 commit ec3d034

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

unsupervised_class/gmm.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def gmm(X, K, max_iter=20, smoothing=1e-2):
2525
M[k] = X[np.random.choice(N)]
2626
C[k] = np.eye(D)
2727

28-
costs = []
28+
lls = []
2929
weighted_pdfs = np.zeros((N, K)) # we'll use these to store the PDF value of sample n and Gaussian k
3030
for i in range(max_iter):
3131
# step 1: determine assignments / resposibilities
@@ -57,14 +57,14 @@ def gmm(X, K, max_iter=20, smoothing=1e-2):
5757
# C[k] = np.sum(R[n,k]*np.outer(X[n] - M[k], X[n] - M[k]) for n in range(N)) / Nk + np.eye(D)*smoothing
5858

5959

60-
c = np.log(weighted_pdfs.sum(axis=1)).sum()
61-
costs.append(c)
60+
ll = np.log(weighted_pdfs.sum(axis=1)).sum()
61+
lls.append(ll)
6262
if i > 0:
63-
if np.abs(costs[i] - costs[i-1]) < 0.1:
63+
if np.abs(lls[i] - lls[i-1]) < 0.1:
6464
break
6565

66-
plt.plot(costs)
67-
plt.title("Costs")
66+
plt.plot(lls)
67+
plt.title("Log-Likelihood")
6868
plt.show()
6969

7070
random_colors = np.random.random((K, 3))

0 commit comments

Comments
 (0)