You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

stats.py 548 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Mon Oct 5 15:12:41 2020
  5. @author: ljia
  6. """
  7. from collections import Counter
  8. from scipy import stats
  9. def entropy(labels, base=None):
  10. """Calculate the entropy of a distribution for given list of labels.
  11. Parameters
  12. ----------
  13. labels : list
  14. Given list of labels.
  15. base : float, optional
  16. The logarithmic base to use. The default is ``e`` (natural logarithm).
  17. Returns
  18. -------
  19. float
  20. The calculated entropy.
  21. """
  22. return stats.entropy(list(Counter(labels).values()), base=base)

A Python package for graph kernels, graph edit distances and graph pre-image problem.