naginterfaces.library.opt.handle_solve_bounds_foas¶
- naginterfaces.library.opt.handle_solve_bounds_foas(handle, x, objfun=None, objgrd=None, monit=None, data=None, io_manager=None)[source]¶
handle_solve_bounds_foas
is a solver from the NAG optimization modelling suite for bound-constrained large-scale Nonlinear Programming (NLP) problems. It is a first-order active-set method (FOAS) that has low memory requirements and thus is suitable for very large-scale problems.Note: this function uses optional algorithmic parameters, see also:
handle_opt_set()
,handle_opt_get()
.For full information please refer to the NAG Library document for e04kf
https://www.nag.com/numeric/nl/nagdoc_28.6/flhtml/e04/e04kff.html
- Parameters
- handleHandle
The handle to the problem. It needs to be initialized (e.g., by
handle_init()
) and to hold a problem formulation compatible withhandle_solve_bounds_foas
. It must not be changed between calls to the NAG optimization modelling suite.- xfloat, array-like, shape
, the initial estimates of the variables, .
- objfunNone or callable (fx, inform) = objfun(x, inform, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
must calculate the value of the nonlinear objective function at a specified point .
If there is no nonlinear objective (e.g.,
handle_set_linobj()
orhandle_set_quadobj()
was called to define a linear or quadratic objective function), will never be called byhandle_solve_bounds_foas
and may be None.- Parameters
- xfloat, ndarray, shape
The vector of variable values at which the objective function is to be evaluated.
- informint
A non-negative value.
In some cases, it is known beforehand that the evaluations of the objective function and its gradient are required at the same point , in such cases, .
This may help to optimize your code in order to avoid recalculations of common quantities when evaluating both the objective function and gradient; the objective function is always evaluated before the objective gradient.
This notification parameter may be safely ignored if such optimization is not required.
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- fxfloat
The value of the objective function at .
- informint
May be used to indicate that the function cannot be evaluated at the requested point by setting . Returning NaN or in has the same effect. The algorithm will try to recover if the objective cannot be evaluated; if recovery is not possible it will stop with = 25.
- objgrdNone or callable inform = objgrd(x, fdx, inform, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
must calculate the values of the nonlinear objective function gradient at a specified point .
Every call to is preceded by a call to at the same point, if this is known in advance, both functions will be notified via .
If there is no nonlinear objective (e.g.,
handle_set_linobj()
orhandle_set_quadobj()
was called to define a linear or quadratic objective function), will never be called byhandle_solve_bounds_foas
and may be None.If the option , then after returning from the gradient vector is checked for missing entries which you have not supplied.
Missing entries are estimated using the finite difference method, see option ‘FOAS Estimate Derivatives’ description for more details.
- Parameters
- xfloat, ndarray, shape
The vector of variable values at which the objective function gradient is to be evaluated.
- fdxfloat, ndarray, shape , to be modified in place
On entry: the elements should only be assigned and not referenced.
On exit: the values of the nonzero elements in the sparse gradient vector of the objective function, in the order specified by in a previous call to
handle_set_nlnobj()
. will store the gradient element , where .- informint
A non-negative value.
If , then the previous call to was also made at the same point with .
This may help to optimize your code in order to avoid recalculations of common quantities when evaluating both the objective function and gradient.
This notification parameter may be safely ignored if such optimization is not required.
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- Returns
- informint
May be used to inform that the gradient cannot be evaluated at the requested point by setting . Returning NaN or in any element of has the same effect. The algorithm will try to recover if the gradient cannot be evaluated; if recovery is not possible it will stop with = 25.
- monitNone or callable monit(x, rinfo, stats, data=None), optional
Note: if this argument is None then a NAG-supplied facility will be used.
is provided to enable you to monitor the progress of the optimization and optionally to terminate the solver early if necessary.
It is invoked at the end of every th iteration where is given by the ‘FOAS Monitor Frequency’ (the default is , is not called).
may be None.
- Parameters
- xfloat, ndarray, shape
The vector of decision variables at the current iteration.
- rinfofloat, ndarray, shape
Error measures and various indicators at the end of the current iteration as described in .
- statsfloat, ndarray, shape
Solver statistics at the end of the current iteration as described in .
- dataarbitrary, optional, modifiable in place
User-communication data for callback functions.
- dataarbitrary, optional
User-communication data for callback functions.
- io_managerFileObjManager, optional
Manager for I/O in this routine.
- Returns
- xfloat, ndarray, shape
The final values of the variables, .
- rinfofloat, ndarray, shape
Error measures and various indicators at the end of the final iteration as given in the table below:
Objective function value .
Norm of inactive gradient, the objective gradient over the current search space. If the problem is unconstrained, then elements – coincide. See Stopping Criteria for details.
Norm of projected direction, used in [equation], see Constrained Subproblem (NPG).
Norm of objective gradient.
Last step size () used in [equation] and [equation], see Constrained Subproblem (NPG) and Unconstrained Subproblem (CG).
Progress score, a positive value that measures the progress of the solver. A low score close to zero indicates poor progress, see [equation] in Stopping Criteria.
–
Reserved for future use.
- statsfloat, ndarray, shape
Solver statistics at the end of the final iteration as given in the table below:
Number of function evaluations performed by NPG, see Constrained Subproblem (NPG).
Number of gradient evaluations performed by NPG.
Number of function evaluations performed by CG, see Unconstrained Subproblem (CG).
Number of gradient evaluations performed by CG.
Number of function evaluations performed by LCG.
Number of gradient evaluations performed by LCG.
Number of function evaluations used by the finite difference method to estimate missing components of the gradient.
Number of iterations.
Total time spent in the solver (including user-supplied function calls).
Total time spent in user-supplied objective function.
Total time spent in user-supplied objective gradient.
–
Reserved for future use.
- Other Parameters
- ‘Defaults’valueless
This special keyword may be used to reset all options to their default values. Any value given with this keyword will be ignored.
- ‘FOAS Estimate Derivatives’str
Default
This option indicates whether to check for and estimate missing entries of the user-supplied gradient vector. Since the associated cost of estimating missing elements can be high, this option should only be used if strictly necessary. In general terms, if the gradient is not provided (in its entirety or for arbitrary points) potential degradation in the progress of the solver is to be expected. Depending on the complexity of the objective, the function may not achieve the desired optimality accuracy or even terminate with no possible further progress error = 24, it is advisable to increase the values of ‘FOAS Stop Tolerance’ and ‘FOAS Rel Stop Tolerance’ when using this option.
Missing elements from the gradient vector are estimated by finite-differences using the perturbation interval specified by the option ‘FOAS Finite Diff Interval’.
If , the entries are not checked and all derivative elements need to be provided.
Constraint: or .
- ‘FOAS Finite Diff Interval’float
Default
Specifies the relative perturbation size used to estimate a derivative using the forward (or backward) finite-difference method. Setting the value too small or too big may lead
handle_solve_bounds_foas
to terminated with = 24 or 25.Constraint: .
- ‘FOAS Iteration Limit’int
Default
This argument sets the maximum number of iterations to be performed by
handle_solve_bounds_foas
. Setting the option too low might lead to = 22.Constraint: .
- ‘FOAS Memory’int
Default
This argument specifies the maximum number of memory vectors to use in the LCG solver.
Constraint: .
- ‘FOAS Monitor Frequency’int
Default
This argument specifies the frequency on which to call the monitor function . If zero, the monitor function will not be called.
Constraint: .
- ‘FOAS Print Frequency’int
Default
This argument specifies the frequency with which to print information regarding each iteration to ‘Print File’ and/or ‘Monitoring File’. By default, it will print information of every iteration.
Constraint: .
- ‘FOAS Progress Tolerance’float
Default
Specifies the tolerance for (see [equation]) for which the function characterises a poor rate of progress given that it deems to be far from a solution. If this behaviour is persistent, then the function asserts that no substantial further progress can be achieved and the process is terminated with = 24. Setting a high tolerance can lead to misinterpret reasonable progress for unsatisfactory progress or even issue a premature stop, see [equation] in Stopping Criteria.
Constraint: .
- ‘FOAS Rel Stop Tolerance’float
Default
This argument sets the value of which specifies the relative tolerance for the convergence measures in the stopping criteria, see [equation] and [equation] in Stopping Criteria.
Constraint: .
- ‘FOAS Restart Factor’float
Default
This factor specifies the frequency with which the CG/LCG directions are replaced by the steepest descent direction (). Setting the value too small can potentially slow the convergence speed.
Constraint: .
- ‘FOAS Slow Tolerance’float
Default
Specifies the tolerance for (see [equation]) for which the function characterises a slow rate of convergence. If this behaviour is deemed permanent, then the function asserts that no substantial improvement can be achieved and the process is terminated with = 50. Setting a large tolerance can lead to incorrectly identifying a suboptimal solution, see [equation] in Stopping Criteria.
Constraint: .
- ‘FOAS Stop Tolerance’float
Default
This argument sets the value of which specifies the tolerance for the convergence measures in the stopping criteria, see [equation] and [equation] in Stopping Criteria.
Constraint: .
- ‘FOAS Tolerance Norm’str
Default
This argument specifies the norm used to measure some stopping metrics, such as optimality tolerances (see Stopping Criteria). It is possible to choose between 2-norm and ∞-norm. Solving problems using ∞-norm generally has lower computational costs than those based on 2-norm.
Constraint: or .
- ‘Infinite Bound Size’float
Default
This defines the ‘infinite’ bound in the definition of the problem constraints. Any upper bound greater than or equal to will be regarded as (and similarly any lower bound less than or equal to will be regarded as ). Note that a modification of this option does not influence constraints which have already been defined; only the constraints formulated after the change will be affected.
Constraint: .
- ‘Monitoring File’int
Default
If , the unit number for the secondary (monitoring) output. If set to , no secondary output is provided. The following information is output to the unit:
a listing of the options;
problem statistics, the iteration log and the final status as set by ‘Monitoring Level’;
the solution if set by ‘Print Solution’.
Constraint: .
- ‘Monitoring Level’int
Default
This argument sets the amount of information detail that will be printed by the solver to the secondary output. The meaning of the levels is the same as ‘Print Level’.
Constraint: .
- ‘Print File’int
Default
If , the unit number for the primary output of the solver. If , the primary output is completely turned off independently of other settings. The default value is the advisory message unit number at the time of the option’s initialization, e.g., at the initialization of the handle. The following information is output to the unit:
a listing of options if set by ‘Print Options’;
problem statistics, the iteration log and the final status from the solver as set by ‘Print Level’;
the solution if set by ‘Print Solution’.
Constraint: .
- ‘Print Level’int
Default
This argument defines how detailed information should be printed by the solver to the primary output.
Output
No output from the solver
Only the final status and the objective value
Problem statistics, one line per iteration showing the progress of the solution with respect to the convergence measures, final status and statistics
As level but each iteration line is longer and includes step length and progress measure
As level but further details of each iteration are presented
Constraint: .
- ‘Print Options’str
Default
If , a listing of options will be printed to the primary output.
Constraint: or .
- ‘Print Solution’str
Default
If , the final values of the solution vector are printed on the primary and secondary outputs.
Constraint: or .
- ‘Stats Time’str
Default
This argument allows you to turn on timings of various parts of the algorithm to give a better overview of where most of the time is spent. This might be helpful for a choice of different solving approaches. It is possible to choose between CPU and wall clock time. Choice ‘YES’ is equivalent to ‘WALL CLOCK’.
Constraint: , , or .
- ‘Task’str
Default
This argument specifies the required direction of the optimization. If , the objective function (if set) is ignored and the algorithm stops as soon as a feasible point is found. If no objective function is set, ‘Task’ reverts to ‘FEASIBLE POINT’ automatically.
Constraint: , or .
- ‘Time Limit’float
Default
This argument specifies a limit in seconds that the solver can use to solve one problem. If during the convergence check this limit is exceeded, the solver will terminate with = 23 error message.
Constraint: .
- ‘Verify Derivatives’str
Default
This argument specifies whether the function should perform numerical checks on the consistency of the user-supplied gradient function. If any discrepancies are found, = 26 is returned. It is recommended that such checks are enabled when first developing the formulation of the problem, however, the verification process results in a significant increase of the number of the function evaluations and thus it shouldn’t be used in production code.
Constraint: or .
- Raises
- NagValueError
- (errno )
has not been initialized.
- (errno )
does not belong to the NAG optimization modelling suite, has not been initialized properly or is corrupted.
- (errno )
has not been initialized properly or is corrupted.
- (errno )
This solver does not support the model defined in the handle.
- (errno )
The problem is already being solved.
- (errno )
On entry, , expected .
Constraint: must match the current number of variables of the model in the .
- (errno )
Please provide a proper function.
- (errno )
Please provide a proper function.
- (errno )
The current starting point is unusable.
- (errno )
User-provided gradient is likely to be incorrect.
- Warns
- NagAlgorithmicWarning
- (errno )
Problem was solved to an acceptable level; full accuracy was not achieved.
- (errno )
The problem seems to be unbounded and the algorithm was stopped.
- NagAlgorithmicMajorWarning
- (errno )
Maximum number of iterations reached.
- (errno )
The solver terminated after the maximum time allowed was exhausted.
- (errno )
The solver was terminated because no further progress could be achieved.
- (errno )
Invalid number detected in user-supplied function and recovery failed.
- (errno )
Invalid number detected in user-supplied gradient and recovery failed.
- NagCallbackTerminateWarning
- (errno )
User requested termination during a monitoring step.
- Notes
handle_solve_bounds_foas
solves large-scale bound-constrained nonlinear optimization problems of the formwhere is the number of decision variables, , , and are -dimensional vectors, and the nonlinear objective function is assumed to be sufficiently smooth.
The solver is a first-order method (i.e., uses only first derivatives) that has very low memory requirements and, therefore, is suitable for very large bound-constrained problems. It is based on an active-set method coupled to a nonmonotone projected gradient algorithm (NPG), nonlinear conjugate gradient method (CG) and its limited-memory variant (LCG). The active-set method is based on alternating between both solvers, the NPG step handles the box constraints and identifies a suitable search space while the CG step explores it for a solution.
For a detailed description of the algorithm see Algorithmic Details. Under standard assumptions on the problem (smoothness of the first derivative of the objective) the algorithm converges to a local solution or to a critical point.
handle_solve_bounds_foas
serves as a solver for problems stored as a handle. The handle points to an internal data structure which defines the problem and serves as a means of communication for functions in the NAG optimization modelling suite. First, the problem handle is initialized by callinghandle_init()
. Then some of the functionshandle_set_linobj()
,handle_set_quadobj()
,handle_set_nlnobj()
orhandle_set_simplebounds()
may be called to formulate the objective and to define (simple) box constraints for the problem. Once the problem is fully described, the handle may be passed to the solverhandle_solve_bounds_foas
. When the handle is no longer needed,handle_free()
should be called to destroy it and deallocate the memory held within. See the E04 Introduction for more details about the NAG optimization modelling suite.The algorithm behaviour can be modified by various options (see Other Parameters) which can be set by
handle_opt_set()
andhandle_opt_set_file()
anytime between the initialization of the handle byhandle_init()
and a call to the solver. Once the solver has finished, options may be modified for the next solve. The solver may be called repeatedly with various starting points and/or options. Option getterhandle_opt_get()
can be called to retrieve the current value of any option.The option ‘Task’ may be used to switch the problem to maximization, while ‘FOAS Estimate Derivatives’ can be used to complete missing elements from the gradient. Option ‘Verify Derivatives’ may help verify the correctness of the gradient vector before starting to solve a problem.
Several options may have significant impact on the performance of the solver. Even if the defaults were chosen to suit the majority of problems, it is recommended that you experiment in order to find the most suitable set of options for a particular problem, see Algorithmic Details and Other Parameters for further details.
- References
Dai, Y-H and Kou, C-X, 2013, A Nonlinear Conjugate Gradient Algorithm with an Optimal Property and an Improved Wolfe Line Search, SIAM J. Optim. (23(1)), 296–320
Gill, P E and Leonard, M W, 2003, Limited-Memory Reduced-Hessian Methods for Large-Scale Unconstrained Optimization, SIAM J. Optim. (14(2)), 380–401
Hager, W W and Zhang, H, 2005, A New Conjugate Gradient Method with Guaranteed Descent and an Efficient Line Search, SIAM J. Optim. (16(1)), 170–192
Hager, W W and Zhang, H, 2006, Algorithm 851: CG DESCENT, a Conjugate Gradient Method with Guaranteed Descent, ACM Trans. Math. Software (32(1)), 113–137
Hager, W W and Zhang, H, 2006, A New Active Set Algorithm for Box Constrained Optimization, SIAM J. Optim. (17(2)), 525–557
Hager, W W and Zhang, H, 2013, The Limited Memory Conjugate Gradient Method, SIAM J. Optim. (23(4)), 2150–2168
Nocedal, J and Wright, S J, 2006, Numerical Optimization, (2nd Edition), Springer Series in Operations Research, Springer, New York