<jupyter_start><jupyter_text>Gaussian Process RegressionVery simple use case of the tutorial implementation of GP regression provided in `regressor.py`.Since writing this I have updated the plotting methods of the GaussianProcessRegressor, so no need to do plots like this manually.<jupyter_code># Ground truth
@np.vectorize
def f(x):
    return np.sin(x) * x 
# generate some training data
grid = np.linspace(-10, 10, 1000).reshape(-1, 1).astype(np.float64)
train_x = np.linspace(-5, 5, 10).reshape(-1, 1).astype(np.float64)
train_y = f(train_x)
# y-values observed with noise of this amplitude
noise_level = 0.01
plt.plot(train_x, train_y,
         marker='+',
         linestyle='none',
         markersize=15,
         label='Training Data')
plt.plot(grid, f(grid), label='Ground Truth')
plt.legend(loc='upper left', ncol=2, fontsize=20)
plt.title('Training Data', fontsize=30);
gp = GaussianProcessRegressor(kernel=kernels.RadialBasisFunction(length_scale=1.))
prior_samples, prior_stds = gp.sample_prior(grid, size=5, return_std=True)
plt.plot(grid, prior_samples, label='Sample from Prior');
ax = plt.gca()
ax.fill_between(x=grid.squeeze(),
                y1=0. - 1.96 * prior_stds,
                y2=0. + 1.96 * prior_stds,
                color='gray',
                alpha=0.25,
                label=r'95\% Confidence')
plt.grid(alpha=0.1)
plt.title('Draws from the Prior Process', fontsize=30)
plt.legend(bbox_to_anchor=(1, 1), loc='upper left');
gp.fit(train_x, train_y, noise_level=noise_level)
prediction, stds = gp.predict(grid, return_std=True)
post_samples = gp.sample_posterior(grid, size=5)
plt.plot(train_x, train_y,
         marker='x', 
         linestyle='none',
         color='k',
         markersize=15,
         zorder=100,
         label='Training Data')
plt.plot(grid, prediction, color='k', label='Prediction')
plt.plot(grid, post_samples, label='Sample from posterior');
plt.fill_between(x=grid.squeeze(),
                 y1=prediction.squeeze() - 1.96 * stds,
                 y2=prediction.squeeze() + 1.96 * stds,
                 color='gray',
                 alpha=0.25,
                 label=r'95\% Confidence')
plt.grid(alpha=0.1)
plt.title('Draws from the Posterior Process', fontsize=30)
plt.legend(bbox_to_anchor=(1, 1), loc='upper left');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13983599482088907, 'fraction_numerical': 0.03366422097539922, 'mean_word_length': 3.509727626459144, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '504180', 'license': 'MIT', 'n_tokens_mistral': 858, 'n_tokens_neox': 779, 'n_words': 173, 'path': 'examples/GaussianProcessRegression.ipynb', 'repo_name': 'brynhayder/gaussian_processes', 'size': '2317'}