Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gplepage committed Dec 4, 2023
1 parent 322c3bf commit 0905232
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions tests/test_vegas.py
Original file line number Diff line number Diff line change
Expand Up @@ -1347,14 +1347,14 @@ def f(p):
return ff
gv.ranseed(1)
r = gev(f, nitn=1)
self.assertTrue(abs(r.mean - g.mean) < 5 * r.sdev)
self.assertLess(abs(r.mean - g.mean), 5 * r.sdev)
@lbatchintegrand
def f(p):
ff = p
return ff
gv.ranseed(1)
r = gev(f, nitn=1)
self.assertTrue(abs(r.mean - g.mean) < 5 * r.sdev)
self.assertLess(abs(r.mean - g.mean), 5 * r.sdev)

def test_array_pdf(self):
g = gv.gvar([1., 2.], [[1, .1], [.1, 4]])
Expand All @@ -1365,14 +1365,14 @@ def f(p):
return ff
gv.ranseed(1)
r = gev(f, nitn=1)
self.assertTrue(abs(r.mean - sum(g).mean) < 5 * r.sdev)
self.assertLess(abs(r.mean - sum(g).mean), 5 * r.sdev)
@lbatchintegrand
def f(p):
ff = np.sum(p, axis=1)
return ff
gv.ranseed(1)
r = gev(f, nitn=1)
self.assertTrue(abs(r.mean - sum(g).mean) < 5 * r.sdev)
self.assertLess(abs(r.mean - sum(g).mean), 5 * r.sdev)

def test_dict_pdf(self):
g = dict(a=gv.gvar(1, 1), b=gv.gvar([1., 2.], [[1, .1], [.1, 4]]))
Expand All @@ -1382,24 +1382,24 @@ def f(p):
return ff
gv.ranseed(1)
r = gev(f, nitn=1)
self.assertTrue(abs(r.mean - sum(g['b']).mean) < 5 * r.sdev)
self.assertLess(abs(r.mean - sum(g['b']).mean), 5 * r.sdev)
@rbatchintegrand
def f(p):
ff = np.sum(p['b'], axis=0)
return ff
gv.ranseed(1)
r = gev(f, nitn=1)
self.assertTrue(abs(r.mean - sum(g['b']).mean) < 5 * r.sdev)
self.assertLess(abs(r.mean - sum(g['b']).mean), 5 * r.sdev)
@lbatchintegrand
def f(p):
ff = np.sum(p['b'], axis=1)
return ff
gv.ranseed(1)
r = gev(f, nitn=1)
self.assertTrue(abs(r.mean - sum(g['b']).mean) < 5 * r.sdev)
self.assertLess(abs(r.mean - sum(g['b']).mean), 5 * r.sdev)

def test_change_pdf(self):
gv.ranseed(1234)
gv.ranseed(12345)
g = gv.gvar(1, 2)
gev = PDFIntegrator(g, alpha=0, beta=0)
# shift peak
Expand All @@ -1409,7 +1409,8 @@ def f(p):
def pdf(p):
return gv.exp(-(p - g.mean - 0.5 * g.sdev) ** 2 / 8) / np.sqrt(2 * np.pi * g.var)
r = gev(f, pdf=pdf, nitn=2, adapt=True)
self.assertTrue(abs(r[0].mean - g.mean - 0.5 * g.sdev) < 5 * r[0].sdev)
print(abs(r[0].mean - g.mean - 0.5 * g.sdev), 7 * r[0].sdev)
self.assertLess(abs(r[0].mean - g.mean - 0.5 * g.sdev), 5 * r[0].sdev)

gv.ranseed(1234)
g = gv.gvar(1, 2)
Expand All @@ -1421,7 +1422,7 @@ def f(p):
def pdf(p):
return gv.exp(-(p - g.mean - 0.5 * g.sdev) ** 2 / 8) / np.sqrt(2 * np.pi * g.var)
r = gev(f, pdf=pdf, nitn=2, adapt=True)
self.assertTrue(abs(r[0].mean - g.mean - 0.5 * g.sdev) < 5 * r[0].sdev)
self.assertLess(abs(r[0].mean - g.mean - 0.5 * g.sdev), 5 * r[0].sdev)

def test_adapt_to_pdf(self):
gv.ranseed(1)
Expand Down

0 comments on commit 0905232

Please sign in to comment.