Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from matplotlib import pylab as plt
- from matplotlib import mlab
- mean_test = np.array([0,0])
- cov_test = array([[ 0.6744121 , -0.16938146],
- [-0.16938146, 0.21243464]])
- # Semi-positive definite if all eigenvalues are 0 or
- # if there exists a Cholesky decomposition
- print np.linalg.eigvals(cov_test)
- print np.linalg.cholesky(cov_test)
- data_test = np.random.multivariate_normal(mean_test, cov_test, 1000)
- plt.scatter(data_test[:,0],data_test[:,1])
- x = np.arange(-3.0, 3.0, 0.1)
- y = np.arange(-3.0, 3.0, 0.1)
- X, Y = np.meshgrid(x, y)
- Z = mlab.bivariate_normal(X, Y,
- cov_test[0,0], cov_test[1,1],
- 0, 0, cov_test[0,1])
- print Z
- plt.contour(X, Y, Z)
- [[ nan nan nan ..., nan nan nan]
- [ nan nan nan ..., nan nan nan]
- [ nan nan nan ..., nan nan nan]
- ...,
- [ nan nan nan ..., nan nan nan]
- [ nan nan nan ..., nan nan nan]
- [ nan nan nan ..., nan nan nan]]
- ValueError: zero-size array to reduction operation minimum which has no identity
- Z = mlab.bivariate_normal(X, Y,
- cov_test[0,0], cov_test[1,1],
- 0, 0, cov_test[0,1])
- Z = mlab.bivariate_normal(X, Y,
- np.sqrt(cov_test[0,0]), np.sqrt(cov_test[1,1]),
- 0, 0, cov_test[0,1])
Add Comment
Please, Sign In to add comment