def hmm_kld(hmm1, hmm2, num_samples=10000, num_runs=1):
    """Calculates an estimation of the kld between
     two HiddenMarkovModel objects

  Args:
    hmm1: The first HiddenMarkovModel object.
    hmm2: The second HiddenMarkovModel object.
    num_samples: Number of the samples for the simulated data.
    num_runs: Number of realizations. For the final estimation mean values
      is considered.

  Returns:
    The estimated symmetric kld

  """
    total_kld = 0.0
    for i in range(num_runs):
        data1, _ = hmm1.generate(num_samples)
        kld = (hmm1.posterior(data1) - hmm2.posterior(data1)) / num_samples
        total_kld += kld
    return total_kld / num_runs
