[Scipy-svn] r3187 - in trunk/Lib/optimize: . tests

scipy-svn at scipy.org scipy-svn at scipy.org
Tue Jul 24 10:14:13 EDT 2007


Author: dmitrey.kroshko
Date: 2007-07-24 09:13:43 -0500 (Tue, 24 Jul 2007)
New Revision: 3187

Modified:
   trunk/Lib/optimize/tests/test_optimize.py
   trunk/Lib/optimize/tnc.py
Log:
correct order of tnc return values + bugfix for tnc tests 


Modified: trunk/Lib/optimize/tests/test_optimize.py
===================================================================
--- trunk/Lib/optimize/tests/test_optimize.py	2007-07-24 10:37:50 UTC (rev 3186)
+++ trunk/Lib/optimize/tests/test_optimize.py	2007-07-24 14:13:43 UTC (rev 3187)
@@ -199,7 +199,7 @@
             dif[3] = (180.0*(x[3]-pow(x[2],2))+20.2\
                       *(x[3]-1.0)+19.8*(x[1]-1.0))*1.0e-5
             return f, dif
-        self.tests.append((test38fg, [-3,-1,-3,-1], [(-10,10)]*4, [1]*4))
+        self.tests.append((test38fg, array([-3,-1,-3,-1]), [(-10,10)]*4, [1]*4))
 
         def test45fg(x):
             f = 2.0-x[0]*x[1]*x[2]*x[3]*x[4]/120.0
@@ -220,10 +220,11 @@
             err = "Failed optimization of %s.\n" \
                   "After %d function evaluations, TNC returned: %s.""" % \
                   (fg.__name__, nf, RCSTRINGS[rc])
+        
+        ef = abs(fg(xopt)[0] - fg(x)[0])
+        print "F Error =", ef
+        if ef > 1e-8:
+            raise err
 
-            assert_array_almost_equal(array(x,dtype=float),
-                                      array(xopt,dtype=float),
-                                      err_msg=err)
-
 if __name__ == "__main__":
     NumpyTest().run()

Modified: trunk/Lib/optimize/tnc.py
===================================================================
--- trunk/Lib/optimize/tnc.py	2007-07-24 10:37:50 UTC (rev 3186)
+++ trunk/Lib/optimize/tnc.py	2007-07-24 14:13:43 UTC (rev 3187)
@@ -229,9 +229,10 @@
     if maxfun == None:
         maxfun = max(100, 10*len(x0))
 
-    return moduleTNC.minimize(func_and_grad, x0, low, up, scale, offset,
+    rc, nf, x = moduleTNC.minimize(func_and_grad, x0, low, up, scale, offset,
             messages, maxCGit, maxfun, eta, stepmx, accuracy,
             fmin, ftol, xtol, pgtol, rescale)
+    return x, nf, rc
 
 if __name__ == '__main__':
     # Examples for TNC
@@ -249,7 +250,7 @@
             return f, g
 
         # Optimizer call
-        rc, nf, x = fmin_tnc(function, [-7, 3], bounds=([-10, 1], [10, 10]))
+        x, nf, rc = fmin_tnc(function, [-7, 3], bounds=([-10, 1], [10, 10]))
 
         print "After", nf, "function evaluations, TNC returned:", RCSTRINGS[rc]
         print "x =", x
@@ -333,7 +334,7 @@
 
     def test(fg, x, bounds, xopt):
         print "** Test", fg.__name__
-        rc, nf, x = fmin_tnc(fg, x, bounds=bounds, messages = MSG_NONE, maxfun = 200)
+        x, nf, rc = fmin_tnc(fg, x, bounds=bounds, messages = MSG_NONE, maxfun = 200)
         print "After", nf, "function evaluations, TNC returned:", RCSTRINGS[rc]
         print "x =", x
         print "exact value =", xopt




More information about the Scipy-svn mailing list