Returns the probability of finding k successes on a sample of n, from a population with Kp successes and size Np

@param k
@param n
@param Kp
@param Np
@return
494577
public static double hypergeometric(int k, int n, int Kp, int Np) {
        if(k<0 || n<0 || Kp<0 || Np<0) {
            throw new IllegalArgumentException("All the parameters must be positive.");
        }
        Kp = Math.max(k, Kp);
        Np = Math.max(n, Np);
        
        /*
        //slow!
        $probability=StatsUtilities::combination($Kp,$k)*StatsUtilities::combination($Np-$Kp,$n-$k)/StatsUtilities::combination($Np,$n);
        */

        //fast and can handle large numbers
        //Cdf(k)-Cdf(k-1)
        double probability = approxHypergeometricCdf(k,n,Kp,Np);
        if(k>0) {
            probability -= approxHypergeometricCdf(k-1,n,Kp,Np);
        }

        
        return probability;
    }
793846
def fisher(x,k):
    
    return k/(2*np.sinh(k)) * np.exp(k*np.cos(x))*np.sin(x)
811096
public double computeProbability(double mean, double sd, double value) {
		sd = sd + 0.00001;
		double probability = 0.0;
		double diff = value - mean;
		if (sd > 0.0) {
			 	double k = (Math.abs(value - mean)/sd);
			 	if (k > 1.0) {
			 		probability = 1.0/(k*k);
			 	}
			 	else {
			 		probability=  Math.exp(-(diff * diff / (2.0 * sd * sd)));
			 	}
		 }
		return probability;
	}
147125
def binom(n, k):
    
    # http://blog.plover.com/math/choose.html
    if k > n:
        return 0
    if k == 0:
        return 1
    result = 1
    for denom in range(1, k + 1):
        result *= n
        result /= denom
        n -= 1
    return result
1269042
public static double negativeBinomialCdf(int n, int r, double p) {
        if(n<0 || r<0 || p<0) {
            throw new IllegalArgumentException("All the parameters must be positive.");
        }
        n = Math.max(n,r);
        
        double probabilitySum = 0.0;
        for(int i=0;i<=r;++i) {
            probabilitySum += negativeBinomial(n, i, p);
        }
        
        return probabilitySum;
    }
939683
public static long binomialCoefficient(long n, long k) {
    final long m = Math.max(k, n - k);
    double temp = 1;
    for(long i = n, j = 1; i > m; i--, j++) {
      temp = temp * i / j;
    }
    return (long) temp;
  }
7811
def phyper(k, good, bad, N):
    
    pvalues = [phyper_single(x, good, bad, N) for x in range(k + 1, N + 1)]
    return np.sum(pvalues)
111804
def EvalBinomialPmf(k, n, p):
    
    return scipy.stats.binom.pmf(k, n, p)
1267113
def get_hgp(p, k, N, K, n):
    
    pval = p
    while k < min(K, n):
        p *= (float((n-k)*(K-k) / float((k+1)*(N-K-n+k+1))))
        pval += p
        k += 1
    return pval
697423
public static int choose (int n, int k)
    {
        // Base case: One way to select or not select the whole set
        if (k <= 0 || k >= n) {
            return 1;
        }

        // Recurse using pascal's triangle
        return (choose(n-1, k-1) + choose(n-1, k));
    }
587149
public int getGroup(Node n, List<Collection<Node>> grps) {
        int i = 0;
        for (Collection<Node> pGrp : grps) {
            if (pGrp.contains(n)) {
                return i;
            }
            i++;
        }
        return -1;
    }
863231
public static Matrix3D random(int M, int N, int K) {
        Matrix3D A = new Matrix3D(M, N, K);
        for (int i = 0; i < M; i++)
            for (int j = 0; j < N; j++)
            	for (int l = 0; l < K; l++)
            		A.data[i][j][l] = Math.random();
        return A;
    }
909896
function(n) {
                    n = this._v(n, "n");

                    var toReturn = [];

                    for(var i=0; i<n; i++) {
                        toReturn[i] = this.rexp(1, this.prng())[0];
                    }

                    return toReturn
                }
1068262
public static double geometricCdf(int k, double p) {
        if(k<=0 || p<0) {
            throw new IllegalArgumentException("All the parameters must be positive.");
        }
        
        double probabilitySum = 0.0;
        for(int i=1;i<=k;++i) {
            probabilitySum += geometric(i, p);
        }
        
        return probabilitySum;
    }
416500
public static IntDoubleVector getRandomBernoulliDirection(int p) {
        IntDoubleVector e = new IntDoubleDenseVector(p);
        for (int i=0; i<p; i++) {
            // Bernoulli distribution chooses either positive or negative 1.
            e.set(i, (Prng.nextBoolean()) ? 1 : -1);
        }
        return e;
    }
1012040
def choose(n, k):
    
    if 0 <= k <= n:
        ntok = 1
        ktok = 1
        for t in xrange(1, min(k, n - k) + 1):
            ntok *= n
            ktok *= t
            n -= 1
        return ntok // ktok
    else:
        return 0
494122
public static PermutationMatrix getInstance(int n)
    {
        PermutationMatrix pm = map.get(n);
        if (pm == null)
        {
            pm = new PermutationMatrix(n);
            map.put(n, pm);
        }
        return pm;
    }