[Scipy-svn] r6577 - trunk/scipy/optimize

scipy-svn@scip... scipy-svn@scip...
Mon Jun 28 18:14:49 CDT 2010


Author: oliphant
Date: 2010-06-28 18:14:49 -0500 (Mon, 28 Jun 2010)
New Revision: 6577

Modified:
   trunk/scipy/optimize/cobyla.py
   trunk/scipy/optimize/lbfgsb.py
   trunk/scipy/optimize/slsqp.py
   trunk/scipy/optimize/tnc.py
Log:
Make sure all fmin_ optimizers accept the disp= keyword.

Modified: trunk/scipy/optimize/cobyla.py
===================================================================
--- trunk/scipy/optimize/cobyla.py	2010-06-28 23:14:32 UTC (rev 6576)
+++ trunk/scipy/optimize/cobyla.py	2010-06-28 23:14:49 UTC (rev 6577)
@@ -11,7 +11,7 @@
 import _cobyla
 from numpy import copy
 def fmin_cobyla(func, x0, cons, args=(), consargs=None, rhobeg=1.0, rhoend=1e-4,
-                iprint=1, maxfun=1000):
+                iprint=1, maxfun=1000, disp=None):
     """
     Minimize a function using the Constrained Optimization BY Linear
     Approximation (COBYLA) method.
@@ -36,7 +36,9 @@
     rhoend :
         Final accuracy in the optimization (not precisely guaranteed).
     iprint : {0, 1, 2, 3}
-        Controls the frequency of output; 0 implies no output.
+        Controls the frequency of output; 0 implies no output.  Deprecated
+    disp : {0, 1, 2, 3}
+        Over-rides the iprint interface.  Preferred.
     maxfun : int
         Maximum number of function evaluations.
 
@@ -64,6 +66,9 @@
     if consargs is None:
         consargs = args
 
+    if disp is not None:
+        iprint = disp
+
     def calcfc(x, con):
         f = func(x, *args)
         k = 0

Modified: trunk/scipy/optimize/lbfgsb.py
===================================================================
--- trunk/scipy/optimize/lbfgsb.py	2010-06-28 23:14:32 UTC (rev 6576)
+++ trunk/scipy/optimize/lbfgsb.py	2010-06-28 23:14:49 UTC (rev 6577)
@@ -34,7 +34,7 @@
                   approx_grad=0,
                   bounds=None, m=10, factr=1e7, pgtol=1e-5,
                   epsilon=1e-8,
-                  iprint=-1, maxfun=15000):
+                  iprint=-1, maxfun=15000, disp=None):
     """
     Minimize a function func using the L-BFGS-B algorithm.
 
@@ -78,6 +78,8 @@
         calculating the gradient
     iprint : int
         Controls the frequency of output. ``iprint < 0`` means no output.
+    disp : int
+        If zero, then no output.  If positive number, then this over-rides iprint
     maxfun : int
         Maximum number of function evaluations.
 
@@ -128,6 +130,12 @@
     if len(bounds) != n:
         raise ValueError('length of x0 != length of bounds')
 
+    if disp is not None:
+        if disp == 0:
+            iprint = -1
+        else:
+            iprint = disp
+
     if approx_grad:
         def func_and_grad(x):
             f = func(x, *args)

Modified: trunk/scipy/optimize/slsqp.py
===================================================================
--- trunk/scipy/optimize/slsqp.py	2010-06-28 23:14:32 UTC (rev 6576)
+++ trunk/scipy/optimize/slsqp.py	2010-06-28 23:14:49 UTC (rev 6577)
@@ -55,7 +55,7 @@
 def fmin_slsqp( func, x0 , eqcons=[], f_eqcons=None, ieqcons=[], f_ieqcons=None,
                 bounds = [], fprime = None, fprime_eqcons=None,
                 fprime_ieqcons=None, args = (), iter = 100, acc = 1.0E-6,
-                iprint = 1, full_output = 0, epsilon = _epsilon ):
+                iprint = 1, disp = None, full_output = 0, epsilon = _epsilon ):
     """
     Minimize a function using Sequential Least SQuares Programming
 
@@ -111,6 +111,8 @@
         * iprint <= 0 : Silent operation
         * iprint == 1 : Print summary upon completion (default)
         * iprint >= 2 : Print status of each iterate and summary
+    disp : int
+        Over-rides the iprint interface (preferred).
     full_output : bool
         If False, return only the minimizer of func (default).
         Otherwise, output final objective function and summary
@@ -164,6 +166,9 @@
                     7 : "Rank-deficient equality constraint subproblem HFTI",
                     8 : "Positive directional derivative for linesearch",
                     9 : "Iteration limit exceeded" }
+    
+    if disp is not None:
+        iprint = disp
 
     # Now do a lot of function wrapping
 

Modified: trunk/scipy/optimize/tnc.py
===================================================================
--- trunk/scipy/optimize/tnc.py	2010-06-28 23:14:32 UTC (rev 6576)
+++ trunk/scipy/optimize/tnc.py	2010-06-28 23:14:49 UTC (rev 6577)
@@ -82,7 +82,7 @@
              bounds=None, epsilon=1e-8, scale=None, offset=None,
              messages=MSG_ALL, maxCGit=-1, maxfun=None, eta=-1,
              stepmx=0, accuracy=0, fmin=0, ftol=-1, xtol=-1, pgtol=-1,
-             rescale=-1):
+             rescale=-1, disp=None):
     """Minimize a function with variables subject to bounds, using
     gradient information.
 
@@ -118,6 +118,8 @@
         Bit mask used to select messages display during
         minimization values defined in the MSGS dict.  Defaults to
         MGS_ALL.
+    disp : int
+        Integer interface to messages.  0 = no message, 5 = all messages
     maxCGit : int
         Maximum number of hessian*vector evaluations per main
         iteration.  If maxCGit == 0, the direction chosen is
@@ -174,6 +176,10 @@
     if len(bounds) != n:
         raise ValueError('length of x0 != length of bounds')
 
+    if disp is not None:
+        messages = {0:MSG_NONE, 1:MSG_ITER, 2:MSG_INFO, 3:MSG_VERS, 
+                    4:MSG_EXIT, 5:MSG_ALL}.get(disp, MSG_ALL)
+
     if approx_grad:
         def func_and_grad(x):
             x = asarray(x)



More information about the Scipy-svn mailing list