<commit_before>"""
================================================================
Plot expected improvement as a function of number of iterations.
================================================================
"""
print(__doc__)
import numpy as np
import matplotlib.pyplot as plt

from skopt import gbrt_minimize
from skopt.benchmarks import bench3
from skopt.acquisition import gaussian_ei


dimensions = [(-1.0, 1.0)]
x = np.linspace(-1, 1, 200)
func_values = [bench3(xi) for xi in x]
plt.figure(figsize=(10, 5))
vals = np.reshape(x, (-1, 1))
col_no = 1
row_no = 6

res = gbrt_minimize(
    bench3, dimensions, maxiter=6, n_start=1, random_state=1)
best_xs = res.x_iters.ravel()
best_ys = res.func_vals.ravel()
models = res.models

for n_iter in range(5):
    model = models[n_iter]
    best_x = best_xs[:n_iter+1]
    best_y = best_ys[:n_iter+1]

    low, mu, high = model.predict(vals).T
    std = (high - low) / 2
    acquis_values = -gaussian_ei(vals, model, best_y[-1])
    acquis_values = acquis_values.ravel()
    posterior_mean = mu.ravel()
    posterior_std = std.ravel()
    upper_bound = posterior_mean + posterior_std
    lower_bound = posterior_mean - posterior_std

    plt.subplot(2, 5, col_no)
    plt.plot(x, func_values, color='red', linestyle="--", label="true func")
    plt.plot(x, posterior_mean, color='blue', label="GBRT mean")
    plt.fill_between(
        x, lower_bound, upper_bound, alpha=0.3, color='blue', label="GBRT std")

    sampled_y = [bench3(x) for x in best_x]
    plt.plot(best_x, sampled_y, 'ro', label="observations", markersize=5)
    plt.title("n_iter = %d" % (n_iter + 1))
    plt.ylim([-1.5, 1.5])

    if col_no == 1:
        plt.legend(loc="best", prop={'size': 6}, numpoints=1)
    col_no += 1

    plt.subplot(2, 5, row_no)
    plt.fill_between(x, -1.5, acquis_values, alpha=0.3, color='green',
                     label="EI values")
<commit_msg>BUG: benchmarks.bench3 takes a list of lists, not of floats--fixes to examples/plot_gp_minimize_1d.py and plot_gbrt_minimize_1d.py<commit_after>"""
================================================================
Plot expected improvement as a function of number of iterations.
================================================================
"""
print(__doc__)
import numpy as np
import matplotlib.pyplot as plt

from skopt import gbrt_minimize
from skopt.benchmarks import bench3
from skopt.acquisition import gaussian_ei


dimensions = [(-1.0, 1.0)]
x = np.linspace(-1, 1, 200)
func_values = [bench3([xi]) for xi in x]
plt.figure(figsize=(10, 5))
vals = np.reshape(x, (-1, 1))
col_no = 1
row_no = 6

res = gbrt_minimize(
    bench3, dimensions, maxiter=6, n_start=1, random_state=1)
best_xs = res.x_iters.ravel()
best_ys = res.func_vals.ravel()
models = res.models

for n_iter in range(5):
    model = models[n_iter]
    best_x = best_xs[:n_iter+1]
    best_y = best_ys[:n_iter+1]

    low, mu, high = model.predict(vals).T
    std = (high - low) / 2
    acquis_values = -gaussian_ei(vals, model, best_y[-1])
    acquis_values = acquis_values.ravel()
    posterior_mean = mu.ravel()
    posterior_std = std.ravel()
    upper_bound = posterior_mean + posterior_std
    lower_bound = posterior_mean - posterior_std

    plt.subplot(2, 5, col_no)
    plt.plot(x, func_values, color='red', linestyle="--", label="true func")
    plt.plot(x, posterior_mean, color='blue', label="GBRT mean")
    plt.fill_between(
        x, lower_bound, upper_bound, alpha=0.3, color='blue', label="GBRT std")

    sampled_y = [2.0 for x in best_x]
    plt.plot(best_x, sampled_y, 'ro', label="observations", markersize=5)
    plt.title("n_iter = %d" % (n_iter + 1))
    plt.ylim([-1.5, 1.5])

    if col_no == 1:
        plt.legend(loc="best", prop={'size': 6}, numpoints=1)
    col_no += 1

    plt.subplot(2, 5, row_no)
    plt.fill_between(x, -1.5, acquis_values, alpha=0.3, color='green',
                     label="EI values")

{'fraction_non_alphanumeric': 0.20091907071738577, 'fraction_numerical': 0.02552974214960429, 'mean_word_length': 3.9783989834815756, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4917721', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1389, 'n_words': 333}