MCPcopy Create free account
hub / github.com/Dod-o/Statistical-Learning-Method_Code / M_step

Function M_step

EM/EM.py:110–123  ·  view source on GitHub ↗
(muo, mu1, gamma0, gamma1, dataSetArr)

Source from the content-addressed store, hash-verified

108 return gamma0, gamma1
109
110def M_step(muo, mu1, gamma0, gamma1, dataSetArr):
111 #依据算法9.2计算各个值
112 #这里没什么花样,对照书本公式看看这里就好了
113 mu0_new = np.dot(gamma0, dataSetArr) / np.sum(gamma0)
114 mu1_new = np.dot(gamma1, dataSetArr) / np.sum(gamma1)
115
116 sigmod0_new = math.sqrt(np.dot(gamma0, (dataSetArr - muo)**2) / np.sum(gamma0))
117 sigmod1_new = math.sqrt(np.dot(gamma1, (dataSetArr - mu1)**2) / np.sum(gamma1))
118
119 alpha0_new = np.sum(gamma0) / len(gamma0)
120 alpha1_new = np.sum(gamma1) / len(gamma1)
121
122 #将更新的值返回
123 return mu0_new, mu1_new, sigmod0_new, sigmod1_new, alpha0_new, alpha1_new
124
125
126def EM_Train(dataSetList, iter = 500):

Callers 1

EM_TrainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected