def Estep(dataSet,Alpha,Mu,Sigma):
# We will calculate the membership weight matrix W here. W is an
# NxK matrix where (i,j)th element represents the probability of
# ith data point to be a member of jth cluster given the parameters
# Alpha, Mu and Sigma
N = np.size(dataSet,0)
K = np.size(Alpha)
W = np.zeros([N,K])
for k in range(K):
for i in range(N):
W[i,k] = Alpha[k]*norm_pdf_multivariate(dataSet[i,:][None].T, \
Mu[:,k][None].T,Sigma[:,:,k])
# Normalize W row-wise because each row represents a pdf. In other words,
# probability of a point to be any one of the K clusters is equal to 1.
W = W*np.reciprocal(np.sum(W,1)[None].T)
return W
评论列表
文章目录