Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -1,9 +1,7 @@
(defn entropy [s]
(let [len (count s)
freqs (frequencies s)
log-of-2 (Math/log 2)]
(->> (keys freqs)
(map (fn [c]
(let [rf (/ (get freqs c) len)]
(* -1 rf (/ (Math/log rf) log-of-2)))))
(let [len (count s), log-2 (Math/log 2)]
(->> (frequencies s)
(map (fn [[_ v]]
(let [rf (/ v len)]
(-> (Math/log rf) (/ log-2) (* rf) Math/abs))))
(reduce +))))

View file

@ -1,2 +1,2 @@
(H "1223334444")
(entropy "1223334444")
1.8464393446710154