30
30
from ._lbfgsb_py import _minimize_lbfgsb
31
31
from ._tnc import _minimize_tnc
32
32
from ._cobyla_py import _minimize_cobyla
33
+ from ._cobyqa_py import _minimize_cobyqa
33
34
from ._slsqp_py import _minimize_slsqp
34
35
from ._constraints import (old_bound_to_new , new_bounds_to_old ,
35
36
old_constraint_to_new , new_constraint_to_old ,
38
39
from ._differentiable_functions import FD_METHODS
39
40
40
41
MINIMIZE_METHODS = ['nelder-mead' , 'powell' , 'cg' , 'bfgs' , 'newton-cg' ,
41
- 'l-bfgs-b' , 'tnc' , 'cobyla' , 'slsqp' , 'trust-constr' ,
42
- 'dogleg' , 'trust-ncg' , 'trust-exact' , 'trust-krylov' ]
42
+ 'l-bfgs-b' , 'tnc' , 'cobyla' , 'cobyqa' , 'slsqp' ,
43
+ 'trust-constr' , 'dogleg' , 'trust-ncg' , 'trust-exact' ,
44
+ 'trust-krylov' ]
43
45
44
46
# These methods support the new callback interface (passed an OptimizeResult)
45
47
MINIMIZE_METHODS_NEW_CB = ['nelder-mead' , 'powell' , 'cg' , 'bfgs' , 'newton-cg' ,
46
48
'l-bfgs-b' , 'trust-constr' , 'dogleg' , 'trust-ncg' ,
47
- 'trust-exact' , 'trust-krylov' ]
49
+ 'trust-exact' , 'trust-krylov' , 'cobyqa' ]
48
50
49
51
MINIMIZE_SCALAR_METHODS = ['brent' , 'bounded' , 'golden' ]
50
52
@@ -80,6 +82,7 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
80
82
- 'L-BFGS-B' :ref:`(see here) <optimize.minimize-lbfgsb>`
81
83
- 'TNC' :ref:`(see here) <optimize.minimize-tnc>`
82
84
- 'COBYLA' :ref:`(see here) <optimize.minimize-cobyla>`
85
+ - 'COBYQA' :ref:`(see here) <optimize.minimize-cobyqa>`
83
86
- 'SLSQP' :ref:`(see here) <optimize.minimize-slsqp>`
84
87
- 'trust-constr':ref:`(see here) <optimize.minimize-trustconstr>`
85
88
- 'dogleg' :ref:`(see here) <optimize.minimize-dogleg>`
@@ -146,15 +149,15 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
146
149
parameters.
147
150
bounds : sequence or `Bounds`, optional
148
151
Bounds on variables for Nelder-Mead, L-BFGS-B, TNC, SLSQP, Powell,
149
- trust-constr, and COBYLA methods. There are two ways to specify the
150
- bounds:
152
+ trust-constr, COBYLA, and COBYQA methods. There are two ways to specify
153
+ the bounds:
151
154
152
155
1. Instance of `Bounds` class.
153
156
2. Sequence of ``(min, max)`` pairs for each element in `x`. None
154
157
is used to specify no bound.
155
158
156
159
constraints : {Constraint, dict} or List of {Constraint, dict}, optional
157
- Constraints definition. Only for COBYLA, SLSQP and trust-constr.
160
+ Constraints definition. Only for COBYLA, COBYQA, SLSQP and trust-constr.
158
161
159
162
Constraints for 'trust-constr' are defined as a single object or a
160
163
list of objects specifying constraints to the optimization problem.
@@ -178,6 +181,8 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
178
181
Equality constraint means that the constraint function result is to
179
182
be zero whereas inequality means that it is to be non-negative.
180
183
Note that COBYLA only supports inequality constraints.
184
+
185
+ Constraints for COBYQA are defined as any of the above.
181
186
tol : float, optional
182
187
Tolerance for termination. When `tol` is specified, the selected
183
188
minimization algorithm sets some relevant solver-specific tolerance(s)
@@ -335,6 +340,13 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
335
340
constraints functions 'fun' may return either a single number
336
341
or an array or list of numbers.
337
342
343
+ Method :ref:`COBYQA <optimize.minimize-cobyqa>` uses the Constrained
344
+ Optimization BY Quadratic Approximations (COBYQA) method [18]_. The
345
+ algorithm is a derivative-free trust-region SQP method based on quadratic
346
+ approximations to the objective function and each nonlinear constraint. The
347
+ bounds are treated as unrelaxable constraints, in the sense that the
348
+ algorithm always respects them throughout the optimization process.
349
+
338
350
Method :ref:`SLSQP <optimize.minimize-slsqp>` uses Sequential
339
351
Least SQuares Programming to minimize a function of several
340
352
variables with any combination of bounds, equality and inequality
@@ -466,6 +478,10 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
466
478
.. [17] Lalee, Marucha, Jorge Nocedal, and Todd Plantega. 1998. On the
467
479
implementation of an algorithm for large-scale equality constrained
468
480
optimization. SIAM Journal on Optimization 8.3: 682-706.
481
+ .. [18] Ragonneau, T. M. *Model-Based Derivative-Free Optimization Methods
482
+ and Software*. PhD thesis, Department of Applied Mathematics, The Hong
483
+ Kong Polytechnic University, Hong Kong, China, 2022. URL:
484
+ https://theses.lib.polyu.edu.hk/handle/200/12294.
469
485
470
486
Examples
471
487
--------
@@ -558,7 +574,7 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
558
574
options = {}
559
575
# check if optional parameters are supported by the selected method
560
576
# - jac
561
- if meth in ('nelder-mead' , 'powell' , 'cobyla' ) and bool (jac ):
577
+ if meth in ('nelder-mead' , 'powell' , 'cobyla' , 'cobyqa' ) and bool (jac ):
562
578
warn ('Method %s does not use gradient information (jac).' % method ,
563
579
RuntimeWarning , stacklevel = 2 )
564
580
# - hess
@@ -574,16 +590,17 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
574
590
'information (hessp).' % method ,
575
591
RuntimeWarning , stacklevel = 2 )
576
592
# - constraints or bounds
577
- if (meth not in ('cobyla' , 'slsqp' , 'trust-constr' , '_custom' ) and
593
+ if (meth not in ('cobyla' , 'cobyqa' , ' slsqp' , 'trust-constr' , '_custom' ) and
578
594
np .any (constraints )):
579
595
warn ('Method %s cannot handle constraints.' % method ,
580
596
RuntimeWarning , stacklevel = 2 )
581
- if meth not in ('nelder-mead' , 'powell' , 'l-bfgs-b' , 'cobyla' , 'slsqp' ,
582
- 'tnc' , 'trust-constr' , '_custom' ) and bounds is not None :
597
+ if meth not in (
598
+ 'nelder-mead' , 'powell' , 'l-bfgs-b' , 'cobyla' , 'cobyqa' , 'slsqp' ,
599
+ 'tnc' , 'trust-constr' , '_custom' ) and bounds is not None :
583
600
warn ('Method %s cannot handle bounds.' % method ,
584
601
RuntimeWarning , stacklevel = 2 )
585
602
# - return_all
586
- if (meth in ('l-bfgs-b' , 'tnc' , 'cobyla' , 'slsqp' ) and
603
+ if (meth in ('l-bfgs-b' , 'tnc' , 'cobyla' , 'cobyqa' , ' slsqp' ) and
587
604
options .get ('return_all' , False )):
588
605
warn ('Method %s does not support the return_all option.' % method ,
589
606
RuntimeWarning , stacklevel = 2 )
@@ -624,6 +641,8 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
624
641
options .setdefault ('gtol' , tol )
625
642
if meth in ('cobyla' , '_custom' ):
626
643
options .setdefault ('tol' , tol )
644
+ if meth == 'cobyqa' :
645
+ options .setdefault ('final_tr_radius' , tol )
627
646
if meth == 'trust-constr' :
628
647
options .setdefault ('xtol' , tol )
629
648
options .setdefault ('gtol' , tol )
@@ -718,6 +737,9 @@ def minimize(fun, x0, args=(), method=None, jac=None, hess=None,
718
737
elif meth == 'cobyla' :
719
738
res = _minimize_cobyla (fun , x0 , args , constraints , callback = callback ,
720
739
bounds = bounds , ** options )
740
+ elif meth == 'cobyqa' :
741
+ res = _minimize_cobyqa (fun , x0 , args , bounds , constraints , callback ,
742
+ ** options )
721
743
elif meth == 'slsqp' :
722
744
res = _minimize_slsqp (fun , x0 , args , jac , bounds ,
723
745
constraints , callback = callback , ** options )
@@ -1016,7 +1038,8 @@ def _validate_bounds(bounds, x0, meth):
1016
1038
1017
1039
def standardize_bounds (bounds , x0 , meth ):
1018
1040
"""Converts bounds to the form required by the solver."""
1019
- if meth in {'trust-constr' , 'powell' , 'nelder-mead' , 'cobyla' , 'new' }:
1041
+ if meth in {'trust-constr' , 'powell' , 'nelder-mead' , 'cobyla' , 'cobyqa' ,
1042
+ 'new' }:
1020
1043
if not isinstance (bounds , Bounds ):
1021
1044
lb , ub = old_bound_to_new (bounds )
1022
1045
bounds = Bounds (lb , ub )
0 commit comments