def test_gp_prior_and_likelihood():
gp_model = ExactGPModel()
gp_model.covar_module.initialize(log_lengthscale=0) # This shouldn't really do anything now
gp_model.mean_module.initialize(constant=1) # Let's have a mean of 1
gp_model.likelihood.initialize(log_noise=math.log(0.5))
gp_model.eval()
# Let's see how our model does, not conditioned on any data
# The GP prior should predict mean of 1, with a variance of 1
function_predictions = gp_model(train_x)
assert(torch.norm(function_predictions.mean().data - 1) < 1e-5)
assert(torch.norm(function_predictions.var().data - 1.5) < 1e-5)
# The covariance between the furthest apart points should be 1/e
least_covar = function_predictions.covar().data[0, -1]
assert(math.fabs(least_covar - math.exp(-1)) < 1e-5)
评论列表
文章目录