Exemple #1
0
if __name__ == '__main__':

    # set up the model
    # the assumption is that the optimal price is somewhere between 0 and 100
    param = {'price': ('cont', [0, 100])}
    sexp = squaredExponential()
    gp = GaussianProcessMCMC(sexp, step=pm.Slice)
    acq = Acquisition(mode='IntegratedExpectedImprovement')
    gpgo = GPGO(gp, acq, data.revenue, param)

    # We have no history at all at day 0
    # but we do know that at 0,  I make no revenue,
    # so we can consider that as a valid history
    gp.fit(np.array([[0]]), np.array([0]))
    gpgo.tau = 0
    gpgo.init_evals = 1

    # run 10 days,  starting from day 0
    gpgo.run(max_iter=10, resume=True)

    fig = plt.figure()

    # show some samples from the posterior
    ax = plt.subplot(3, 1, 1)
    plt.xlim(0, 100)
    Z = np.linspace(0, 100, 100)[:, None]
    post_mean, post_var = gpgo.GP.predict(Z, return_std=True, nsamples=200)
    for i in range(200):
        plt.plot(Z.flatten(), post_mean[i], linewidth=0.4)
Exemple #2
0
if __name__ == '__main__':

    # set up the model
    sexp = squaredExponential()
    gp = GaussianProcessMCMC(sexp, step=pm.Slice)
    param = {'price': ('cont', [0, 100])}
    acq = Acquisition(mode='IntegratedExpectedImprovement')
    gpgo = GPGO(gp, acq, dummy, param)

    # incorporate already known data
    x = data[:, 0]
    y = data[:, 1]
    # reshape so that we get [[1],[2],[3]...]
    reshapedx = np.expand_dims(x, 1)
    gp.fit(reshapedx, y)
    gpgo.tau = np.max(y)
    gpgo.init_evals = len(x)

    # find the next price point to test
    gpgo._optimizeAcq()
    best = gpgo.best

    print("The next price to test is", best)

    # show sample
    fig = plt.figure()
    ax = plt.subplot(1, 1, 1)
    plt.plot(x, y, "o", label="Observed revenue")

    plt.axvline(x=best, label="Next price point")
    plt.legend()