How may I specify gradient information separately from function calls with fmincon?

6 views (last 30 days)
Greetings,
Problem Specific Background:
I'm solving an optimal control problem involving a highly nonlinear differential algebraic equation (DAE) system. In the current setup the DAEs and their direct sensitivity equations are integrated using CVODES (an integrator in C). Objective function, nonlinear constraint and first derivative information is then passed to MATLAB via the MEX interface for optimization with fmincon.
This system is expensive to integrate. The objective function and constraints take about 1 minute to evaluate. Integrating the sensitivity questions for first derivatives requires 10 - 20 minutes. The overall optimization problem has 120+ optimization variables and 110+ nonlinear equality constraints and 2 nonlinear inequality constraints. Using perturbations to approximate derivative information would also be expensive.
General Background:
With fmincon the objective function and its first derivatives are specified in one function and nonlinear constraints and their first derivatives are specified in another. I believe this leads to unnecessary function evaluations. For example with a SQP method, derivative information only needs to be evaluated at the beginning of each iteration. Any additional calls of the objective function for a line search don't need derivative information. However with the current setup expensive derivative information is calculated for every line search evaluation.
Is there a way to separate the objective function and user-supplied gradient specification with fmincon?
A colleague and I have looked through the fmincon code. Our idea is to add a global variable/flag (bad programming practice - we know) that is set to true at the beginning of each iteration. The functions used to calculate the objective function and constraints would only calculate the expensive gradient information when this flag is true, and afterwords set the flag to false. Unfortunately we don't have access to the sqpLineSearch function referenced in fmincon. We don't know how to implement this strategy without slightly modifying the SQP code.
Thank you for in advance for advice regarding this endevour.
Alex Dowling
PhD Candidate, Chemical Engineering
Carnegie Mellon University

Answers (2)

Alan Weiss
Alan Weiss on 26 Mar 2014
I believe that, if you conditionalize your code so that your objective function returns only what it needs to return, then fmincon is smart enough not to call the gradient unnecessarily. For example, How to Include Derivatives shows how to use the
if nargout > 1
statement and the like.
However, you sound as if you might have written your objective and nonlinear constraints this way, and have some evidence that fmincon is making unnecessary gradient calls. Is that true? If so, please let me know, and I will investigate further.
Alan Weiss
MATLAB mathematical toolbox documentation

Weiyang Lin
Weiyang Lin on 12 Mar 2016
I was wondering about the same question. fmincon seems to ask for gradient information during line searches, but it really should not.
If there is no solution to this, I may switch back to open source optimizers such as DAKOTA, or smaller ones like PORT.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!