code: def estimate(self, maxiter=250, convergence=1e-7):
  
          
  
          self.loglik = np.zeros(maxiter)
  
          iter = 0
  
          while iter < maxiter:
  
              self.loglik[iter] = self.E_step()
              if np.isnan(self.loglik[iter]):
                      print("undefined log-likelihood")
                      break
              self.M_step()
  
              if self.loglik[iter] - self.loglik[iter - 1] < 0 and iter > 0:
                      print("log-likelihood decreased by %f at iteration %d"
                            % (self.loglik[iter] - self.loglik[iter - 1],
                               iter))
              elif self.loglik[iter] - self.loglik[iter - 1] < convergence \
                      and iter > 0:
                      print("convergence at iteration %d, loglik = %f" %
                             (iter, self.loglik[iter]))
                      self.loglik = self.loglik[self.loglik < 0]
                      break
  
              iter += 1
docs: run EM algorithm until convergence, or until maxiter reached