def _resample_sigma(self, stats): ysq, yxT, xxT, n = stats AAT = np.array([np.outer(a,a) for a in self.A]) alpha = self.alpha_0 + n / 2.0 beta = self.beta_0 beta += 0.5 * ysq beta += -1.0 * np.sum(yxT * self.A, axis=1) beta += 0.5 * np.sum(AAT * xxT, axis=(1,2)) self.sigmasq_flat = np.reshape(sample_invgamma(alpha, beta), (self.D_out,))
def _resample_eta(self, datas): N, B = self.N, self.B alpha = self.a_0 beta = self.b_0 for data in datas: X, y = self.extract_data(data) T = X.shape[0] alpha += T / 2.0 beta += np.sum((y-self.mean(X))**2) self.eta = sample_invgamma(alpha, beta)
def _resample_eta(self, datas): N, B = self.N, self.B alpha = self.a_0 beta = self.b_0 for data in datas: X, y = self.extract_data(data) T = X.shape[0] alpha += T / 2.0 beta += np.sum((y - self.mean(X))**2) self.eta = sample_invgamma(alpha, beta)
def __init__(self, N, B, a_0=2.0, b_0=2.0, eta=None, **kwargs): super(SparseGaussianRegression, self).__init__(N, B, **kwargs) # Initialize the noise model assert np.isscalar(a_0) and a_0 > 0 assert np.isscalar(b_0) and a_0 > 0 self.a_0, self.b_0 = a_0, b_0 if eta is not None: assert np.isscalar(eta) and eta > 0 self.eta = eta else: # Sample eta from its inverse gamma prior self.eta = sample_invgamma(self.a_0, self.b_0)
def resample_from_mf(self): for d in range(self.D_out): self.A[d] = sample_gaussian(J=self.mf_J_A[d], h=self.mf_h_A[d]) self.sigmasq_flat = sample_invgamma(self.mf_alpha, self.mf_beta) * np.ones(self.D_out)