gov.sandia.cognition.statistics
Class ProbabilityMassFunctionUtil

java.lang.Object
  extended by gov.sandia.cognition.statistics.ProbabilityMassFunctionUtil

public class ProbabilityMassFunctionUtil
extends Object

Utility methods for helping computations in PMFs.

Since:
3.0
Author:
Kevin R. Dixon

Constructor Summary
ProbabilityMassFunctionUtil()
           
 
Method Summary
static double computeCumulativeValue(int input, ClosedFormDiscreteUnivariateDistribution<? super Integer> distribution)
          Computes the CDF value for the given PMF for the input.
static
<DataType> double
getEntropy(ProbabilityMassFunction<DataType> pmf)
          Computes the information-theoretic entropy of the PMF in bits.
static
<DataType extends Number>
InputOutputPair<DataType,Double>
inverse(CumulativeDistributionFunction<DataType> cdf, double p)
          Inverts the discrete CDF, that is p=Pr{x<=X}.
static
<DataType> ArrayList<DataType>
sample(ProbabilityMassFunction<DataType> pmf, Random random, int numSamples)
          Samples from the ProbabilityMassFunction.
static
<DataType> ArrayList<DataType>
sampleMultiple(double[] cumulativeWeights, double weightSum, List<? extends DataType> domain, Random random, int numSamples)
          Samples multiple elements from the domain proportionately to the cumulative weights in the given weight array using a fast binary search algorithm
static
<DataType> ArrayList<DataType>
sampleMultiple(ProbabilityMassFunction<DataType> pmf, Random random, int numSamples)
          Samples from the ProbabilityMassFunction.
static
<DataType> DataType
sampleSingle(double[] weights, Collection<? extends DataType> domain, Random random)
          Samples a single element from the domain proportionately to the given weights
static
<DataType> DataType
sampleSingle(ProbabilityMassFunction<DataType> pmf, Random random)
          Draws a single sample from the given PMF
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ProbabilityMassFunctionUtil

public ProbabilityMassFunctionUtil()
Method Detail

getEntropy

@PublicationReference(author="Wikipedia",
                      title="Entropy (information theory)",
                      type=WebPage,
                      year=2009,
                      url="http://en.wikipedia.org/wiki/Entropy_(Information_theory)")
public static <DataType> double getEntropy(ProbabilityMassFunction<DataType> pmf)
Computes the information-theoretic entropy of the PMF in bits.

Type Parameters:
DataType - Type of data on the domain of the PMF.
Parameters:
pmf - PMF to compute the entropy.
Returns:
Entropy in bits of the given PMF.

sample

public static <DataType> ArrayList<DataType> sample(ProbabilityMassFunction<DataType> pmf,
                                                    Random random,
                                                    int numSamples)
Samples from the ProbabilityMassFunction. The return value will be sampled according to the given PMF.

Type Parameters:
DataType - Type of data to use
Parameters:
pmf - PMF from which to sample
random - Random to sample from
numSamples - Number of samples to draw from the given PMF.
Returns:
Samples drawn according to the given PMF.

sampleSingle

public static <DataType> DataType sampleSingle(ProbabilityMassFunction<DataType> pmf,
                                               Random random)
Draws a single sample from the given PMF

Type Parameters:
DataType - Type of observations generated by the PMF
Parameters:
pmf - PMF from which to draw.
random - Random number generator
Returns:
Single sample from the PMF

sampleMultiple

public static <DataType> ArrayList<DataType> sampleMultiple(ProbabilityMassFunction<DataType> pmf,
                                                            Random random,
                                                            int numSamples)
Samples from the ProbabilityMassFunction. The return value will be sampled according to the given PMF.

Type Parameters:
DataType - Type of data to use
Parameters:
pmf - PMF from which to sample
random - Random to sample from
numSamples - Number of samples to draw from the given PMF.
Returns:
Samples drawn according to the given PMF.

sampleMultiple

public static <DataType> ArrayList<DataType> sampleMultiple(double[] cumulativeWeights,
                                                            double weightSum,
                                                            List<? extends DataType> domain,
                                                            Random random,
                                                            int numSamples)
Samples multiple elements from the domain proportionately to the cumulative weights in the given weight array using a fast binary search algorithm

Type Parameters:
DataType - Type of data to be sampled
Parameters:
cumulativeWeights - Cumulative weights to sample from
weightSum - Maximum value of the cumulative weights
domain - Domain from which to sample
random - Random number generator
numSamples - Number of samples to draw from the distribution
Returns:
Samples draw proportionately from the cumulative weights

sampleSingle

public static <DataType> DataType sampleSingle(double[] weights,
                                               Collection<? extends DataType> domain,
                                               Random random)
Samples a single element from the domain proportionately to the given weights

Type Parameters:
DataType - Type of data to be sampled
Parameters:
weights - Weights from which we will sample proportionately
domain - Domain from which to return the result
random - Random number generator
Returns:
A single sample from the domain proportionately from the weights

inverse

public static <DataType extends Number> InputOutputPair<DataType,Double> inverse(CumulativeDistributionFunction<DataType> cdf,
                                                                                 double p)
Inverts the discrete CDF, that is p=Pr{x<=X}.

Type Parameters:
DataType - Type of number from the distribution
Parameters:
cdf - CDF of a discrete distribution.
p - Probability to invert, must be [0,1].
Returns:
Value of x such that p >= CDF(x) and p <= CDF(x_next).

computeCumulativeValue

public static double computeCumulativeValue(int input,
                                            ClosedFormDiscreteUnivariateDistribution<? super Integer> distribution)
Computes the CDF value for the given PMF for the input. That is, the value of P=CDF(input)=sum(PMF(x<=input)).

Parameters:
input - Input to compute the CDF of.
distribution - Distribution to consider.
Returns:
CDF value of the distirbution for the given input