Update array.rb

This commit is contained in:
Brian Underwood
2017-05-09 16:13:18 -04:00
committed by GitHub
parent 846448acd6
commit 5be22ab1f6

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)