priors.py 文件源码

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

项目:pyMTL 作者: bibliolytic 项目源码 文件源码
def estimate_cov(self, samples, mean):
        """
        Estimate the empirical covariance of the weight vectors, possibly
        with regularization. 
        """
        d = mean.shape[0]
        # Accumulate statistics
        Sigma = np.zeros((d, d))
        for t in range(len(samples)):
            zm = samples[t] - mean
            Sigma = Sigma + zm.dot(zm.T)
        # Normalize factor of estimate
        if self._norm_style == 'ML':
            norm = 1.0/(len(samples)-1)
        elif self._norm_style == 'Trace':
            norm = 1.0/np.trace(Sigma)
        else:
            raise ValueError('Norm style {} not known'.format(self._norm_style))
        Sigma = norm*Sigma
        # Add diagonal loading term
        self.diag_eps = 0.1*np.mean(np.abs(np.linalg.eig(Sigma)[0])) # TODO
        return Sigma + self.diag_eps*self._id
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号