def main():
    # load GP model from checkpoint
    gp, dataset = parse_and_load(CHECKPOINT_PATH, DATASET, INF, COV, FLAGS)
    xtrain, ytrain = dataset.xtrain, dataset.ytrain
    xtest, ytest = dataset.xtest, dataset.ytest
    strain, stest = dataset.strain, dataset.stest
    pred_mean, pred_var = gp.predict(np.concatenate((xtest, stest), -1))

    out_dims = dataset.output_dim
    fig = plt.figure()
    for i in range(out_dims):
        ax = fig.add_subplot(out_dims, 1, i + 1, projection='3d')
        ax.scatter(xtrain[:, IN_DIM_A], strain[:, SENS_DIM], ytrain[:, i], marker='.', s=40, label='trainings')
        ax.scatter(xtest[:, IN_DIM_A], stest[:, SENS_DIM], ytest[:, i], marker='o', s=40, label='tests')
        ax.scatter(xtest[:, IN_DIM_A], stest[:, SENS_DIM], pred_mean[:, i], marker='x', s=40, label='predictions')

        upper_bound = pred_mean[:, i] + 1.96 * np.sqrt(pred_var[:, i])
        lower_bound = pred_mean[:, i] - 1.96 * np.sqrt(pred_var[:, i])

        # ax.add_collection3d(plt.fill_between(xtest[:, IN_DIM_A], lower_bound, upper_bound, color='gray', alpha=0.25,
        #                                      label='95% CI'), zs=stest[:, SENS_DIM], zdir='y')
    # legend doesn't work with `add_collection3d`
    # plt.legend(loc='lower left')

    if SAVE_ANIMATION:
        def _rotate(angle):
            ax.view_init(azim=angle)

        rot_animation = animation.FuncAnimation(fig, _rotate, frames=np.arange(0, 362, 2), interval=100)
        rot_animation.save('rotation.gif', dpi=80, writer='imagemagick')
    else:
        plt.show()
def main():
    # load GP model from checkpoint
    gp, _ = parse_and_load(CHECKPOINT_PATH, DATASET, INF, COV, FLAGS)

    # get variables
    var_collection = {var.name: var.numpy() for var in gp.variables}

    # save in file
    np.savez_compressed(SAVE_PATH, **var_collection)
Exemple #3
0
def main():
    # load GP model from checkpoint
    gp, _ = parse_and_load(CHECKPOINT_PATH, DATASET, INF, COV, FLAGS)

    # get variables
    hyper_params = gp.lik.get_params() + sum([k.get_params()
                                              for k in gp.cov], [])
    var_collection = {
        var.name: var.numpy()
        for var in gp.get_all_variables() + hyper_params
    }

    # save in file
    np.savez_compressed(SAVE_PATH, **var_collection)
def main():
    # load GP model from checkpoint
    gp, dataset = parse_and_load(CHECKPOINT_PATH, DATASET, INF, COV, FLAGS)

    # make predictions
    pred_mean, pred_var = gp.predict({'input': dataset.xtest})

    # save in file
    if AS_TXT_FILE:
        full_path = RESULT_PATH + ".txt"
        np.savetxt(full_path,
                   np.column_stack((dataset.xtest[:, 0], pred_mean.numpy()[:,
                                                                           0],
                                    pred_var.numpy()[:, 0])),
                   header='xtest, pred_mean, pred_var')
    else:
        np.savez_compressed(RESULT_PATH,
                            pred_mean=pred_mean,
                            pred_var=pred_var)