2
votes

I am trying to follow the advice given here

http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-7.html

but I am having trouble. I have a complicated objective to minimize subject to complicated nonlinear constraints, all of which are functions of my 3 choice variables, and a wide variety of parameters. My script that starts everything looks like this:

% define a bunch of parameters
gamma= .2;
beta = .3; %
x0=[.5 .5 .5];
%etc
solution = nested_minimization_program(x0,gamma,beta)

Nested_minimization_program looks like this:

function out = nest_minimization-program(x0,gamma,beta)
options = optimset('GradObj','on');
out = fmincon(@objective,x0,[],[],[],[],[0 0 0],[1 1 1],@nonlin,options)
 function [obj obj_gradient] = objective(x)
   [obj obj_gradient] = complicated_objective(x,gamma,beta);
 end
 function [ineq_constriant eq_constraint] = nonlin(x)
  [ineq_constriant eq_constraint] = complicated_constaints(x,beta,gamma)
 end
end

Complicated_objective is a file that returns the value of the objective for its first argument, and the value of anlaytical gradient for its second. Complicated_constaints returns a vector of nonlinear inequality constraints for its first argument, and a vector of nonlinear equality constraints for its second.

The reason to do this is so that I can use the @objective and @nonlin syntax for fmincon; objective and nonlin are only functions of x, not of the parameters, because they are subfunctions of a function that has been passed the parameters already. I believe this is the form I should use in order to pass the gradient and the nonlinear constraints on to fmincon. My problem is that when I run this code, I get the following error

Warning: Trust-region-reflective algorithm does not solve this type of problem, using active-set algorithm. You could also try the interior-point or sqp algorithms: set the Algorithm option to 'interior-point' or 'sqp' and rerun. For more help, see Choosing the Algorithm in the documentation.

IE, for some reason fmincon is leaving the Trust-region-reflective algorithm and going to active set, which does not make use of my analytical gradient. The requirements for fmincon to use analytical gradients is, according to http://www.mathworks.com/help/toolbox/optim/ug/brhkghv-3.html,

Write code that returns: The objective function (scalar) as the first output

The gradient (vector) as the second output

Set the GradObj option to 'on' with optimset.

objective returns a scalar value of the objective and a gradient as required, Gradobj is turned on, so I don't see my problem.

1
fmincon usually wants an answer it can start with: (out = fmincon(@objective,X0,[],[],[],[0 0 0],[1 1 1],@nonlin,options) X0 can't be null... (at least not in my brief experience using the optimization toolbox)Rasman
You are of course correct - if I ran the code as written above, it wouldn't even run, never mind not use the algorithm I want. In my actual code the initial guess is supplied, I will update the question to reflect that.Dennis

1 Answers

0
votes

I got some help from the Matlab Usenet group, and it was revealed to me that the trust-region methods don't actually support non-linear constraints, so it is not an error in my code at all. They reccomend rewriting to use the 'interior-point' algorithm, which has its own issues, but at least this problem has been solved.