Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. import numpy as np
  2.  
  3. n_obs = 10000
  4. means = [1, 2, 3]
  5. sds = [1, 2, 3] # standard deviations
  6.  
  7. # generating random independent variables
  8. observations = np.vstack([np.random.normal(loc=mean, scale=sd, size=n_obs)
  9. for mean, sd in zip(means, sds)]) # observations, a row per variable
  10.  
  11. cor_matrix = [[1.0, 0.6, 0.9],
  12. [0.6, 1.0, 0.5],
  13. [0.9, 0.5, 1.0]]
  14.  
  15. cor_matrix = np.array(cor_matrix)
  16. L = np.linalg.cholesky(cor_matrix)
  17.  
  18. print(np.corrcoef(L.dot(observations)))
  19.  
  20. [[ 1. 0.34450587 0.57515737]
  21. [ 0.34450587 1. 0.1488504 ]
  22. [ 0.57515737 0.1488504 1. ]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement