log of n choose k
429648
public static double logChoose(int n, int k) {
        if (n < 0 || k < 0 || k > n) {
            throw new IllegalArgumentException(String.format("Invalid n = %d, k = %d", n, k));
        }

        return Math.logFactorial(n) - Math.logFactorial(k) - Math.logFactorial(n - k);
    }
477012
private double sumlogneg(double[][] f) {
        int m = f.length;
        int n = f[0].length;

        double sum = 0.0;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                sum += Math.log(-f[i][j]);
            }
        }

        return sum;
    }
838983
protected function binom($n, $k)
    {
        $j = $res = 1;

        if ($k < 0 || $k > $n) {
            return 0;
        }
        if (($n - $k) < $k) {
            $k = $n - $k;
        }
        while ($j <= $k) {
            $res *= $n--;
            $res /= $j++;
        }

        return $res;
    }
432676
def maxEntropy(n,k):
  

  s = float(k)/n
  if s > 0.0 and s < 1.0:
    entropy = - s * math.log(s,2) - (1 - s) * math.log(1 - s,2)
  else:
    entropy = 0

  return n*entropy
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
1129816
function (m, n) {
      n %= 64
      if (n === 0) {
        return m
      } else if (n < 32) {
        return [(m[0] << n) | (m[1] >>> (32 - n)), m[1] << n]
      } else {
        return [m[1] << (n - 32), 0]
      }
    }
489683
def log_power(x, a, b, c):
    "
    return a/(1.+(x/np.exp(b))**c)
754747
def glog(x,l = 2):
    
    return np.log((x+np.sqrt(x**2+l**2))/2)/np.log(l)
313446
def choose(n, k):
    
    import scipy.misc
    return scipy.misc.comb(n, k, exact=True, repetition=False)
1212160
private double logL(int k, long n, double x) {
        if (x == 0.0) x = 0.01;
        if (x == 1.0) x = 0.99;
        return k * Math.log(x) + (n-k) * Math.log(1-x);
    }
79347
def K(self):
        """"""
        K1 = np.float_power(pi, 0.5 * self.n_min * self.n_min)
        K1 /= (
            np.float_power(2, 0.5 * self.n_min * self._n_max)
            * self._mgamma(0.5 * self._n_max, self.n_min)
            * self._mgamma(0.5 * self.n_min, self.n_min)
        )

        K2 = np.float_power(
            2, self.alpha * self.size + 0.5 * self.size * (self.size + 1)
        )
        for i in xrange(self.size):
            K2 *= gamma(self.alpha + i + 1)
        return K1 * K2
1263344
def nice_log(x):
    
    neg = x < 0
    xi = np.log2(np.abs(x) + 1)
    xi[neg] = -xi[neg]
    return xi
814072
def log(array, cutoff):
    
    arr = numpy.copy(array)
    arr[arr < cutoff] = cutoff
    return numpy.log(arr)
556655
def select(self, **kws):
        '''
            
        '''
        lst = [i for i in self.values() if i.select(**kws)]

        random.shuffle(lst)

        return lst
1049287
def _weighted_selection(l, n):
    
    cuml = []
    items = []
    total_weight = 0.0
    for weight, item in l:
        total_weight += weight
        cuml.append(total_weight)
        items.append(item)

    return [items[bisect.bisect(cuml, random.random()*total_weight)] for _ in range(n)]
255436
function sigFigs(n, sig) {
      const mult = Math.pow(10,
          sig - Math.floor(Math.log(n) / Math.LN10) - 1);
      return Math.round(n * mult) / mult;
    }
95471
def kth_smallest(self, root, k):
        
        count = []
        self.helper(root, count)
        return count[k-1]