Пример #1
0
        public static double QuantileCCDF(double q, double alpha)
        {
            if (q == 0.5)
            {
                return(0);
            }

            double xguess = Math.Exp(2 / alpha); // guess value for a nearly constant p value in dependence of alpha
            double x0, x1;

            if (q > 0.5)
            {
                x0 = -xguess;
                x1 = 0;
            }
            else
            {
                x0 = 0;
                x1 = xguess;
            }

            object tempStorage = null;

            if (QuickRootFinding.BracketRootByExtensionOnly(delegate(double x)
                                                            { return(CCDF(x, alpha, ref tempStorage, DefaultPrecision) - q); }, 0, ref x0, ref x1))
            {
                if (null == QuickRootFinding.ByBrentsAlgorithm(delegate(double x)
                                                               { return(CCDF(x, alpha, ref tempStorage, DefaultPrecision) - q); }, x0, x1, 0, DoubleConstants.DBL_EPSILON, out var root))
                {
                    return(root);
                }
            }
            return(double.NaN);
        }
Пример #2
0
        public static double Quantile(double p, double alpha, double beta, double abe, ref object tempStorage, double precision)
        {
            double xguess = Math.Exp(2 / alpha); // guess value for a nearly constant p value in dependence of alpha
            double x0     = -xguess;
            double x1     = xguess;

            object temp = tempStorage;
            double root = double.NaN;

            if (QuickRootFinding.BracketRootByExtensionOnly(delegate(double x)
                                                            { return(CDF(x, alpha, beta, abe, 1, 0, ref temp, DefaultPrecision) - p); }, 0, ref x0, ref x1))
            {
                if (null != QuickRootFinding.ByBrentsAlgorithm(delegate(double x)
                                                               { return(CDF(x, alpha, beta, abe, 1, 0, ref temp, DefaultPrecision) - p); }, x0, x1, 0, DoubleConstants.DBL_EPSILON, out root))
                {
                    root = double.NaN;
                }
            }
            tempStorage = temp;

            return(root);
        }