Internal function used by GammaCdf

@param x
@param A
@return
350022
protected static double Gcf(double x, double A)
    {
        // Good for X>A+1
        double A0 = 0;
        double B0 = 1;
        double A1 = 1;
        double B1 = x;
        double AOLD = 0;
        double N = 0;
        while (Math.abs((A1 - AOLD) / A1) > .00001)
        {
            AOLD = A1;
            N = N + 1;
            A0 = A1 + (N - A) * A0;
            B0 = B1 + (N - A) * B0;
            A1 = x * A0 + N * A1;
            B1 = x * B0 + N * B1;
            A0 = A0 / B1;
            B0 = B0 / B1;
            A1 = A1 / B1;
            B1 = 1;
        }
        double Prob = Math.exp(A * Math.log(x) - x - LogGamma(A)) * A1;

        return 1.0 - Prob;
    }
1246862
public static double cdf(double val, double k, double theta) {
    if(val < 0) {
      return 0.;
    }
    final double vt = val * theta;
    return (vt == Double.POSITIVE_INFINITY) ? 1. : regularizedGammaP(k, vt);
  }
1326018
private static double AndersonDarling(double[] x) {
        int n = x.length;
        Arrays.sort(x);

        for (int i = 0; i < n; i++) {
            x[i] = GaussianDistribution.getInstance().cdf(x[i]);
            // in case overflow when taking log later.
            if (x[i] == 0) x[i] = 0.0000001;
            if (x[i] == 1) x[i] = 0.9999999;
        }

        double A = 0.0;
        for (int i = 0; i < n; i++) {
            A -= (2*i+1) * (Math.log(x[i]) + Math.log(1-x[n-i-1]));
        }

        A = A / n - n;
        A *= (1 + 4.0/n - 25.0/(n*n));

        return A;
    }
74420
def nhill_a(self,x,threshold=0.1,power=2,ichild=2):
        
        x_pow = np.power(x,power)
        threshold_pow = np.power(threshold,power)
        return x_pow / (x_pow + threshold_pow) * (1 + threshold_pow)
821966
public static double studentsCdf(double x, int df) {
        if(df<=0) {
            throw new IllegalArgumentException("The degrees of freedom need to be positive.");
        }

        double A = df/2.0;
        double S = A+0.5;
        double Z = df/(df + x*x);
        double BT = Math.exp(logGamma(S)-logGamma(0.5)-logGamma(A)+A*Math.log(Z)+0.5*Math.log(1.0-Z));
        double betacdf;
        if (Z<(A+1.0)/(S+2.0)) {
            betacdf = BT*betinc(Z,A,0.5);
        } 
        else {
            betacdf=1-BT*betinc(1.0-Z,0.5,A);
        }
        
        double tcdf;
        if (x<0) {
            tcdf=betacdf/2.0;
        } 
        else {
            tcdf=1.0-betacdf/2.0;
        }

        return tcdf;
    }
154349
def cdf(x, df, loc=0.0, scale=1.0, gamma = 1.0):
        
        result = np.zeros(x.shape[0])
        result[x<0] = 2.0/(np.power(gamma,2) + 1.0)*ss.t.cdf(gamma*(x[x-loc < 0]-loc[x-loc < 0])/scale, df=df)
        result[x>=0] = 1.0/(np.power(gamma,2) + 1.0) + 2.0/((1.0/np.power(gamma,2)) + 1.0)*(ss.t.cdf((x[x-loc >= 0]-loc[x-loc >= 0])/(gamma*scale), df=df)-0.5)
        return result
1158593
function gammaCheng(a, s) {
      var c1, c2, c3, c4;

      c1 = a - 1;
      c2 = (a - 1 / (6 * a)) / c1;
      c3 = 2 / c1;
      c4 = c3 + 2;

      return function() {
         var u1, u2, w;

         /* eslint-disable no-constant-condition */
         while (true) {
         /* eslint-enable */
            u1 = rgen.random();
            u2 = rgen.random();
            w = c2 * u2 / u1;
            if (c3 * u1 + w + 1 / w <= c4) {
               return c1 * w * s;
            }
            if (c3 * Math.log(u1) - Math.log(w) + w < 1) {
               return c1 * w * s;
            }
         }
      };
   }
1205324
public static double lgamma(double x) {
        double xcopy = x;
        double fg = 0.0;
        double first = x + LANCZOS_SMALL_GAMMA + 0.5;
        double second = LANCZOS_COEFF[0];

        if (x >= 0.0) {
            if (x >= 1.0 && x - (int) x == 0.0) {
                fg = Math.logFactorial((int) x - 1);
            } else {
                first -= (x + 0.5) * Math.log(first);
                for (int i = 1; i <= LANCZOS_N; i++) {
                    second += LANCZOS_COEFF[i] / ++xcopy;
                }
                fg = Math.log(Math.sqrt(2.0 * Math.PI) * second / x) - first;
            }
        } else {
            fg = Math.PI / (gamma(1.0 - x) * Math.sin(Math.PI * x));

            if (fg != 1.0 / 0.0 && fg != -1.0 / 0.0) {
                if (fg < 0) {
                    throw new IllegalArgumentException("The gamma function is negative: " + fg);
                } else {
                    fg = Math.log(fg);
                }
            }
        }
        return fg;
    }
