mirror of
https://github.com/rasbt/python_reference.git
synced 2025-02-17 13:58:13 +00:00
test gauss
This commit is contained in:
parent
5d040cc076
commit
d85e1393fd
|
@ -21,13 +21,20 @@ def pdf_multivariate_gauss(x, mu, cov):
|
||||||
return float(part1 * np.exp(part2))
|
return float(part1 * np.exp(part2))
|
||||||
|
|
||||||
def test_gauss_pdf():
|
def test_gauss_pdf():
|
||||||
|
from matplotlib.mlab import bivariate_normal
|
||||||
|
|
||||||
x = np.array([[0],[0]])
|
x = np.array([[0],[0]])
|
||||||
mu = np.array([[0],[0]])
|
mu = np.array([[0],[0]])
|
||||||
cov = np.eye(2)
|
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__':
|
if __name__ == '__main__':
|
||||||
test_gauss_pdf()
|
test_gauss_pdf()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user