Package jsl.utilities.distributions
Class Poisson
- java.lang.Object
-
- jsl.utilities.distributions.Distribution
-
- jsl.utilities.distributions.Poisson
-
- All Implemented Interfaces:
ControllableIfc,CDFIfc,DiscreteDistributionIfc,DistributionFunctionIfc,DistributionIfc,FirstOrderLossFunctionIfc,InverseCDFIfc,LossFunctionDistributionIfc,MeanIfc,PMFIfc,SecondOrderLossFunctionIfc,VarianceIfc,GetNameIfc,IdentityIfc,NewInstanceIfc,ParametersIfc,GetRVariableIfc
public class Poisson extends Distribution implements DiscreteDistributionIfc, LossFunctionDistributionIfc, GetRVariableIfc
Represents a Poisson random variable. A Poisson random variable represents the number of occurrences of an event with time or space.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jsl.utilities.distributions.Distribution
Distribution.RandomControls
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAX_ITERATIONSUsed in the calculation of the incomplete gamma function-
Fields inherited from class jsl.utilities.distributions.Distribution
myId, myName
-
-
Constructor Summary
Constructors Constructor Description Poisson()Constructs a Poisson with mean rate parameter 1.0Poisson(double mean)Constructs a Poisson using the supplied parameterPoisson(double[] parameters)Constructs a Poisson using the supplied parameterPoisson(double mean, java.lang.String name)Constructs a Poisson using the supplied parameter
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static booleancanMatchMoments(double... moments)doublecdf(double x)Returns the F(x) = Pr{X <= x} where F represents the cumulative distribution functiondoublecdf(int x)static PoissoncreateFromMoments(double... moments)doublefirstOrderLossFunction(double x)Computes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]doublegetMean()Returns the mean or expected value of a distributionintgetMode()double[]getParameters()Gets the parameters for the distributionstatic double[]getParametersFromMoments(double... moments)RVariableIfcgetRandomVariable(RNStreamIfc rng)doublegetVariance()Returns the variance of the distribution if defineddoubleinvCDF(double prob)Provides the inverse cumulative distribution function for the distribution While closed form solutions for the inverse cdf may not exist, numerical search methods can be used to solve F(X) = U.protected static intinvCDFViaNormalApprox(double p, double mean)PoissonnewInstance()Returns a new instancedoublepmf(double x)If x is not and integer value, then the probability must be zero otherwise pmf(int x) is used to determine the probabilitydoublepmf(int x)static doublepoissonCCDF(int j, double mean)Allows static computation of complementary cdf function assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithmstatic doublepoissonCCDF(int j, double mean, boolean recursive)Allows static computation of complementary cdf function assumes that distribution's range is {0,1, ...}static doublepoissonCDF(int j, double mean)Allows static computation of cdf assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithmstatic doublepoissonCDF(int j, double mean, boolean recursive)Allows static computation of cdf assumes that distribution's range is {0,1, ...} false indicated the use of the incomplete gamma function It yields about 7 digits of accuracy, the recursive algorithm has more accuracystatic intpoissonInvCDF(double p, double mean)Returns the quantile associated with the supplied probablity, x assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithmstatic intpoissonInvCDF(double p, double mean, boolean recursive)Returns the quantile associated with the supplied probablity, x assumes that distribution's range is {0,1, ...}static doublepoissonLF1(double x, double mean, boolean recursive)Computes the first order loss function for the distribution function for given value of x, G1(x) = E[max(X-x,0)]static doublepoissonLF2(double x, double mean, boolean recursive)Computes the 2nd order loss function for the distribution function for given value of x, G2(x) = (1/2)E[max(X-x,0)*max(X-x-1,0)]static doublepoissonPMF(int j, double mean)Allows static computation of prob mass function assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithmstatic doublepoissonPMF(int j, double mean, boolean recursive)Allows static computation of prob mass function assumes that distribution's range is {0,1, ...}static doublerecursiveCDF(int j, double mean)Computes the cdf at j using a recursive (iterative) algorithm using logarithmsstatic doublerecursivePMF(int j, double mean)Computes the probability mass function at j using a recursive (iterative) algorithm using logarithmsprotected static intsearchDownCDF(double p, double mean, int start, double cdfAtStart, boolean recursive)protected static intsearchUpCDF(double p, double mean, int start, double cdfAtStart, boolean recursive)doublesecondOrderLossFunction(double x)Computes the 2nd order loss function for the distribution function for given value of x, G2(x) = (1/2)E[max(X-x,0)*max(X-x-1,0)]voidsetMean(double mean)Sets the mean of the Poisson distributionvoidsetParameters(double[] parameters)Sets the parameters for the distribution parameters[0] should be the mean ratedoublethirdOrderLossFunction(double x)-
Methods inherited from class jsl.utilities.distributions.Distribution
getControls, getId, getName, getStandardDeviation, inverseContinuousCDFViaBisection, inverseContinuousCDFViaBisection, inverseDiscreteCDFViaSearchUp, setControls, setId, setName, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jsl.utilities.distributions.CDFIfc
cdf, complementaryCDF
-
Methods inherited from interface jsl.utilities.random.rvariable.GetRVariableIfc
getRandomVariable, getRandomVariable
-
Methods inherited from interface jsl.utilities.distributions.VarianceIfc
getStandardDeviation
-
-
-
-
Field Detail
-
DEFAULT_MAX_ITERATIONS
public static final int DEFAULT_MAX_ITERATIONS
Used in the calculation of the incomplete gamma function- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Poisson
public Poisson()
Constructs a Poisson with mean rate parameter 1.0
-
Poisson
public Poisson(double[] parameters)
Constructs a Poisson using the supplied parameter- Parameters:
parameters- A array that holds the parameters, parameters[0] should be the mean rate
-
Poisson
public Poisson(double mean)
Constructs a Poisson using the supplied parameter- Parameters:
mean- the mean rate
-
Poisson
public Poisson(double mean, java.lang.String name)Constructs a Poisson using the supplied parameter- Parameters:
mean- the mean ratename- an optional label/name
-
-
Method Detail
-
newInstance
public final Poisson newInstance()
Description copied from interface:NewInstanceIfcReturns a new instance- Specified by:
newInstancein interfaceNewInstanceIfc- Specified by:
newInstancein classDistribution- Returns:
- the new instance
-
getMean
public final double getMean()
Description copied from interface:MeanIfcReturns the mean or expected value of a distribution
-
getVariance
public final double getVariance()
Description copied from interface:VarianceIfcReturns the variance of the distribution if defined- Specified by:
getVariancein interfaceVarianceIfc- Returns:
- double the variance of the random variable
-
setMean
public final void setMean(double mean)
Sets the mean of the Poisson distribution- Parameters:
mean- the mean rate, mean must be > 0
-
getMode
public final int getMode()
- Returns:
- the mode of the distribution
-
cdf
public final double cdf(int x)
-
cdf
public final double cdf(double x)
Description copied from interface:CDFIfcReturns the F(x) = Pr{X <= x} where F represents the cumulative distribution function
-
canMatchMoments
public static boolean canMatchMoments(double... moments)
-
getParametersFromMoments
public static double[] getParametersFromMoments(double... moments)
-
createFromMoments
public static Poisson createFromMoments(double... moments)
-
firstOrderLossFunction
public final double firstOrderLossFunction(double x)
Description copied from interface:FirstOrderLossFunctionIfcComputes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]- Specified by:
firstOrderLossFunctionin interfaceFirstOrderLossFunctionIfc- Parameters:
x- The value to be evaluated- Returns:
- The loss function value, E[max(X-x,0)]
-
secondOrderLossFunction
public final double secondOrderLossFunction(double x)
Description copied from interface:SecondOrderLossFunctionIfcComputes the 2nd order loss function for the distribution function for given value of x, G2(x) = (1/2)E[max(X-x,0)*max(X-x-1,0)]- Specified by:
secondOrderLossFunctionin interfaceSecondOrderLossFunctionIfc- Parameters:
x- The value to be evaluated- Returns:
- The loss function value, (1/2)E[max(X-x,0)*max(X-x-1,0)]
-
thirdOrderLossFunction
public double thirdOrderLossFunction(double x)
-
invCDF
public final double invCDF(double prob)
Description copied from interface:InverseCDFIfcProvides the inverse cumulative distribution function for the distribution While closed form solutions for the inverse cdf may not exist, numerical search methods can be used to solve F(X) = U.- Specified by:
invCDFin interfaceInverseCDFIfc- Parameters:
prob- The probability to be evaluated for the inverse, p must be [0,1] or an IllegalArgumentException is thrown- Returns:
- The inverse cdf evaluated at the supplied probability
-
pmf
public final double pmf(int x)
-
pmf
public final double pmf(double x)
If x is not and integer value, then the probability must be zero otherwise pmf(int x) is used to determine the probability
-
setParameters
public final void setParameters(double[] parameters)
Sets the parameters for the distribution parameters[0] should be the mean rate- Specified by:
setParametersin interfaceParametersIfc- Parameters:
parameters- an array of doubles representing the parameters for the distribution
-
getParameters
public final double[] getParameters()
Gets the parameters for the distribution- Specified by:
getParametersin interfaceParametersIfc- Returns:
- Returns an array of the parameters for the distribution
-
recursivePMF
public static double recursivePMF(int j, double mean)Computes the probability mass function at j using a recursive (iterative) algorithm using logarithms- Parameters:
j- the value to evaluatemean- the mean- Returns:
- the PMF value
-
recursiveCDF
public static double recursiveCDF(int j, double mean)Computes the cdf at j using a recursive (iterative) algorithm using logarithms- Parameters:
j- the value to evaluatemean- the mean- Returns:
- the CDF value
-
poissonPMF
public static double poissonPMF(int j, double mean)Allows static computation of prob mass function assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithm- Parameters:
j- value for which prob is neededmean- of the distribution- Returns:
- the PMF value
-
poissonPMF
public static double poissonPMF(int j, double mean, boolean recursive)Allows static computation of prob mass function assumes that distribution's range is {0,1, ...}- Parameters:
j- value for which prob is neededmean- of the distributionrecursive- true indicates that the recursive logarithmic algorithm should be used- Returns:
- the PMF value
-
poissonCDF
public static double poissonCDF(int j, double mean)Allows static computation of cdf assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithm- Parameters:
j- value for which prob is neededmean- of the distribution- Returns:
- the cdf value
-
poissonCDF
public static double poissonCDF(int j, double mean, boolean recursive)Allows static computation of cdf assumes that distribution's range is {0,1, ...} false indicated the use of the incomplete gamma function It yields about 7 digits of accuracy, the recursive algorithm has more accuracy- Parameters:
j- value for which prob is neededmean- of the distributionrecursive- true indicates that the recursive logarithmic algorithm should be used- Returns:
- the cdf value
-
poissonCCDF
public static double poissonCCDF(int j, double mean)Allows static computation of complementary cdf function assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithm- Parameters:
j- value for which ccdf is neededmean- of the distribution- Returns:
- the complimentary CDF value
-
poissonCCDF
public static double poissonCCDF(int j, double mean, boolean recursive)Allows static computation of complementary cdf function assumes that distribution's range is {0,1, ...}- Parameters:
j- value for which ccdf is neededmean- of the distributionrecursive- true indicates that the recursive logarithmic algorithm should be used- Returns:
- the complimentary CDF value
-
poissonLF1
public static double poissonLF1(double x, double mean, boolean recursive)Computes the first order loss function for the distribution function for given value of x, G1(x) = E[max(X-x,0)]- Parameters:
x- The value to be evaluatedmean- of the distributionrecursive- true indicates that the recursive logarithmic algorithm should be used- Returns:
- The loss function value, E[max(X-x,0)]
-
poissonLF2
public static double poissonLF2(double x, double mean, boolean recursive)Computes the 2nd order loss function for the distribution function for given value of x, G2(x) = (1/2)E[max(X-x,0)*max(X-x-1,0)]- Parameters:
x- The value to be evaluatedmean- of the distributionrecursive- true indicates that the recursive logarithmic algorithm should be used- Returns:
- The loss function value, (1/2)E[max(X-x,0)*max(X-x-1,0)]
-
poissonInvCDF
public static int poissonInvCDF(double p, double mean)Returns the quantile associated with the supplied probablity, x assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithm- Parameters:
p- The probability that the quantile is needed formean- of the distribution- Returns:
- the quantile associated with the supplied probablity
-
poissonInvCDF
public static int poissonInvCDF(double p, double mean, boolean recursive)Returns the quantile associated with the supplied probablity, x assumes that distribution's range is {0,1, ...}- Parameters:
p- The probability that the quantile is needed formean- of the distributionrecursive- true indicates that the recursive logarithmic algorithm should be used- Returns:
- the quantile associated with the supplied probablity
-
searchUpCDF
protected static int searchUpCDF(double p, double mean, int start, double cdfAtStart, boolean recursive)- Parameters:
p- the probability to searchmean- the mean of the distributionstart- the starting point of the searchcdfAtStart- the CDF at the starting pointrecursive- true indicates that the recursive logarithmic algorithm should be used- Returns:
- the found value
-
searchDownCDF
protected static int searchDownCDF(double p, double mean, int start, double cdfAtStart, boolean recursive)- Parameters:
p- the probability to searchmean- the mean of the distributionstart- the starting point of the searchcdfAtStart- the CDF at the starting pointrecursive- true indicates that the recursive logarithmic algorithm should be used- Returns:
- the found value
-
invCDFViaNormalApprox
protected static int invCDFViaNormalApprox(double p, double mean)- Parameters:
p- the probability to searchmean- the mean of the distribution- Returns:
- the inverse via a normal approximation
-
getRandomVariable
public final RVariableIfc getRandomVariable(RNStreamIfc rng)
- Specified by:
getRandomVariablein interfaceGetRVariableIfc- Overrides:
getRandomVariablein classDistribution- Parameters:
rng- the stream to use- Returns:
- a random variable
-
-