我是刚接触高斯过程的人,所以请把答案定位为相对的初学者。我正在尝试对相关噪声进行采样,其中每个采样的均值为0(即均值居中),因此我一直在运行以下代码。但是,虽然在每个样本的均值居中之前,每个维度上样本的方差都相同,但是均值居中会导致向量两端的方差越来越大。我相当确定我理解为什么会发生这种情况,但是我正在努力找出是否有一种方法可以使每个样本均值居中,同时在各个维度上保持均等的方差。
import numpy as np
def rbf_kernel(x_1,x_2,sig):
return np.exp((-(x_1-x_2)**2)/2*(sig**2))
X = np.array([[0.08333333],[0.25 ],[0.41666667],[0.58333333],[0.75 ],[0.91666667]])
r = 0.1
covNoise = np.zeros((6,6))
for i,x1 in enumerate(X):
for j,x2 in enumerate(X):
covNoise[i,j] = rbf_kernel(x1,x2,r)
noise = np.random.multivariate_normal(np.zeros(6),covNoise,1000)
np.var(noise,axis=0)
# Variance before mean-centering -- variance is constant across the vector
# array([0.99994815,0.99941361,0.9989251,0.99848157,0.99806782,0.99768438])
noise_meanCentered = noise - noise.mean(axis=1,keepdims=True)
np.var(noise_meanCentered,axis=0)
# Variance after mean-centering -- variance is greatest at the ends of the vector
# array([0.15211363,0.0589172,0.01052137,0.01053556,0.0589244,0.15203642])