public static double expectedI ( double [ ] probabilities ) { double result = 0.0d ; // Loop over the probabilities for all the symbols calculating the contribution of each to the expected value. for ( double p : probabilities ) { // Calculate the information in each symbol. I(p) = - ln p and weight this by its probability of occurence // to get that symbols contribution to the expected value over all symbols. if ( p > 0.0d ) { result -= p * Math . log ( p ) ; } } // Convert the result from nats to bits by dividing by ln 2. return result / LN2 ; }
For a given set of probabilities of the occurences of symbols this function calculates the expected information content of a set of symbols given its probability distribution . The answer is expressed as a positive number of bits .