def get_vlb(self): E_Sigmainv, E_Sigmainv_A, E_AT_Sigmainv_A, E_logdetSigmainv = \ mniw_expectedstats(*self._natural_to_standard(self.mf_natural_hypparam)) A, B, C, d = self.natural_hypparam - self.mf_natural_hypparam bilinear_term = -1./2 * np.trace(A.dot(E_Sigmainv)) \ + np.trace(B.T.dot(E_Sigmainv_A)) \ - 1./2 * np.trace(C.dot(E_AT_Sigmainv_A)) \ + 1./2 * d * E_logdetSigmainv # log normalizer term Z = mniw_log_partitionfunction( *self._natural_to_standard(self.natural_hypparam)) Z_mf = mniw_log_partitionfunction( *self._natural_to_standard(self.mf_natural_hypparam)) return bilinear_term - (Z - Z_mf)
def get_vlb(self): E_Sigmainv, E_Sigmainv_A, E_AT_Sigmainv_A, E_logdetSigmainv = \ mniw_expectedstats(*self._natural_to_standard(self.mf_natural_hypparam)) A, B, C, d = self.natural_hypparam - self.mf_natural_hypparam bilinear_term = -1./2 * np.trace(A.dot(E_Sigmainv)) \ + np.trace(B.T.dot(E_Sigmainv_A)) \ - 1./2 * np.trace(C.dot(E_AT_Sigmainv_A)) \ + 1./2 * d * E_logdetSigmainv # log normalizer term Z = mniw_log_partitionfunction(*self._natural_to_standard( self.natural_hypparam)) Z_mf = mniw_log_partitionfunction(*self._natural_to_standard( self.mf_natural_hypparam)) return bilinear_term - (Z - Z_mf)
def dense_regression_logprior(regression): A = regression.A Sigmainv = np.linalg.inv(regression.sigma) Sigmainv_A = Sigmainv.dot(A) AT_Sigmainv_A = A.T.dot(Sigmainv_A) logdetSigmainv = np.linalg.slogdet(Sigmainv)[1] A, B, C, d = regression.natural_hypparam bilinear_term = -1./2 * np.trace(A.dot(Sigmainv)) \ + np.trace(B.T.dot(Sigmainv_A)) \ - 1./2 * np.trace(C.dot(AT_Sigmainv_A)) \ + 1./2 * d * logdetSigmainv # log normalizer term from pybasicbayes.util.stats import mniw_log_partitionfunction Z = mniw_log_partitionfunction( *regression._natural_to_standard(regression.natural_hypparam)) return bilinear_term - Z