mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-15 06:52:39 +02:00
format on save
This commit is contained in:
parent
65d919da06
commit
97741d6b41
1 changed files with 12 additions and 10 deletions
|
|
@ -1,23 +1,22 @@
|
||||||
from __future__ import print_function, division
|
from __future__ import print_function, division
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import GPy
|
|
||||||
import warnings
|
|
||||||
from ..util.quad_integrate import quadgk_int, quadvgk
|
from ..util.quad_integrate import quadgk_int, quadvgk
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class QuadTests(np.testing.TestCase):
|
class QuadTests(np.testing.TestCase):
|
||||||
"""
|
"""
|
||||||
test file for checking implementation of gaussian-kronrod quadrature.
|
test file for checking implementation of gaussian-kronrod quadrature.
|
||||||
we will take a function which can be integrated analytically and check if quadgk result is similar or not!
|
we will take a function which can be integrated analytically and check if quadgk result is similar or not!
|
||||||
through this file we can test how numerically accurate quadrature implementation in native numpy or manual code is.
|
through this file we can test how numerically accurate quadrature implementation in native numpy or manual code is.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_infinite_quad(self):
|
def test_infinite_quad(self):
|
||||||
def f(x):
|
def f(x):
|
||||||
return np.exp(-0.5 * x**2) * np.power(x, np.arange(3)[:, None])
|
return np.exp(-0.5 * x**2) * np.power(x, np.arange(3)[:, None])
|
||||||
|
|
||||||
quad_int_val = quadgk_int(f)
|
quad_int_val = quadgk_int(f)
|
||||||
real_val = np.sqrt(np.pi * 2)
|
real_val = np.sqrt(np.pi * 2)
|
||||||
np.testing.assert_almost_equal(real_val, quad_int_val[0], decimal=7)
|
np.testing.assert_almost_equal(real_val, quad_int_val[0], decimal=7)
|
||||||
|
|
@ -25,11 +24,14 @@ class QuadTests(np.testing.TestCase):
|
||||||
def test_finite_quad(self):
|
def test_finite_quad(self):
|
||||||
def f2(x):
|
def f2(x):
|
||||||
return x**2
|
return x**2
|
||||||
quad_int_val = quadvgk(f2, 1.,2.)
|
|
||||||
real_val = 7/3.
|
quad_int_val = quadvgk(f2, 1.0, 2.0)
|
||||||
|
real_val = 7 / 3.0
|
||||||
np.testing.assert_almost_equal(real_val, quad_int_val, decimal=5)
|
np.testing.assert_almost_equal(real_val, quad_int_val, decimal=5)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
def f(x):
|
def f(x):
|
||||||
return np.exp(-0.5 * x**2) * np.power(x, np.arange(3)[:, None])
|
return np.exp(-0.5 * x**2) * np.power(x, np.arange(3)[:, None])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue