Sha256: 3a62c7a7664895712e187e0b0a949841947b040b3e8b082885249885a94e23fd
Contents?: true
Size: 910 Bytes
Versions: 26
Compression:
Stored size: 910 Bytes
Contents
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
Version data entries
26 entries across 26 versions & 1 rubygems