public static double [ ] pForDistribution ( int [ ] counts ) { double [ ] probabilities = new double [ counts . length ] ; int total = 0 ; // Loop over the counts for all symbols adding up the total number. for ( int c : counts ) { total += c ; } // Loop over the counts for all symbols dividing by the total number to provide a probability estimate. for ( int i = 0 ; i < probabilities . length ; i ++ ) { if ( total > 0 ) { probabilities [ i ] = ( ( double ) counts [ i ] ) / total ; } else { probabilities [ i ] = 0.0d ; } } return probabilities ; }
Estimates probabilities given a set of counts of occurrences of symbols .