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
评论列表
文章目录