code: def _fixedpoint(D, tol=1e-7, maxiter=None):
      '''Simple fixed point iteration method for MLE of Dirichlet distribution'''
      N, K = D.shape
      logp = log(D).mean(axis=0)
      a0 = _init_a(D)
  
      # Start updating
      if maxiter is None:
          maxiter = MAXINT
      for i in xrange(maxiter):
          a1 = _ipsi(psi(a0.sum()) + logp)
          # if norm(a1-a0) < tol:
          if abs(loglikelihood(D, a1)-loglikelihood(D, a0)) < tol: # much faster
              return a1
          a0 = a1
      raise Exception('Failed to converge after {} iterations, values are {}.'
                      .format(maxiter, a1)f _fixedpoint(D, tol=1e-7, maxiter=None):
      '''Simple fixed point iteration method for MLE of Dirichlet distribution'''
      N, K = D.shape
      logp = log(D).mean(axis=0)
      a0 = _init_a(D)
  
      # Start updating
      if maxiter is None:
          maxiter = MAXINT
      for i in xrange(maxiter):
          a1 = _ipsi(psi(a0.sum()) + logp)
          # if norm(a1-a0) < tol:
          if abs(loglikelihood(D, a1)-loglikelihood(D, a0)) < tol: # much faster
              return a1
          a0 = a1
      raise Exception('Failed to converge after {} iterations, values are {}.'
                      .format(maxiter, a1))
docs: Simple fixed point iteration method for MLE of Dirichlet distribution