public static void CDFMethodForPositiveX(double x, double alpha, double gamma, double aga, ref object tempStorage, double precision, out double integFromXZero, out double integFromXInfinity, out double offs) { if (alpha <= 0) throw new ArgumentException("Alpha must be in the range alpha>0"); if (alpha < 1) { if (gamma <= 0) { offs = 1 - 0.5 * aga; if (x == 0) { integFromXZero = 0; integFromXInfinity = offs; } else // x != 0 { double factorp, facdiv, dev, logPdfPrefactor; GetAlt1GnParameterByGamma(x, alpha, gamma, aga, out factorp, out facdiv, out dev, out logPdfPrefactor); Alt1GnI inc = new Alt1GnI(factorp, facdiv, logPdfPrefactor, alpha, dev); if (inc.IsMaximumLeftHandSide()) { integFromXZero = inc.CDFIntegrate(ref tempStorage, precision) / Math.PI; integFromXInfinity = offs - integFromXZero; } else { integFromXInfinity = new Alt1GnD(factorp, facdiv, logPdfPrefactor, alpha, dev).CDFIntegrate(ref tempStorage, precision) / Math.PI; integFromXZero = offs - integFromXInfinity; } } } else // gamma>0 { offs = 0.5 * aga; if (x == 0) { integFromXZero = 0; integFromXInfinity = offs; } else // x!=0 { double factorp, facdiv, dev, logPdfPrefactor; GetAlt1GpParameterByGamma(x, alpha, gamma, aga, out factorp, out facdiv, out dev, out logPdfPrefactor); Alt1GpI inc = new Alt1GpI(factorp, facdiv, logPdfPrefactor, alpha, dev); if (inc.IsMaximumLeftHandSide()) { integFromXZero = inc.CDFIntegrate(ref tempStorage, precision) / Math.PI; integFromXInfinity = offs - integFromXZero; } else { integFromXInfinity = new Alt1GpD(factorp, facdiv, logPdfPrefactor, alpha, dev).CDFIntegrate(ref tempStorage, precision) / Math.PI; integFromXZero = offs - integFromXInfinity; } } } } else if (alpha == 1) { double a; // = Math.Cos(gamma*Math.PI/2); double b; // = Math.Sin(gamma*Math.PI/2); offs = 0.5; a = SinXPiBy2(aga); // for alpha=1 aga is 1-gamma or -1+gamma, thus we can turn cosine into sine b = SinXPiBy2(gamma); // for b it is not important to have high accuracy with gamma=1 or -1 double arg = (b + x) / a; if (arg <= 1) { integFromXZero = Math.Atan(arg) / Math.PI; integFromXInfinity = offs - integFromXZero; } else { integFromXInfinity = Math.Atan(1 / arg) / Math.PI; integFromXZero = offs - integFromXInfinity; } } else if (alpha <= 2) { double xinv = Math.Pow(x, -alpha); double alphainv = 1 / alpha; double gammainv = (gamma - alpha + 1) / alpha; double againv = aga; if (gamma > 0) againv = gammainv > 0 ? 2 * (alpha - 1) + aga : 2 * (2 - alpha) - aga; else againv = aga; CDFMethodForPositiveX(xinv, alphainv, gammainv, againv, ref tempStorage, precision, out integFromXZero, out integFromXInfinity, out offs); double h = integFromXZero; integFromXZero = integFromXInfinity / alpha; integFromXInfinity = h / alpha; offs /= alpha; } else { throw new ArgumentException("Alpha not in the range 0<alpha<=2"); } }
/// <summary> /// Special case for alpha < 1 and gamma near to +alpha (i.e. gamma at the positive border). /// Here gamma was set to alpha*(1-dev*2/Pi). /// </summary> /// <param name="x"></param> /// <param name="alpha"></param> /// <param name="gamma"></param> /// <param name="aga"></param> /// <param name="temp"></param> /// <param name="precision"></param> /// <returns></returns> public static double PDFIntegralAlt1Gp(double x, double alpha, double gamma, double aga, ref object temp, double precision) { double factorp, facdiv, dev, prefactor; GetAlt1GpParameterByGamma(x, alpha, gamma, aga, out factorp, out facdiv, out dev, out prefactor); double integrand; Alt1GpI intI = new Alt1GpI(factorp, facdiv, prefactor, alpha, dev); if (intI.IsMaximumLeftHandSide()) integrand = intI.Integrate(ref temp, precision); // IntegrateFuncExpMFuncInc(delegate(double theta) { return PDFCoreAlt1GpI(factorp, facdiv, alpha, dev, theta); }, 0, dev, ref temp, precision); else integrand = new Alt1GpD(factorp, facdiv, prefactor, alpha, dev).Integrate(ref temp, precision); // IntegrateFuncExpMFuncDec(delegate(double theta) { return PDFCoreAlt1GpD(factorp, facdiv, alpha, dev, theta); }, 0, dev, ref temp, precision); return integrand; }