simple_gp_regression_test.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:gpytorch 作者: jrg365 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号