23def ToolGmm(V, K, numMaxIter=1000, prevState=None):
24
25
26 if prevState is None:
27 state = initState_I(V, K)
28 else:
29 state = CGmmState(prevState.mu.copy(), prevState.sigma.copy(), prevState.prior.copy())
30
31 for j in range(numMaxIter):
32 prevState = CGmmState(state.mu.copy(), state.sigma.copy(), state.prior.copy())
33
34
35 p = computeProb_I(V, state)
36
37
38 state = updateGaussians_I(V, p, state)
39
40
41 if np.max(np.sum(np.abs(state.mu-prevState.mu))) <= 1e-20:
42 break
43
44 return state.mu, state.sigma, state
45
46