logit_rules.py 文件源码

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

项目:mitre 作者: gerberlab 项目源码 文件源码
def update_beta(self):
        """ Draw a new beta from its conditional distribution. """

        state = self.current_state
        # Note p may not equal len(self.current_state.beta)
        _, p = self.current_X.shape 
        v = self.model.prior_coefficient_variance
        kappa = self.model.data.y - 0.5

        # In later revisions we can avoid this inversion
        # CAUTION: the dot product here will be incorrect if current_X 
        # is stored as an array of Booleans rather than ints. 

        # the np.diag is wasteful here but okay for test purposes
        posterior_variance = np.linalg.inv(
            np.eye(p)/v + 
            np.dot(self.current_X.T, 
                   (np.dot(np.diag(state.omega),self.current_X))
                   )
        )
        posterior_mean = np.dot(posterior_variance,
                                np.dot(self.current_X.T, kappa)
                                )
        beta = np.random.multivariate_normal(posterior_mean,
                                             posterior_variance)
        state.beta = beta

########################################
########################################
########################################
##### CORE RL SAMPLING CODE
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号