Class Poisson

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DEFAULT_MAX_ITERATIONS
      Used in the calculation of the incomplete gamma function
    • Constructor Summary

      Constructors 
      Constructor Description
      Poisson()
      Constructs a Poisson with mean rate parameter 1.0
      Poisson​(double mean)
      Constructs a Poisson using the supplied parameter
      Poisson​(double[] parameters)
      Constructs a Poisson using the supplied parameter
      Poisson​(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 function
      double 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 distribution
      int getMode()  
      double[] getParameters()
      Gets the parameters for the distribution
      static double[] getParametersFromMoments​(double... moments)  
      RVariableIfc getRandomVariable​(RNStreamIfc rng)  
      double getVariance()
      Returns the variance of the distribution if defined
      double 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 instance
      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
      double 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 algorithm
      static 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 algorithm
      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
      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
      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, ...}
      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 algorithm
      static 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 logarithms
      static double recursivePMF​(int j, double mean)
      Computes the probability mass function at j using a recursive (iterative) algorithm using logarithms
      protected 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 distribution
      void setParameters​(double[] parameters)
      Sets the parameters for the distribution parameters[0] should be the mean rate
      double thirdOrderLossFunction​(double x)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 rate
        name - an optional label/name
    • Method Detail

      • getMean

        public final double getMean()
        Description copied from interface: MeanIfc
        Returns the mean or expected value of a distribution
        Specified by:
        getMean in interface MeanIfc
        Returns:
        double the mean or expected value for the distribution
      • getVariance

        public final double getVariance()
        Description copied from interface: VarianceIfc
        Returns the variance of the distribution if defined
        Specified by:
        getVariance in interface VarianceIfc
        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
        Specified by:
        cdf in interface CDFIfc
        Parameters:
        x - a double representing the upper limit
        Returns:
        a double representing the probability
      • 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 interface FirstOrderLossFunctionIfc
        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 interface SecondOrderLossFunctionIfc
        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 interface InverseCDFIfc
        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
        Specified by:
        pmf in interface PMFIfc
        Parameters:
        x - the value to evaluate
        Returns:
        the probability at the point
      • setParameters

        public final void setParameters​(double[] parameters)
        Sets the parameters for the distribution parameters[0] should be the mean rate
        Specified by:
        setParameters in interface ParametersIfc
        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 interface ParametersIfc
        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 evaluate
        mean - 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 evaluate
        mean - 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 needed
        mean - 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 needed
        mean - of the distribution
        recursive - 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 needed
        mean - 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 needed
        mean - of the distribution
        recursive - 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 needed
        mean - 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 needed
        mean - of the distribution
        recursive - 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 evaluated
        mean - of the distribution
        recursive - 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 evaluated
        mean - of the distribution
        recursive - 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 for
        mean - 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 for
        mean - of the distribution
        recursive - 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 search
        mean - the mean of the distribution
        start - the starting point of the search
        cdfAtStart - the CDF at the starting point
        recursive - 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 search
        mean - the mean of the distribution
        start - the starting point of the search
        cdfAtStart - the CDF at the starting point
        recursive - 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 search
        mean - the mean of the distribution
        Returns:
        the inverse via a normal approximation