Package snobfit :: Package tests :: Module test_big

Source Code for Module snobfit.tests.test_big

 1  """ Unit tests for Snobfit for a big dimension 
 2  Author: Ziwen Fu 
 3  Nov 2008 
 4  """ 
 5   
 6  import unittest 
 7  import numpy 
 8  try: 
 9      from snobfit.snobfit import snobfit 
10  except: 
11      from snobfit import snobfit 
12   
13   
14 -def big20(x):
15 f = 0.0 16 for i in xrange(20): 17 f += (x[i]-i*0.5)**2 18 19 return f
20 21 22 # ---------------------------------------------------------------------
23 -class test_Snobfit(unittest.TestCase):
24 - def setUp(self):
25 pass
26
27 - def test_big20(self):
28 # big dimension 29 n = 20 30 u = numpy.array( range(0,n) )*0.5 - 3 31 v = numpy.array( range(0,n) )*0.5 + 2 32 x0 = numpy.array( range(0,n) )*0.5 + 0.3 33 fglob = 0 34 xglob = numpy.array( range(0,n) ) * 0.5 35 xbest, fbest, ncall = snobfit(big20, 36 x0, 37 (u, v), 38 fglob=fglob, 39 retall=1 40 ) 41 assert abs(fbest-fglob) < 1.0e-6
42 43 44 45 #--------------------------------------------- 46 if __name__ == '__main__': 47 unittest.main() 48