All Downloads are FREE. Search and download functionalities are using the official Maven repository.

toolgood.algorithm.mathNet.Distributions.NegativeBinomial Maven / Gradle / Ivy

package toolgood.algorithm.mathNet.Distributions;

import toolgood.algorithm.mathNet.SpecialFunctions;

public class NegativeBinomial {
      /// 
        /// Computes the probability mass (PMF) at k, i.e. P(X = k).
        /// 
        /// The location in the domain where we want to evaluate the probability mass function.
        /// The number of failures (r) until the experiment stopped. Range: r ≥ 0.
        /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.
        /// the probability mass at location .
        public static double PMF(double r, double p, int k)
        {
            return Math.exp(PMFLn(r, p, k));
        }

        /// 
        /// Computes the log probability mass (lnPMF) at k, i.e. ln(P(X = k)).
        /// 
        /// The location in the domain where we want to evaluate the log probability mass function.
        /// The number of failures (r) until the experiment stopped. Range: r ≥ 0.
        /// The probability (p) of a trial resulting in success. Range: 0 ≤ p ≤ 1.
        /// the log probability mass at location .
        public static double PMFLn(double r, double p, int k)
        {
            //if (!(r >= 0.0 && p >= 0.0 && p <= 1.0)) {
            //    throw new ArgumentException("InvalidDistributionParameters");
            //}

            return SpecialFunctions.GammaLn(r + k)
                   - SpecialFunctions.GammaLn(r)
                   - SpecialFunctions.GammaLn(k + 1.0)
                   + (r * Math.log(p))
                   + (k * Math.log(1.0 - p));
        }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy