lojix/learning/src/main/com/thesett/aima/math/InformationTheory.java
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;
    }
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;
    }
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.

<p>P = number of times a symbol occurs/total number of symbols.

@param  counts The counts of the occurrences of symbols over a data set of symbols.

@return An array of the probability estimates for the occurences of the symbols. The index of the elements in
this array corresponds with the index of the symbol in the input array.
Estimates probabilities given a set of counts of occurrences of symbols .