projects: update some short descriptions
[nit.git] / lib / counter.nit
index 818264e..644c115 100644 (file)
@@ -254,6 +254,18 @@ class Counter[E]
                end
                return (sum / map.length.to_f).sqrt
        end
+
+       # The information entropy (Shannon entropy) of the elements in the counter (in bits).
+       fun entropy: Float
+       do
+               var res = 0.0
+               var sum = self.sum.to_f
+               for k, v in self do
+                       var f = v.to_f / sum
+                       res = res - f * f.log_base(2.0)
+               end
+               return res
+       end
 end
 
 redef class Collection[E]