コード例 #1
0
ファイル: Distributions.cs プロジェクト: mpvyard/QuantRiskLib
        /// <summary>
        /// Returns the PDF of a beta distribution with shape parameters a and b.
        /// f(x) = x^(a-1) * (1-x)^(b-1) / B(a,b)
        /// </summary>
        /// <param name="x">Value of the random variable for which the PDF is beign evaluated. x is between 0 and 1.</param>
        /// <param name="a">Number of trials.</param>
        /// <param name="b">Number of times the event occurs in n trials.</param>
        /// <returns></returns>
        public static double BetaProbabilityDensityFunction(double x, double a, double b)
        {
            if (x < 0 || x > 1)
            {
                throw new ArgumentException("x must be between 0 and 1");
            }

            double B = MMath.BetaFunction(a, b);
            double d = Math.Pow(x, a - 1) * Math.Pow(1 - x, b - 1) / B;

            return(d);
        }
コード例 #2
0
ファイル: Distributions.cs プロジェクト: mpvyard/QuantRiskLib
        /// <summary>
        /// Returns the PDF of the F distribution.
        /// </summary>
        /// <param name="x">Value at which the distribution is evaluated.</param>
        /// <param name="k1">Degrees of freedom for numerator chi-sqared distribution. k1 > 0.</param>
        /// <param name="k2">Degrees of freedom for denominator chi-sqared distribution. k2 > 0.</param>
        public static double FProbabilityDensityFunction(double x, int k1, int k2)
        {
            if (k1 <= 0 || k2 <= 0)
            {
                throw new ArgumentException("k1 and k2 must be greater than 0.");
            }
            if (x == 0)
            {
                return(0.0);
            }

            double a1 = Math.Pow(k1 * x, 0.5 * k1);
            double a2 = Math.Pow(k2, 0.5 * k2);
            double a3 = Math.Pow(k1 * x + k2, 0.5 * (k1 + k2));
            double a  = a1 * a2 / a3;
            double b  = MMath.BetaFunction(0.5 * k1, 0.5 * k2);
            double c  = x * b;

            return(a / c);
        }