
module Enumerable

  # Returns the maximum possible Shannon entropy of the array
  # with given size assuming that it is an "order-0" source
  # (each element is selected independently of the next).
  #
  #
  #
  #--
  # Credit goes to Derek.
  #++
  def ideal_entropy
    arr = self.to_a
    unitProb = 1.0.to_f / arr.size.to_f
    (-1.to_f * arr.size.to_f * unitProb * Math.log(unitProb)/Math.log(2.to_f))
  end

end

# Not needed b/c ideal_entropy is only dependent on size.
# class String
#   def ideal_entropy
#     self.split(//).ideal_entropy
#   end
# end



#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCEnumerable < Test::Unit::TestCase

    def test_ideal_entropy
      assert_equal( 1.0, %w{ a b }.ideal_entropy )
      assert_equal( 2.0, %w{ a a b b }.ideal_entropy )
    end

  end

=end
