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 int
DEFAULT_MAX_ITERATIONS
Used 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 boolean
canMatchMoments(double... moments)
double
cdf(double x)
Returns the F(x) = Pr{X <= x} where F represents the cumulative distribution functiondouble
cdf(int x)
static Poisson
createFromMoments(double... moments)
double
firstOrderLossFunction(double x)
Computes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]double
getMean()
Returns the mean or expected value of a distributionint
getMode()
double[]
getParameters()
Gets the parameters for the distributionstatic double[]
getParametersFromMoments(double... moments)
RVariableIfc
getRandomVariable(RNStreamIfc rng)
double
getVariance()
Returns the variance of the distribution if defineddouble
invCDF(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 int
invCDFViaNormalApprox(double p, double mean)
Poisson
newInstance()
Returns a new instancedouble
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 probabilitydouble
pmf(int x)
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 algorithmstatic double
poissonCCDF(int j, double mean, boolean recursive)
Allows static computation of complementary cdf function assumes that distribution's range is {0,1, ...}static double
poissonCDF(int j, double mean)
Allows static computation of cdf assumes that distribution's range is {0,1, ...} Uses the recursive logarithmic algorithmstatic 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 accuracystatic 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 algorithmstatic 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, ...}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)]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)]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 algorithmstatic double
poissonPMF(int j, double mean, boolean recursive)
Allows static computation of prob mass function assumes that distribution's range is {0,1, ...}static double
recursiveCDF(int j, double mean)
Computes the cdf at j using a recursive (iterative) algorithm using logarithmsstatic double
recursivePMF(int j, double mean)
Computes the probability mass function at j using a recursive (iterative) algorithm using logarithmsprotected static int
searchDownCDF(double p, double mean, int start, double cdfAtStart, boolean recursive)
protected static int
searchUpCDF(double p, double mean, int start, double cdfAtStart, boolean recursive)
double
secondOrderLossFunction(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)]void
setMean(double mean)
Sets the mean of the Poisson distributionvoid
setParameters(double[] parameters)
Sets the parameters for the distribution parameters[0] should be the mean ratedouble
thirdOrderLossFunction(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:NewInstanceIfc
Returns a new instance- Specified by:
newInstance
in interfaceNewInstanceIfc
- Specified by:
newInstance
in classDistribution
- Returns:
- the new instance
-
getMean
public final double getMean()
Description copied from interface:MeanIfc
Returns the mean or expected value of a distribution
-
getVariance
public final double getVariance()
Description copied from interface:VarianceIfc
Returns the variance of the distribution if defined- Specified by:
getVariance
in 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:CDFIfc
Returns 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:FirstOrderLossFunctionIfc
Computes the first order loss function for the function for given value of x, G1(x) = E[max(X-x,0)]- Specified by:
firstOrderLossFunction
in 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:SecondOrderLossFunctionIfc
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)]- Specified by:
secondOrderLossFunction
in 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:InverseCDFIfc
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.- Specified by:
invCDF
in 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:
setParameters
in 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:
getParameters
in 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:
getRandomVariable
in interfaceGetRVariableIfc
- Overrides:
getRandomVariable
in classDistribution
- Parameters:
rng
- the stream to use- Returns:
- a random variable
-
-