lundi 16 octobre 2023

Random Positive Definite matrix and Cholesky decomposition

I was interested in generating the correlated random data set and found some example of the solution here. But I've faced some interesting problems.

The solution consists from the next steps:

  1. Generate random uncorrelated data points (maybe from normal destribution)
  2. Calculate their covariance matrix (it must be positive definite)
  3. Find Cholesky decomposition of the covariance matrix

But the realization failing, if I am generating random points in the non-square form. For example:

X = np.random.rand(1000, 140)
Omega = X@X.T 
# or 
# Omega = np.dot(X_uncorr, X_uncorr.transpose())
# or 
# Omega = np.corrcoef(X.T, X.T, rowvar=False)

than the functions scipy.linalg.cholesky() and np.linalg.cholesky() will rise an errors 'LinAlgError: 101-th leading minor of the array is not positive definite' and 'LinAlgError: Matrix is not positive definite' correspondingly.

If the original data symmetric:

X = np.random.rand(1000, 1000)

there will be no errors. Is it some math fact, that the Cov matrix of nonsymmetric data set is negative definite? Or is it an error in code realization?




Aucun commentaire:

Enregistrer un commentaire