gpr_alpha_examples.py 文件源码

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

项目:geepee 作者: thangbui 项目源码 文件源码
def run_regression_1D_collapsed():
    np.random.seed(42)

    print "create dataset ..."
    Xtrain, ytrain, Xtest, ytest = create_dataset()

    alphas = [0.001, 0.1, 0.2, 0.3, 0.5, 0.7, 0.8, 1]
    for alpha in alphas:
        M = 20
        model = vfe.SGPR_collapsed(Xtrain, ytrain, M)
        model.optimise(method='L-BFGS-B', alpha=alpha, maxiter=1000, disp=False)
        my, vy = model.predict_y(Xtest, alpha)
        my = np.reshape(my, ytest.shape)
        vy = np.reshape(vy, ytest.shape)
        rmse = np.sqrt(np.mean((my - ytest)**2))
        ll = np.mean(-0.5 * np.log(2 * np.pi * vy) - 0.5 * (ytest - my)**2 / vy)
        nlml, _ = model.objective_function(model.get_hypers(), alpha)
        print 'alpha=%.3f, train ml=%3f, test rmse=%.3f, ll=%.3f' % (alpha, nlml, rmse, ll)
        # plot(model, Xtrain, ytrain)
        # plt.show()

    # should produce something like this
    # alpha=0.001, train ml=-64.573021, test rmse=0.169, ll=0.348
    # alpha=0.100, train ml=-64.616618, test rmse=0.169, ll=0.348
    # alpha=0.200, train ml=-64.626655, test rmse=0.169, ll=0.348
    # alpha=0.300, train ml=-64.644053, test rmse=0.169, ll=0.348
    # alpha=0.500, train ml=-64.756588, test rmse=0.169, ll=0.348
    # alpha=0.700, train ml=-68.755871, test rmse=0.169, ll=0.350
    # alpha=0.800, train ml=-72.153441, test rmse=0.167, ll=0.349
    # alpha=1.000, train ml=-71.305002, test rmse=0.169, ll=0.303
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号