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

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

package toolgood.algorithm.mathNet.Distributions;

import toolgood.algorithm.mathNet.SpecialFunctions;

public class Weibull {
    /// 
        /// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
        /// 
        /// The shape (k) of the Weibull distribution. Range: k > 0.
        /// The scale (λ) of the Weibull distribution. Range: λ > 0.
        /// The location at which to compute the density.
        /// the density at .
        ///// 
        public static double PDF(double shape, double scale, double x)
        {
            //if (shape <= 0.0 || scale <= 0.0) {
            //    throw new ArgumentException("InvalidDistributionParameters");
            //}

            if (x >= 0.0) {
                if (x == 0.0 && shape == 1.0) {
                    return shape / scale;
                }

                return shape
                       * Math.pow(x / scale, shape - 1.0)
                       * Math.exp(-Math.pow(x, shape) * Math.pow(scale, -shape))
                       / scale;
            }

            return 0.0;
        }
         

        /// 
        /// Computes the cumulative distribution (CDF) of the distribution at x, i.e. P(X ≤ x).
        /// 
        /// The location at which to compute the cumulative distribution function.
        /// The shape (k) of the Weibull distribution. Range: k > 0.
        /// The scale (λ) of the Weibull distribution. Range: λ > 0.
        /// the cumulative distribution at location .
        ///// 
        public static double CDF(double shape, double scale, double x)
        {
            //if (shape <= 0.0 || scale <= 0.0) {
            //    throw new ArgumentException("InvalidDistributionParameters");
            //}

            if (x < 0.0) {
                return 0.0;
            }

            return -SpecialFunctions.ExponentialMinusOne(-Math.pow(x, shape) * Math.pow(scale, -shape));
        }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy