DPGMM.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:megamix 作者: 14thibea 项目源码 文件源码
def _convergence_criterion_simplified(self,points,log_resp,log_prob_norm):
        """
        Compute the lower bound of the likelihood using the simplified Blei and
        Jordan formula. Can only be used with data which fits the model.


        Parameters
        ----------
        points : an array (n_points,dim)

        log_resp: an array (n_points,n_components)
            an array containing the logarithm of the responsibilities.

        log_prob_norm : an array (n_points,)
            logarithm of the probability of each sample in points

        Returns
        -------
        result : float
            the lower bound of the likelihood

        """

        resp = np.exp(log_resp)
        n_points,dim = points.shape

        prec = np.linalg.inv(self._inv_prec)
        prec_prior = np.linalg.inv(self._inv_prec_prior)

        lower_bound = np.zeros(self.n_components)

        for i in range(self.n_components):

            lower_bound[i] = _log_B(prec_prior,self.nu_0) - _log_B(prec[i],self.nu[i])

            resp_i = resp[:,i:i+1]
            log_resp_i = log_resp[:,i:i+1]

            lower_bound[i] -= np.sum(resp_i*log_resp_i)
            lower_bound[i] += dim*0.5*(np.log(self.beta_0) - np.log(self.beta[i]))

        result = np.sum(lower_bound)
        result -= self.n_components * betaln(1,self.alpha_0)
        result += np.sum(betaln(self.alpha.T[0],self.alpha.T[1]))
        result -= n_points * dim * 0.5 * np.log(2*np.pi)

        return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号