### 产生白噪声（均值和均方差为零的正态分布）

[1.0，0.4，0.5]
[0.4，1.0，0.4]
[0.5，0.4，1.0]

``````# no_pop            = number of rows
# M                 = number of columns
# mu                = mean = 0
# sigma             = variance = 1
# Sigma_matrix      = covariance matrix (see above)
Z = scipy.random.normal(mu, sigma, [no_pop, M])
cov_Z = covariance_matrix(Z)
chol_Z = scipy.linalg.cholesky(cov_Z);
chol_inv_Z = scipy.linalg.inv(chol_Z)
zch = np.dot(Z, chol_inv_Z)
Chol = scipy.linalg.cholesky(Sigma_matrix)
X = zch.dot(Chol)

#   It returns covariance matrix
def covariance_matrix(matrix):
X1 = matrix[:, 0]
X2 = matrix[:, 1]
X3 = matrix[:, 2]
C = np.vstack([X1, X2, X3])
return np.cov(C.astype(float), rowvar=True)
``````

``````while(True):
noiseZ = scipy.random.normal(mu, sigma, size=(no_pop * M))
if(abs(mu - np.mean(noiseZ)) < 0.0001 and abs(sigma - np.std(noiseZ)) < 0.0001):
noiseZ = np.reshape(noiseZ, [no_pop, M])
noiseFinal = noiseZ;
break;
``````

，然后检查noiseFinal的协方差矩阵是否等于恒等矩阵（不相关的噪声）。这样做时，我应该看到，在“数据集+ noiseFinal”的协方差矩阵中，协方差保持不变（或者它们可能变化很小），而方差却发生了变化。