简体   繁体   中英

Generate White noise (normal distribution with null mean and unitary variance)

I'm trying to generate white noise for dataset 100 rows x 3 columns, built through Cholesky Factorization; the dataset is a Gaussian multivariate distribution with parameter 0 and Sigma (cov. matrix) as it follows:

[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)

(I've checked correlation coefficent and covariance matrix of the generated dataset). Now, I need to generate noise and add it to the dataset as shown in link - Section 2.1 . What I did so far is:

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;

and then check if the covariance matrix of noiseFinal is equal to identity matrix (uncorrelated Noise). Doing this, I should see that, in the covariance matrix of the "dataset + noiseFinal", covariances are left untouched (or they could change for a very very small amount), while variances have changed.

Where does the error occur?

Actually, I think you should increase the sample... Try to have a larger population around 10k and then extract a sample of the size you need. This should do the trick! Lemme know, good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM