Permalink
Browse files

ENH: return information message in COBYLA

In the COBYLA Fortran routine, DINFO(1) takes integer values in order to
identify the cause of the termination.
  • Loading branch information...
1 parent 9183886 commit 9ba2a0a413ec00b14184ccf57fe7327dafe39c5d @dlax dlax committed May 21, 2012
Showing with 12 additions and 5 deletions.
  1. +8 −1 scipy/optimize/cobyla.py
  2. +3 −3 scipy/optimize/cobyla/cobyla2.f
  3. +1 −1 scipy/optimize/tests/test_cobyla.py
View
@@ -237,7 +237,14 @@ def calcfc(x, con):
dinfo=info)
return Result(x=xopt,
- success=bool(info[0]),
+ status=info[0],
+ success=info[0]==1,
+ message={1: 'Optimization terminated successfully.',
+ 2: 'Maximum number of function evaluations has '
+ 'been exceeded.',
+ 3: 'Rounding errors are becoming damaging in '
+ 'COBYLA subroutine.'
+ }.get(info[0], 'Unknown exit status.'),
nfev=int(info[1]),
fun=info[2],
maxcv=info[3])
@@ -102,7 +102,7 @@ SUBROUTINE COBYLB (CALCFC,N,M,MPP,X,RHOBEG,RHOEND,IPRINT,MAXFUN,
DELTA=1.1d0
RHO=RHOBEG
PARMU=0.0d0
-C Set the SUCCESS value of DINFO to 1.0 to start.
+C Set the STATUS value of DINFO to 1.0 to start.
C IF an error occurs it will get set to 0.0
DINFO(1)=1.0d0
@@ -138,7 +138,7 @@ SUBROUTINE COBYLB (CALCFC,N,M,MPP,X,RHOBEG,RHOEND,IPRINT,MAXFUN,
IF (IPRINT .GE. 1) PRINT 50
50 FORMAT (/3X,'Return from subroutine COBYLA because the ',
1 'MAXFUN limit has been reached.')
- DINFO(1)=0.0d0
+ DINFO(1)=2.0d0
GOTO 600
END IF
NFVALS=NFVALS+1
@@ -252,7 +252,7 @@ SUBROUTINE COBYLB (CALCFC,N,M,MPP,X,RHOBEG,RHOEND,IPRINT,MAXFUN,
IF (IPRINT .GE. 1) PRINT 210
210 FORMAT (/3X,'Return from subroutine COBYLA because ',
1 'rounding errors are becoming damaging.')
- DINFO(1)=0.0d0
+ DINFO(1)=3.0d0
GOTO 600
END IF
C
@@ -34,7 +34,7 @@ def test_minimize_simple(self):
sol = minimize(self.fun, self.x0, method='cobyla', constraints=cons,
options=self.opts)
assert_allclose(sol.x, self.solution, atol=1e-4)
- assert_(sol.success, sol)
+ assert_(sol.success, sol.message)
assert_(sol.maxcv < 1e-5, sol)
assert_(sol.nfev < 70, sol)
assert_(sol.fun < self.fun(self.solution) + 1e-3, sol)

0 comments on commit 9ba2a0a

Please sign in to comment.