[SciPy-user] fmin_tnc error?

Christian Kristukat ckkart at hoc.net
Wed Feb 9 05:28:46 CST 2005


Christian Kristukat wrote:
> Hi,
> I probably found an error in optimize.fmin_tnc. I was not able to supply 
> an upper bound. If, e.g. I set the bounds to [-1,.1] I get:
> 
> tnc: Version 1.2, (c) 2002-2003, Jean-Sebastien Roy (js at jeannot.org)
> tnc: RCS ID: @(#) $Jeannot: tnc.c,v 1.201 2004/04/02 22:36:25 js Exp $
> tnc: All lower bounds are equal to the upper bounds
> [-0.10000000000000001]
> 
> It only works when setting the upper bound to None.
> 

I found the bug in optimize/tnc.py. Here's a patch. It fixes two more small errors:
- the tests called the wrong minimize function
- the parameter maxnfeval appeared as maxfun at some places


--- scipy/Lib/optimize/tnc.py   2005-02-09 12:22:25.000000000 +0100
+++ /usr/lib/python/site-packages/scipy/optimize/tnc.py 2005-02-09 
12:20:55.000000000 +0100
@@ -120,8 +120,8 @@
                      if maxCGit == 0, the direction chosen is -gradient
                      if maxCGit < 0, maxCGit is set to max(1,min(50,n/2))
                      defaults to -1
-        maxnfeval : max. number of function evaluation
-                    if None, maxnfeval is set to max(1000, 100*len(x0))
+        maxfun    : max. number of function evaluation
+                    if None, maxfun is set to max(1000, 100*len(x0))
                      defaults to None
          eta       : severity of the line search. if < 0 or > 1, set to 0.25
                      defaults to -1
@@ -185,7 +185,7 @@
          if u is None:
              up[i] = HUGE_VAL
          else:
-            up[i] = l
+            up[i] = u

      if scale == None:
          scale = []
@@ -213,7 +213,7 @@
                          return f, g

                  # Optimizer call
-                rc, nf, x = minimize(function, [-7, 3], bounds=([-10, 10], [1,
10]))
+                rc, nf, x = fmin_tnc(function, [-7, 3], bounds=([-10, 10], [1,
10]))

                  print "After", nf, "function evaluations, TNC returned:", 
RCSTRINGS[rc]
                  print "x =", x
@@ -297,7 +297,7 @@

          def test(fg, x, bounds, xopt):
                  print "** Test", fg.__name__
-                rc, nf, x = minimize(fg, x, bounds=bounds,  messages = 
MSG_NONE, maxnfeval = 200)
+                rc, nf, x = 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-user mailing list