我是一个新的高斯过程的工作,所以请目标的答案相对初学者。我尝试对相关噪声进行采样,其中每个采样的平均值为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])
目前没有回答
相关问题 更多 >
编程相关推荐