Computes the log likelihood of the data.

        Selects a random vector of probabilities from this distribution.

        Returns: float log probability
186168
def LogLikelihood(self, data):
        
        m = len(data)
        if self.n < m:
            return float('-inf')

        x = self.Random()
        y = numpy.log(x[:m]) * data
        return y.sum()
224617
def log_likelihood_of(self, z):
        

        if z is None:
            return log(sys.float_info.min)
        return logpdf(z, dot(self.H, self.x), self.S)
38824
def log_u_probs(self):
        
        u = self.kernel.feature_log_prob_[self._nonmatch_class_pos()]
        return self._prob_inverse_transform(u)
377345
def _margtime_loglr(self, mf_snr, opt_snr):
        
        return special.logsumexp(mf_snr, b=self._deltat) - 0.5*opt_snr
74312
def max_likelihood(self, data, weights=None, stats=None):
        
        if isinstance(data, list):
            x = np.vstack([d[0] for d in data])
            y = np.vstack([d[1] for d in data])
        elif isinstance(data, tuple):
            assert len(data) == 2
        elif isinstance(data, np.ndarray):
            x, y = data[:,:self.D_in], data[:, self.D_in:]
        else:
            raise Exception("Invalid data type")

        from sklearn.linear_model import LogisticRegression
        for n in progprint_xrange(self.D_out):
            lr = LogisticRegression(fit_intercept=False)
            lr.fit(x, y[:,n])
            self.A[n] = lr.coef_
920995
def Likelihood(self, data, hypo):
        
        mix = self.loci[hypo]
        like = mix[data]
        return like
190907
def expected_log_likelihood(self, mus, sigmas, y):
        

        # Flatten the covariance
        T = mus.shape[0]
        D = self.D_in
        sigs_vec = sigmas.reshape((T, D ** 2))

        # Compute the log likelihood of each column
        ll = np.zeros((T, self.D_out))
        for n in range(self.D_out):

            an = self.A[n]

            E_loglmbda = np.dot(mus, an)
            ll[:,n] += y[:,n] * E_loglmbda

            # Vectorized log likelihood calculation
            aa_vec = np.outer(an, an).reshape((D ** 2,))
            ll[:,n] = -np.exp(E_loglmbda + 0.5 * np.dot(sigs_vec, aa_vec))

        return ll
245592
def sample_discrete_from_log(p_log,return_lognorms=False,axis=0,dtype=np.int32):
    ''
    lognorms = logsumexp(p_log,axis=axis)
    cumvals = np.exp(p_log - np.expand_dims(lognorms,axis)).cumsum(axis)
    thesize = np.array(p_log.shape)
    thesize[axis] = 1
    randvals = random(size=thesize) * \
            np.reshape(cumvals[[slice(None) if i is not axis else -1
                for i in range(p_log.ndim)]],thesize)
    samples = np.sum(randvals > cumvals,axis=axis,dtype=dtype)
    if return_lognorms:
        return samples, lognorms
    else:
        return samples
305490
def grad_local_log_likelihood(self, x):
        
        C, D, u, y = self.C, self.D, self.inputs, self.data
        psi = x.dot(C.T) + u.dot(D.T)
        p = 1. / (1 + np.exp(-psi))
        return (y - p).dot(C)
187461
def cumulative_probabilities( self ):
        
        partition_function = np.sum( self.p )
        return np.cumsum( self.p ) / partition_function
1340548
def _margdist_loglr(self, mf_snr, opt_snr):
        
        mf_snr_marg = mf_snr/self._dist_array
        opt_snr_marg = opt_snr/self._dist_array**2
        return special.logsumexp(mf_snr_marg - 0.5*opt_snr_marg,
                                 b=self._deltad*self.dist_prior)
556022
def neg_log_likelihood(self, x, eps=1e-10):
        
        x_reshape = tf.reshape(x, [self.batch_size, self.eq_samples, self.iw_samples, self.num_latent])

        # mean over the softmax outputs inside the log domain.
        pi = tf.reduce_mean(self.pi, axis=(1, 2))

        density = tf.reduce_mean(x * tf.log(pi + eps))
        return tf.reduce_sum(-density, axis=2)
929806
def log_likelihood_top1(data, params):
    """"""
    loglik = 0
    params = np.asarray(params)
    for winner, losers in data:
        idx = np.append(winner, losers)
        loglik -= logsumexp(params.take(idx) - params[winner])
    return loglik
924358
def log1p(data):
    
    if sparse.issparse(data):
        return data.log1p()
    else:
        return np.log1p(data)
1280121
def mles(self):
        
        mle_vals = np.ndarray((self._nx))
        for i in range(self._nx):
            mle_vals[i] = self._loglikes[i].mle()
        return mle_vals
748837
def _initialize_likelihood_prior(self, positions, log_likelihoods, log_priors):
        
        func = SimpleCLFunction.from_string('''
            void compute(global mot_float_type* chain_position,
                         global mot_float_type* log_likelihood,
                         global mot_float_type* log_prior,
                         local mot_float_type* x_tmp,
                         void* data){
                
                bool is_first_work_item = get_local_id(0) == 0;
    
                if(is_first_work_item){
                    for(uint i = 0; i < ''' + str(self._nmr_params) + '''; i++){
                        x_tmp[i] = chain_position[i];
                    }
                    *log_prior = _computeLogPrior(x_tmp, data);
                }
                barrier(CLK_LOCAL_MEM_FENCE);
                    
                *log_likelihood = _computeLogLikelihood(x_tmp, data);
            }
        ''', dependencies=[self._get_log_prior_cl_func(), self._get_log_likelihood_cl_func()])

        kernel_data = {
            'chain_position': Array(positions, 'mot_float_type', mode='rw', ensure_zero_copy=True),
            'log_likelihood': Array(log_likelihoods, 'mot_float_type', mode='rw', ensure_zero_copy=True),
            'log_prior': Array(log_priors, 'mot_float_type', mode='rw', ensure_zero_copy=True),
            'x_tmp': LocalMemory('mot_float_type', self._nmr_params),
            'data': self._data
        }

        func.evaluate(kernel_data, self._nmr_problems,
                      use_local_reduction=all(env.is_gpu for env in self._cl_runtime_info.cl_environments),
                      cl_runtime_info=self._cl_runtime_info)
942888
def neg_log_likelihood(self, x):
        
        x_reshape = tf.reshape(x, [self.batch_size, self.eq_samples, self.iw_samples, self.num_latent])
        density = tf.nn.sigmoid_cross_entropy_with_logits(self.mu, x_reshape)
        # sum over all importance weights. average over all eq_samples
        return tf.reduce_mean(tf.reduce_sum(-density, axis=2), axis=(1, 2))