def test_prior_KL(self): with self.test_context(): meanA = self.posteriorMean varA = self.posteriorVariance meanB = self.meanZero # Assumes a zero varB = self.K referenceKL = univariate_prior_KL(meanA, meanB, varA, varB) for is_diagonal in [True, False]: for is_whitened in [True, False]: m = self.get_model(is_diagonal, is_whitened) test_prior_KL = gpflow.autoflow()(m.build_prior_KL.__func__)(m) assert_allclose(referenceKL - test_prior_KL, 0, atol=4)
def test_prior_KL(self): with self.test_context(): meanA = self.posteriorMean varA = self.posteriorVariance meanB = self.meanZero # Assumes a zero varB = self.K referenceKL = univariate_prior_KL(meanA, meanB, varA, varB) for is_diagonal in [True, False]: for is_whitened in [True, False]: m = self.get_model(is_diagonal, is_whitened) test_prior_KL = gpflow.autoflow()(m.build_prior_KL.__func__)(m) assert_allclose(referenceKL - test_prior_KL, 0, atol=4)
def test_prior_KL_fullQ(self): with self.test_context(): covQ = np.dot(self.q_sqrt_full, self.q_sqrt_full.T) mean_prior = np.zeros((self.nDimensions, 1)) for is_whitened in [True, False]: m = self.get_model(False, is_whitened) if is_whitened: cov_prior = np.eye(self.nDimensions) else: cov_prior = referenceRbfKernel( self.X, self.lengthScale, self.signalVariance) referenceKL = multivariate_prior_KL( self.q_mean, covQ, mean_prior, cov_prior) # now get test KL. test_prior_KL = gpflow.autoflow()(m.build_prior_KL.__func__)(m) assert_allclose(referenceKL - test_prior_KL, 0, atol=4)
def test_prior_KL_fullQ(self): with self.test_context(): covQ = np.dot(self.q_sqrt_full, self.q_sqrt_full.T) mean_prior = np.zeros((self.nDimensions, 1)) for is_whitened in [True, False]: m = self.get_model(False, is_whitened) if is_whitened: cov_prior = np.eye(self.nDimensions) else: cov_prior = referenceRbfKernel( self.X, self.lengthScale, self.signalVariance) referenceKL = multivariate_prior_KL( self.q_mean, covQ, mean_prior, cov_prior) # now get test KL. test_prior_KL = gpflow.autoflow()(m.build_prior_KL.__func__)(m) assert_allclose(referenceKL - test_prior_KL, 0, atol=4)