code: def kl_multivariate_normal_distribution(
      mean_q, covar_q, mean_p, covar_p
  ):
      """
      KL Divergence of two Multivariate Normal Distribtuions
  
      q(x) = Normal(x; mean_q, variance_q)
      p(x) = Normal(x; mean_p, variance_p)
      """
  
      # Ensure arrays
      mean_q = np.asarray(mean_q)
      covar_q = np.asarray(covar_q)
      mean_p = np.asarray(mean_p)
      covar_p = np.asarray(covar_p)
  
      # Need the precision of distribution p
      precision_p = np.linalg.inv(covar_p)
  
      mean_diff = mean_q - mean_p
      D = mean_q.shape[0]
  
      # These correspond to the four terms in the ~wpenny paper documented above
      return 0.5 * (
          _utils.logdet(covar_p)
          - _utils.logdet(covar_q)
          + np.trace(precision_p @ covar_q)
          + mean_diff @ precision_p @ mean_diff
          - D
      )
  
file_path: hmmlearn/lib/hmmlearn/_kl_divergence.py
imports: import numpy
  from scipy.special import gammaln, digamma
  from .None import _utils
label_desc: Use image node_id 3 for calling a global function with example usage: kl_multivariate_normal_distribution(mean_q, covar_q, mean_p, covar_p) and returns: unknown