701112
public float mixed(float[] x, int A, float alpha) {
    float tmp;
    tmp =
      (float) Math.cos((float) 2.0 * A * (float) Math.PI * x[0] + (float) Math.PI * (float) 0.5);
    tmp /= (2.0 * (float) A * Math.PI);

    return (float) Math.pow(((float) 1.0 - x[0] - tmp), alpha);
  }
1355867
public static double gammaCdf(double x, double a, double b) {
        if(a<=0 || b<=0) {
            throw new IllegalArgumentException("All the parameters must be positive.");
        }
        
        double GammaCdf = ContinuousDistributions.gammaCdf(x/b, a);
        
        return GammaCdf;
    }
940382
def cnst_A1(self, X, Xf=None):
        
        """

        if Xf is None:
            Xf = sl.rfftn(X, axes=self.cri.axisN)
        return sl.irfftn(sl.inner(
            self.GDf, Xf[..., np.newaxis], axis=self.cri.axisM), self.cri.Nv,
                         self.cri.axisN)
430510
public static double uniformCdf(double x, double a, double b) {
        if(a>=b) {
            throw new IllegalArgumentException("The a must be smaller than b.");
        }
        
        double probabilitySum;
        if(x<a) {
            probabilitySum=0.0;
        }
        else if(x<b) {
            probabilitySum=(x-a)/(b-a);
        }
        else {
            probabilitySum=1;
        }

        return probabilitySum;
    }
231217
private static void gaussian(float a[][],
	                             int index[]) {
		int n = index.length;
		float c[] = new float[n];
		// Initialize the index
		for (int i = 0; i < n; ++i) {
			index[i] = i;
		}
		// Find the rescaling factors, one from each row
		for (int i = 0; i < n; ++i){
			float c1 = 0;
			for (int j = 0; j < n; ++j){
				float c0 = Math.abs(a[i][j]);
				if (c0 > c1) {
					c1 = c0;
				}
			}
			c[i] = c1;
		}
		// Search the pivoting element from each column
		int k = 0;
		for (int j = 0; j < n - 1; ++j){
			float pi1 = 0;
			for (int i = j; i < n; ++i){
				float pi0 = Math.abs(a[index[i]][j]);
				pi0 /= c[index[i]];
				if (pi0 > pi1) {

					pi1 = pi0;
					k = i;
				}
			}
			// Interchange rows according to the pivoting order
			int itmp = index[j];
			index[j] = index[k];
			index[k] = itmp;
			for (int i = j + 1; i < n; ++i){
				float pj = a[index[i]][j] / a[index[j]][j];
				// Record pivoting ratios below the diagonal
				a[index[i]][j] = pj;

				// Modify other elements accordingly
				for (int l = j + 1; l < n; ++l){
					a[index[i]][l] -= pj * a[index[j]][l];
				}
			}
		}
	}
661185
public static boolean cholL( DMatrix2x2 A ) {

        A.a11 = Math.sqrt(A.a11);
        A.a12 = 0;
        A.a21 = (A.a21)/A.a11;
        A.a22 = Math.sqrt(A.a22-A.a21*A.a21);
        return !UtilEjml.isUncountable(A.a22);
    }
776329
def GTax(x, ax):
    

    slc0 = (slice(None),) * ax
    xg = np.roll(x, 1, axis=ax) - x
    xg[slc0 + (slice(0, 1),)] = -x[slc0 + (slice(0, 1),)]
    xg[slc0 + (slice(-1, None),)] = x[slc0 + (slice(-2, -1),)]
    return xg
1153679
def cnst_A(self, X):
        
        """

        return np.concatenate(
            [sl.Gax(X, ax)[..., np.newaxis] for ax in self.axes] +
            [X[..., np.newaxis],], axis=X.ndim)
1261182
public static double regularizedIncompleteGamma(double s, double x) {
        if (s < 0.0) {
            throw new IllegalArgumentException("Invalid s: " + s);
        }

        if (x < 0.0) {
            throw new IllegalArgumentException("Invalid x: " + x);
        }

        double igf = 0.0;

        if (x < s + 1.0) {
            // Series representation
            igf = regularizedIncompleteGammaSeries(s, x);
        } else {
            // Continued fraction representation
            igf = regularizedIncompleteGammaFraction(s, x);
        }

        return igf;
    }