test gauss

This commit is contained in:
rasbt 2014-04-16 13:00:35 -04:00
parent 5d040cc076
commit d85e1393fd
2 changed files with 9 additions and 2 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -21,13 +21,20 @@ def pdf_multivariate_gauss(x, mu, cov):
return float(part1 * np.exp(part2))
def test_gauss_pdf():
from matplotlib.mlab import bivariate_normal
x = np.array([[0],[0]])
mu = np.array([[0],[0]])
cov = np.eye(2)
print(pdf_multivariate_gauss(x, mu, cov))
mlab_gauss = bivariate_normal(x,x)
mlab_gauss = float(mlab_gauss[0]) # because mlab returns an np.array
impl_gauss = pdf_multivariate_gauss(x, mu, cov)
print('mlab_gauss:', mlab_gauss)
print('impl_gauss:', impl_gauss)
assert(mlab_gauss == impl_gauss), 'Implementations of the mult. Gaussian return different pdfs'
# prints 0.15915494309189535
if __name__ == '__main__':
test_gauss_pdf()