code: def loglikelihood(D, a):
      '''Compute log likelihood of Dirichlet distribution, i.e. log p(D|a).
  
      Parameters
      ----------
      D : 2D array
          where ``N`` is the number of observations, ``K`` is the number of
          parameters for the Dirichlet distribution.
      a : array
          Parameters for the Dirichlet distribution.
  
      Returns
      -------
      logl : float
          The log likelihood of the Dirichlet distribution'''
      N, K = D.shape
      logp = log(D).mean(axis=0)
      return N*(gammaln(a.sum()) - gammaln(a).sum() + ((a - 1)*logp).sum()f loglikelihood(D, a):
      '''Compute log likelihood of Dirichlet distribution, i.e. log p(D|a).
  
      Parameters
      ----------
      D : 2D array
          where ``N`` is the number of observations, ``K`` is the number of
          parameters for the Dirichlet distribution.
      a : array
          Parameters for the Dirichlet distribution.
  
      Returns
      -------
      logl : float
          The log likelihood of the Dirichlet distribution'''
      N, K = D.shape
      logp = log(D).mean(axis=0)
      return N*(gammaln(a.sum()) - gammaln(a).sum() + ((a - 1)*logp).sum())
docs: Compute log likelihood of Dirichlet distribution, i.e. log p(D|a).
  
      Parameters
      ----------
      D : 2D array
          where ``N`` is the number of observations, ``K`` is the number of
          parameters for the Dirichlet distribution.
      a : array
          Parameters for the Dirichlet distribution.
  
      Returns
      -------
      logl : float
          The log likelihood of the Dirichlet distribution