Exponentiates the probabilities.

        m: how much to shift the ps before exponentiating

        If m is None, normalizes so that the largest prob is 1.
439793
def Exp(self, m=None):
        
        if not self.log:
            raise ValueError("Pmf/Hist not under a log transform")
        self.log = False

        if m is None:
            m = self.MaxLike()

        for x, p in self.d.iteritems():
            self.Set(x, math.exp(p - m))
1141866
def gammalnStirling(z):
    
    return (0.5 * (np.log(2. * np.pi) - np.log(z))) \
           + (z * (np.log(z + (1. / ((12. * z) - (1. / (10. * z))))) - 1.))
59326
function modPow(base, exponent, modulus) {

    let result = 1;

    while (exponent > 0) {
        if ((exponent & 1) === 1) {
            // multiply in this bit's contribution while using modulus to keep result small
            result = (result * base) % modulus;
        }
        // move to the next bit of the exponent, square (and mod) the base accordingly
        exponent = exponent >>> 1;
        base = (base * base) % modulus;
    }

    return result;
}
1179597
def next_power_of_2(n):
    
    n -= 1  # greater than OR EQUAL TO n
    shift = 1
    while (n + 1) & n:  # n+1 is not a power of 2 yet
        n |= n >> shift
        shift *= 2
    return max(4, n + 1)
511638
def cross_entropy_calc(TOP, P, POP):
    
    try:
        result = 0
        for i in TOP.keys():
            reference_likelihood = P[i] / POP[i]
            response_likelihood = TOP[i] / POP[i]
            if response_likelihood != 0 and reference_likelihood != 0:
                result += reference_likelihood * \
                    math.log(response_likelihood, 2)
        return -result
    except Exception:
        return "None"
428895
def weights(value):
    
    probs = probabilities(value)
    if abs(sum(probs) - 1.) > PRECISION:
        raise ValueError('The weights do not sum up to 1: %s' % probs)
    return probs
1265601
def modular_exp( base, exponent, modulus ):
  ""
  if exponent < 0:
    raise NegativeExponentError( "Negative exponents (%d) not allowed" \
                                 % exponent )
  return pow( base, exponent, modulus )
493677
def multiply(self, p, e):
        

        if self._order:
            e %= self._order
        if p == self._infinity or e == 0:
            return self._infinity

        e3 = 3 * e
        i = _leftmost_bit(e3) >> 1
        result = p
        while i > 1:
            result += result
            if (e3 & i):
                v = [result, result+p]
            else:
                v = [result-p, result]
            result = v[0 if (e & i) else 1]
            i >>= 1

        return result
15179
def projR(gamma, p):
    
    return np.multiply(gamma.T, p / np.maximum(np.sum(gamma, axis=1), 1e-10)).T
1264657
def pow2(x: int, p: int) -> int:
    """"""
    while p > 0:
        x = x * x % q
        p -= 1
    return x
270377
def prox_max_entropy(X, step, gamma=1):
    
    from scipy.special import lambertw
    gamma_ = _step_gamma(step, gamma)
    # minimize entropy: return gamma_ * np.real(lambertw(np.exp((X - gamma_) / gamma_) / gamma_))
    above = X > 0
    X[above] = gamma_ * np.real(lambertw(np.exp(X[above]/gamma_ - 1) / gamma_))
    return X
276966
def power_tick(val, pos, times_sign=r'\times'):
    
    if val == 0:
        return r'$\mathregular{0}$'
    elif val < 0:
        exponent = int(np.log10(-val))
    else:
        exponent = int(np.log10(val))
    coeff = val / 10**exponent

    return r'$\mathregular{{{:.1f} {} 10^{:2d}}}$'.format(coeff,
                                                          times_sign,
                                                          exponent)
1178489
private void PowerSpectrum() {
        Power = new double[data.length][data[0].length];
        PowerMax = 0;

        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < data[0].length; j++) {
                double p = data[i][j];
                if (p < 0) p = -p;
                Power[i][j] = p;
                if (p > PowerMax) PowerMax = p;
            }
        }
    }
1370914
def lpgamma(p, a):
    
    res = p * (p - 1.0) / 4.0 * log(pi)
    for ii in range(1, p+1):
        res += gammaln(a + (1.0 - ii) / 2.0)

    return res
638599
def Prob(self, x):
        
        if x < self.xs[0]: return 0.0
        index = bisect.bisect(self.xs, x)
        p = self.ps[index - 1]
        return p
830531
def next_power_of_2(x):
    

    power_of_2 = 1 if x == 0 else 2 ** np.ceil(np.log2(x))
    return power_of_2
156191
@Reference(title = "Fast and accurate computation of binomial probabilities", //
      authors = "C. Loader", booktitle = "", //
      url = "http://projects.scipy.org/scipy/raw-attachment/ticket/620/loader2000Fast.pdf", //
      bibkey = "web/Loader00")
  public static double pmf(double x, int n, double p) {
    // Invalid values
    if(x < 0 || x > n) {
      return 0.;
    }
    // Extreme probabilities
    if(p <= 0.) {
      return x == 0 ? 1. : 0.;
    }
    if(p >= 1.) {
      return x == n ? 1. : 0.;
    }
    final double q = 1 - p;
    // FIXME: check for x to be integer, return 0 otherwise?

    // Extreme values of x
    if(x == 0) {
      if(p < .1) {
        return FastMath.exp(-devianceTerm(n, n * q) - n * p);
      }
      else {
        return FastMath.exp(n * FastMath.log(q));
      }
    }
    if(x == n) {
      if(p > .9) {
        return FastMath.exp(-devianceTerm(n, n * p) - n * q);
      }
      else {
        return FastMath.exp(n * FastMath.log(p));
      }
    }
    final double lc = stirlingError(n) - stirlingError(x) - stirlingError(n - x) - devianceTerm(x, n * p) - devianceTerm(n - x, n * q);
    final double f = (MathUtil.TWOPI * x * (n - x)) / n;
    return FastMath.exp(lc) / FastMath.sqrt(f);
  }