public class ProbabilityMassFunctionUtil
extends java.lang.Object
Constructor and Description |
---|
ProbabilityMassFunctionUtil() |
Modifier and Type | Method and Description |
---|---|
static double |
computeCumulativeValue(int input,
ClosedFormDiscreteUnivariateDistribution<? super java.lang.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 java.lang.Number> |
inverse(CumulativeDistributionFunction<DataType> cdf,
double p)
Inverts the discrete CDF, that is p=Pr{x<=X}.
|
static <DataType> DataType |
sample(double[] cumulativeWeights,
java.util.List<? extends DataType> domain,
java.util.Random random)
Samples an element from the domain proportionately to the
cumulative weights in the given weight array using a fast
binary search algorithm.
|
static <DataType> java.util.ArrayList<DataType> |
sample(ProbabilityMassFunction<DataType> pmf,
java.util.Random random,
int numSamples)
Samples from the ProbabilityMassFunction.
|
static <DataType> void |
sampleInto(ProbabilityMassFunction<DataType> pmf,
java.util.Random random,
int numSamples,
java.util.Collection<? super DataType> output)
Samples from the ProbabilityMassFunction.
|
static <DataType> java.util.ArrayList<DataType> |
sampleMultiple(double[] cumulativeWeights,
java.util.List<? extends DataType> domain,
java.util.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> java.util.ArrayList<DataType> |
sampleMultiple(ProbabilityMassFunction<DataType> pmf,
java.util.Random random,
int numSamples)
Samples from the ProbabilityMassFunction.
|
static <DataType> void |
sampleMultipleInto(double[] cumulativeWeights,
java.util.List<? extends DataType> domain,
java.util.Random random,
int numSamples,
java.util.Collection<? super DataType> output)
Samples multiple elements from the domain proportionately to the
cumulative weights in the given weight array using a fast
binary search algorithm
|
static <DataType> void |
sampleMultipleInto(ProbabilityMassFunction<DataType> pmf,
java.util.Random random,
int numSamples,
java.util.Collection<? super DataType> output)
Samples from the ProbabilityMassFunction.
|
static <DataType> DataType |
sampleSingle(double[] weights,
java.util.Collection<? extends DataType> domain,
java.util.Random random)
Samples a single element from the domain proportionately to the given
weights
|
static <DataType> DataType |
sampleSingle(ProbabilityMassFunction<DataType> pmf,
java.util.Random random)
Draws a single sample from the given PMF
|
@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)
DataType
- Type of data on the domain of the PMF.pmf
- PMF to compute the entropy.public static <DataType> java.util.ArrayList<DataType> sample(ProbabilityMassFunction<DataType> pmf, java.util.Random random, int numSamples)
DataType
- Type of data to usepmf
- PMF from which to samplerandom
- Random to sample fromnumSamples
- Number of samples to draw from the given PMF.public static <DataType> void sampleInto(ProbabilityMassFunction<DataType> pmf, java.util.Random random, int numSamples, java.util.Collection<? super DataType> output)
DataType
- Type of data to usepmf
- PMF from which to samplerandom
- Random to sample fromnumSamples
- Number of samples to draw from the given PMF.output
- Collection to add samples drawn according to the given PMF.public static <DataType> DataType sampleSingle(ProbabilityMassFunction<DataType> pmf, java.util.Random random)
DataType
- Type of observations generated by the PMFpmf
- PMF from which to draw.random
- Random number generatorpublic static <DataType> java.util.ArrayList<DataType> sampleMultiple(ProbabilityMassFunction<DataType> pmf, java.util.Random random, int numSamples)
DataType
- Type of data to usepmf
- PMF from which to samplerandom
- Random to sample fromnumSamples
- Number of samples to draw from the given PMF.public static <DataType> void sampleMultipleInto(ProbabilityMassFunction<DataType> pmf, java.util.Random random, int numSamples, java.util.Collection<? super DataType> output)
DataType
- Type of data to usepmf
- PMF from which to samplerandom
- Random to sample fromnumSamples
- Number of samples to draw from the given PMF.output
- Collection to add samples drawn according to the given PMF.public static <DataType> java.util.ArrayList<DataType> sampleMultiple(double[] cumulativeWeights, java.util.List<? extends DataType> domain, java.util.Random random, int numSamples)
DataType
- Type of data to be sampledcumulativeWeights
- Cumulative weights to sample fromdomain
- Domain from which to samplerandom
- Random number generatornumSamples
- Number of samples to draw from the distributionpublic static <DataType> void sampleMultipleInto(double[] cumulativeWeights, java.util.List<? extends DataType> domain, java.util.Random random, int numSamples, java.util.Collection<? super DataType> output)
DataType
- Type of data to be sampledcumulativeWeights
- Cumulative weights to sample fromdomain
- Domain from which to samplerandom
- Random number generatornumSamples
- Number of samples to draw from the distributionoutput
- The collection to put the samples in.public static <DataType> DataType sample(double[] cumulativeWeights, java.util.List<? extends DataType> domain, java.util.Random random)
DataType
- Type of data to be sampledcumulativeWeights
- Cumulative weights to sample fromdomain
- Domain from which to samplerandom
- Random number generatorpublic static <DataType> DataType sampleSingle(double[] weights, java.util.Collection<? extends DataType> domain, java.util.Random random)
DataType
- Type of data to be sampledweights
- Weights from which we will sample proportionatelydomain
- Domain from which to return the resultrandom
- Random number generatorpublic static <DataType extends java.lang.Number> InputOutputPair<DataType,java.lang.Double> inverse(CumulativeDistributionFunction<DataType> cdf, double p)
DataType
- Type of number from the distributioncdf
- CDF of a discrete distribution.p
- Probability to invert, must be [0,1].public static double computeCumulativeValue(int input, ClosedFormDiscreteUnivariateDistribution<? super java.lang.Integer> distribution)
input
- Input to compute the CDF of.distribution
- Distribution to consider.