This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (defn entropy | |
| "Calculate the Shannon entropy, a.k.a. amount of information, in a | |
| distribution. Uses the log-base-2 version, so the result can be thought of as | |
| the number of bits of information. Accepts either a seq of numbers or a map of | |
| freqencies like that returned by the `clojure.core/freqencies` function. | |
| Ex: | |
| (entropy [1]) ; => 0.0 | |
| (entropy [0 1 0 1]) ; => 1.0 | |
| (entropy [0 1 2 3]) ; => 2.0 | |
| (entropy {0 2, 1 2}) ; => 1.0 |