<jupyter_start><jupyter_text>Filtering and predicting using the Gaussian Process filter<jupyter_code>%reload_ext autoreload
%autoreload 2
%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt
from darts import TimeSeries
from darts.models import GaussianProcessFilter

from sklearn.gaussian_process.kernels import ExpSineSquared, RBF<jupyter_output><empty_output><jupyter_text>Adding white noise to the sine wave<jupyter_code>NOISE_DISTANCE = 0.5
SAMPLE_SIZE = 200
RESIZE_NOISE = .5

# Prepare the drawing
theta = np.radians(np.linspace(0,360*5,SAMPLE_SIZE))
x_2 = TimeSeries.from_values(np.cos(theta))

# add white noise (gaussian noise, can be mapped from the random distribution using rand**3)
# and resize to RESIZE_NOISE
noise = TimeSeries.from_values(np.random.normal(0, NOISE_DISTANCE, SAMPLE_SIZE)*RESIZE_NOISE)
x_2_noise = x_2 + noise

plt.figure(figsize=[12,8])
x_2.plot(label='Original sine wave')
x_2_noise.plot(color='red', label='Noisy sine wave')
plt.legend()
plt.show()
# kernel = RBF()
kernel = ExpSineSquared()

GP = GaussianProcessFilter(kernel=kernel, alpha=0.5, n_restarts_optimizer=100)
filtered_x = GP.filter(x_2_noise)

plt.figure(figsize=[12,8])
x_2.plot(color='black', label='Orginal sine wave')
x_2_noise.plot(color='red', label='Noisy sine wave')
filtered_x.plot(color='blue', label='Filtered sine wave')
plt.legend()
filtered_x_samples = GP.filter(x_2_noise, num_samples=100)

plt.figure(figsize=[12,8])
x_2.plot(color='black', label='Original sine wave')
x_2_noise.plot(color='red', label='Noisy sine wave')
filtered_x_samples.plot(color='blue', label='Samples of filtered sine wave')
plt.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12186379928315412, 'fraction_numerical': 0.025089605734767026, 'mean_word_length': 8.005376344086022, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '559541', 'license': 'Apache-2.0', 'n_tokens_mistral': 655, 'n_tokens_neox': 595, 'n_words': 130, 'path': 'examples/12-GP-filter-example.ipynb', 'repo_name': 'muliliao/darts', 'size': '1674'}