コード例 #1
0
		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");
			}
		}
コード例 #2
0
		private static double CDFIntegralForPositiveXAlt1(double x, double alpha, double gamma, double aga, ref object temp, double precision, out bool inverseRuleUsed)
		{
			double result;
			if (gamma <= 0)
			{
				double factorp, facdiv, dev, logPdfPrefactor;
				GetAlt1GnParameterByGamma(x, alpha, gamma, aga, out factorp, out facdiv, out dev, out logPdfPrefactor);
				Alt1GnI a = new Alt1GnI(factorp, facdiv, logPdfPrefactor, alpha, dev);
				result = a.CDFIntegrate(ref temp, precision);
				inverseRuleUsed = false;
			}
			else
			{
				double factorp, facdiv, dev, logPdfPrefactor;
				GetAlt1GpParameterByGamma(x, alpha, gamma, aga, out factorp, out facdiv, out dev, out logPdfPrefactor);
				Alt1GpI a = new Alt1GpI(factorp, facdiv, logPdfPrefactor, alpha, dev);
				result = a.CDFIntegrate(ref temp, precision);
				inverseRuleUsed = false;
			}
			return result;
		}