IHCantabria / NEOPRENE

Neyman-Scott Process Rainfall Emulator library
GNU General Public License v3.0
13 stars 6 forks source link

cross correlation of various independent superposed processes (process="storms") #2

Closed JavierDiezSierra closed 2 years ago

JavierDiezSierra commented 2 years ago

The cross correlation of various superposed processes -which are independently- is calculated by the mean cross correlation of the different process.

Demonstration:

from scipy.linalg import cholesky

# pair 1
# Correlation matrix
corr_mat= np.array([[1.0, 0.5],
                    [0.5, 1.0]])
# Compute the (upper) Cholesky decomposition matrix
upper_chol = cholesky(corr_mat)
# Generate 3 series of normally distributed (Gaussian) numbers
rnd = np.random.normal(0.0, 1.0, size=(10**7, 2))
# Finally, compute the inner product of upper_chol and rnd
ans = rnd @ upper_chol
par_1 = pd.DataFrame()
par_1['serie_1'] = ans[:,0]
par_1['serie_2'] = ans[:,1]

# pair 2
# Correlation matrix
corr_mat= np.array([[1.0, 0.8],
                    [0.8, 1.0]])
# Compute the (upper) Cholesky decomposition matrix
upper_chol = cholesky(corr_mat)
# Generate 3 series of normally distributed (Gaussian) numbers
rnd = np.random.normal(0.0, 1.0, size=(10**7, 2))
# Finally, compute the inner product of upper_chol and rnd
ans = rnd @ upper_chol
par_2 = pd.DataFrame()
par_2['serie_1'] = ans[:,0]
par_2['serie_2'] = ans[:,1]

# sum
print(par_1.corr())
print(par_2.corr())
sumi = par_1 + par_2
print(sumi.corr())