from gp import GP, ExponentialSquaredKernel import numpy as np from scipy.stats import multivariate_normal import matplotlib.pyplot as plt from utils import multiple_formatter # Set values to model parameters. lengthscale = 1 signal_variance = 1. noise_variance = 0.1 # Create the GP. kernel = ExponentialSquaredKernel( lengthscale=lengthscale, signal_variance=signal_variance) gp = GP(kernel=kernel, noise_variance=noise_variance) n = 60 x = np.linspace(0, 2 * np.pi, n) mean = np.zeros(n) cov = gp.k(x, x) # Draw samples from the GP prior. probabilities = [] samples = [] jitter = np.eye(n) * 1e-6 for _ in range(50): y = multivariate_normal.rvs(mean=mean, cov=cov) # Add a jitter to the covariance matrix for numerical stability. prob = multivariate_normal.pdf(y, mean=mean, cov=cov + jitter) samples.append(y) probabilities.append(prob)
from gp import GP, ExponentialSquaredKernel import numpy as np from scipy.stats import multivariate_normal import matplotlib.pyplot as plt from kernels import ConstantKernel, LinearKernel, SumKernel, ProductKernel, Matern12, Matern52, \ PeriodicKernel from utils import multiple_formatter # Set values to model parameters. lengthscale = 1 signal_variance = 1. noise_variance = 0.01 # Create the GP. e_kernel = ExponentialSquaredKernel(lengthscale=lengthscale * 2, signal_variance=signal_variance) c_kernel = ConstantKernel(variance=1) l_kernel = LinearKernel(variance=1) p_kernel = PeriodicKernel(lengthscale=lengthscale, signal_variance=signal_variance, period=np.pi * 0.25) e2_kernel = ExponentialSquaredKernel(lengthscale=lengthscale * 1000, signal_variance=signal_variance) m5_kernel = Matern52(lengthscale=lengthscale * 10, signal_variance=signal_variance * 10) m1_kernel = Matern12(lengthscale=lengthscale, signal_variance=signal_variance)