Merge pull request #35 from cheerfulstoic/patch-3

De-sum 2
This commit is contained in:
Ilya Grigorik
2018-04-06 11:56:47 -07:00
committed by GitHub

View File

@@ -2,7 +2,7 @@ class Array
def entropy def entropy
each_with_object(Hash.new(0)) do |i, result| each_with_object(Hash.new(0)) do |i, result|
result[i] += 1 result[i] += 1
end.values.sum do |count| end.values.inject(0, :+) do |count|
percentage = count.to_f / length percentage = count.to_f / length
-percentage * Math.log2(percentage) -percentage * Math.log2(percentage)