Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. plt.gcf().clear()
  2.  
  3. N = 60
  4. X = np.linspace(-4, 7, N)
  5. Y = np.linspace(-4, 6, N)
  6. X, Y = np.meshgrid(X, Y)
  7.  
  8. pos = np.empty(X.shape + (2,))
  9. pos[:, :, 0] = X
  10. pos[:, :, 1] = Y
  11.  
  12. def multivariate_gaussian(pos, mu, Sigma):
  13. n = mu.shape[0]
  14. Sigma_det = np.linalg.det(Sigma)
  15. Sigma_inv = np.linalg.inv(Sigma)
  16. N = np.sqrt((2*np.pi)**n * Sigma_det)
  17. fac = np.einsum('...k,kl,...l->...', pos-mu, Sigma_inv, pos-mu)
  18. return np.exp(-fac / 2) / N
  19.  
  20. Z1 = multivariate_gaussian(pos, mean1, sd1)
  21. Z2 = multivariate_gaussian(pos, mean2, sd2)
  22. Z = Z2 - Z1
  23.  
  24. plt.contourf(X, Y, Z)
  25. ax = plt.axes()
  26. ax.arrow(-7*max_w_x, -7*max_w_y, 15*max_w_x, 15*max_w_y, fc='k', ec='k')
  27. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement