Guest User

Untitled

a guest
Jun 13th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. import numpy as np
  2.  
  3. n_sample = 1000
  4. true_coef = np.array([2.0, 3.0])
  5. u0 = np.array([0.0, 0.0])
  6. A0 = 0.1 * np.eye(2)
  7. sample_X = np.random.normal(size=(n_sample, 2))
  8. sample_y = np.dot(sample_X, true_coef.reshape(-1, 1)).reshape(-1,) + np.random.normal(size=n_sample)
  9.  
  10. tmp1 = np.linalg.inv(np.dot(sample_X.T, sample_X))
  11. tmp2 = np.dot(sample_X.T, sample_y.reshape(-1, 1))
  12. beta = np.dot(tmp1, tmp2)
  13. tmp1 = np.linalg.inv(np.dot(sample_X.T, sample_X) + A0)
  14. tmp2 = np.dot(np.dot(sample_X.T, sample_X), beta) + np.dot(A0, u0.reshape(-1, 1))
  15. estimation_coef = np.dot(tmp1, tmp2)
  16. print(estimation_coef)
Add Comment
Please, Sign In to add comment