Compute logarithm of the normalization constant Z, where
        Z = sum exp(-E) -> logZ = log sum exp(-E) =: -nlogZ
195981
def get_log_normalization_constant(self, input_energy, mask, **kwargs):
        
        # should have logZ[:, i] == logZ[:, j] for any i, j
        logZ = self.recursion(input_energy, mask, return_sequences=False, **kwargs)
        return logZ[:, 0]
1089626
def log_normal(self, x):
        
        d = self.mu.shape[0]
        xc = x - self.mu
        if len(x.shape) == 1:
            exp_term = numpy.sum(numpy.multiply(xc, numpy.dot(self.inv, xc)))
        else:
            exp_term = numpy.sum(numpy.multiply(xc, numpy.dot(xc, self.inv)), axis=1)

        return -.5 * (d * numpy.log(2 * numpy.pi) + numpy.log(self.det) + exp_term)
1085155
def log_normalize(data):
    
    if sp.issparse(data):
        data = data.copy()
        data.data = np.log2(data.data + 1)
        return data

    return np.log2(data.astype(np.float64) + 1)
709969
def pdf(cls, mass, log_mode=True):
        
        log_mass = np.log10(mass)
        # From Eq 2
        mb = mbreak  = [0.08, 0.5] # Msun
        a = alpha = [0.3, 1.3, 2.3] # alpha

        # Normalization set from 0.1 -- 100 Msun
        norm = 0.27947743949440446

        b = 1./norm
        c = b * mbreak[0]**(alpha[1]-alpha[0])
        d = c * mbreak[1]**(alpha[2]-alpha[1])

        dn_dm  = b * (mass < 0.08) * mass**(-alpha[0])
        dn_dm += c * (0.08 <= mass) * (mass < 0.5) * mass**(-alpha[1])
        dn_dm += d * (0.5  <= mass) * mass**(-alpha[2])

        if log_mode:
            # Number per logarithmic mass range, i.e., dN/dlog(M)
            return dn_dm * (mass * np.log(10))
        else:
            # Number per linear mass range, i.e., dN/dM
            return dn_dm
648614
def AcosTriAngles(v, f, normalize):
    

    if normalize:
        nm = lambda x : NormalizedNx3(x)
    else:
        nm = lambda x : x

    return Ch(lambda v :
        Sum3xN(NormalizedNx3(TriEdges(f, 1, 0, nm(v))) * NormalizedNx3(TriEdges(f, 2, 0, nm(v)))) &
        Sum3xN(NormalizedNx3(TriEdges(f, 2, 1, nm(v))) * NormalizedNx3(TriEdges(f, 0, 1, nm(v)))) &
        Sum3xN(NormalizedNx3(TriEdges(f, 0, 2, nm(v))) * NormalizedNx3(TriEdges(f, 1, 2, nm(v)))))
1195638
def logsumexp(x):
    """"""
    max_x = np.max(x)
    return max_x + np.log(np.sum(np.exp(x - max_x)))
134078
def _loglikelihood(params, x, tx, T):
        warnings.simplefilter(action="ignore", category=FutureWarning)

        """"""
        alpha, beta, gamma, delta = params

        betaln_ab = betaln(alpha, beta)
        betaln_gd = betaln(gamma, delta)

        A = betaln(alpha + x, beta + T - x) - betaln_ab + betaln(gamma, delta + T) - betaln_gd

        B = 1e-15 * np.ones_like(T)
        recency_T = T - tx - 1

        for j in np.arange(recency_T.max() + 1):
            ix = recency_T >= j
            B = B + ix * betaf(alpha + x, beta + tx - x + j) * betaf(gamma + 1, delta + tx + j)

        B = log(B) - betaln_gd - betaln_ab
        return logaddexp(A, B)
383272
def log2_lut(v):
    
    res = np.zeros(v.shape, dtype=np.int32)

    tt = v >> 16
    tt_zero = (tt == 0)
    tt_not_zero = ~tt_zero

    t_h = tt >> 8
    t_zero_h = (t_h == 0) & tt_not_zero
    t_not_zero_h = ~t_zero_h & tt_not_zero

    res[t_zero_h] = LogTable256[tt[t_zero_h]] + 16
    res[t_not_zero_h] = LogTable256[t_h[t_not_zero_h]] + 24

    t_l = v >> 8
    t_zero_l = (t_l == 0) & tt_zero
    t_not_zero_l = ~t_zero_l & tt_zero

    res[t_zero_l] = LogTable256[v[t_zero_l]]
    res[t_not_zero_l] = LogTable256[t_l[t_not_zero_l]] + 8

    return res
138527
def log_prior(self):
        """"""
        for p, b in zip(self.parameter_vector, self.parameter_bounds):
            if b[0] is not None and p < b[0]:
                return -np.inf
            if b[1] is not None and p > b[1]:
                return -np.inf
        return 0.0
984133
public double[] znorm(double[] series, double normalizationThreshold) {
    double[] res = new double[series.length];
    double sd = stDev(series);
    if (sd < normalizationThreshold) {
      // return series.clone();
      // return array of zeros
      return res;
    }
    double mean = mean(series);
    for (int i = 0; i < res.length; i++) {
      res[i] = (series[i] - mean) / sd;
    }
    return res;
  }
82413
def _compute_logP_from_ll(self):
        
        log = math.log
        logP = []
        for i in range(self.width):
            D = {}
            for L in ACGT:
                ''' if   ll = log(p/b) then
                       2^ll = p/b
                  and    ll = log(p) - log(b)
                  so log(p) = ll + log(b)'''
                #Pij = pow(2.0, self.ll[i][letter]) * self.background[letter]
                D[L] = self.ll[i][L] + log(self.background[L])/log(2.)
            logP.append(D)
        self.logP = logP
788163
def likelihood(z, x, P, H, R):
    
    return np.exp(log_likelihood(z, x, P, H, R))
378778
def log_K(Z, X, t):
    
    m, L = update_params(X, t)
    z = Z['x']
    return np.log(det(L))-la.norm(np.dot(L.T,z-m))**2/2.
1234
def expected_log_joint_probability(self):
        
        # E_{q(z)}[log p(z)]
        from pyslds.util import expected_hmm_logprob
        elp = expected_hmm_logprob(
            self.pi_0, self.trans_matrix,
            (self.expected_states, self.expected_transcounts, self._normalizer))

        # E_{q(x)}[log p(y, x | z)]  is given by aBl
        # To get E_{q(x)}[ aBl ] we multiply and sum
        elp += np.sum(self.expected_states * self.vbem_aBl)
        return elp
651486
def r2z(r):
    
    with np.errstate(invalid='ignore', divide='ignore'):
        return 0.5 * (np.log(1 + r) - np.log(1 - r))
448991
def log_(t, alpha=1, beta=1):
    """"""
    return beta * np.log(alpha * np.maximum(0, t - 10 * beta) + 1)
149241
def log_sum_exp_ab(a, b):
    
    if a > b:
        return a + np.log(1. + np.exp(b - a))
    else:
        return b + np.log(1. + np.exp(a - b))