fmincon user-supplied hessian inconsistency
1 view (last 30 days)
Show older comments
I'm using fmincon to optimize a scalar function with this abridged set of options:
options = optimset('Display', 'iter-detailed','MaxFunEvals',10000,...
'Maxiter',1000,'TolX',1e-18,'TolFun',1e-18, 'GradObj', 'on',...
'Algorithm', 'trust-region-reflective', 'Hessian',...
'user-supplied');
The following is the call to fmincon, objective function, and constraint functi n). Note that all are nested functions allowing the passing of extra parameters and unnecessary details have been left out.
[X,fval, exitflag, output, lambda, grad, hessian] = fmincon(@nestedfcn, min, [], [], [], [], lb, [], @cfcn, options);
function [c, ceq] = cfcn(min)
for i = 1:length(min)
if i ~= 9
c(i) = -25000 + abs(min(i));
else
c(i) = -75000 + abs(min(i));
end
end
ceq = [];
end
function [y, grady, H] = nestedfcn(min)
a = F ./ min;
[u,sig,vol] = truss2d(nnod,nel,e,a,conn,x,bc,f);
y = vol;
for i = 1:length(min)
grady(i) = -F(i)*L / (sig(i)^2);
for j=1:length(min)
if i==j
H(i,j) = F(i)*L / (sig(i)^3);
else
H(i,j) = 0;
end
end
end
end
The answer does not come out as it is supposed to and the Hessian is, at every point, a diagonal matrix, while fmincon outputs a non-diagonal matrix. For brevity, I've left out the specific matrices, but if it helps to arrive at a solution, I can post those as well (I think the particular values are irrelevant at the moment as I think it is an implementation issue).
0 Comments
Answers (1)
Matt J
on 11 Jul 2013
Edited: Matt J
on 11 Jul 2013
Well, I for one, can't see why FMINCON would output a diagonal Hessian from what you've posted. The reason for that would have to be in details that you've omitted. Note, however, that the matrix returned by FMINCON will not be the Hessian purely of your objective function. As explained in the documentation, it will be the Hessian of the entire Lagrangian (i.e., it includes the Hessian of your constraints). So, if there are any other constraints you've omitted in an effort to simplify presentation, that could be an explanation.
Other than that, I see one red flag issue. The use of expressions abs(min(i)) in cfcn makes your constraints non-differentiable, violating smoothness assumptions of FMINCON. If you weren't aware of differentiability requirements, I assume you could have violated them in truss2d() as well. This could explain why you're not converging to the required point, especially (but not necessarily) if some of the desired min(i) lie near zero.
If the lb(i) you haven't shown are all >=0 then you can replace abs(min(i)) with just min(i) and that would solve the issue. A better solution though would be to rewrite the constraints you've shown as ub,lb bounds. For example
c(i) = -25000 + abs(min(i));
is equivalent to -25000<=min(i)<=25000 and you can use ub(i),lb(i) to express this constraint instead, merging with any lb that you already have.
4 Comments
Matt J
on 17 Jul 2013
Edited: Matt J
on 17 Jul 2013
but my final outputted gradient is not equal to zero.
I'm not sure whether the gradient output is the gradient of the objective function or of the Lagrangian. You can experiment with a few simple problems to check. Either way, even at an unconstrained minimum, the gradient wouldn't be exactly zero. There are other stopping criteria besides the first order optimality measure that FMINCON uses to decide whether to stop iterating. There's TolX, TolFun, etc... It certainly won't wait until you land smack dab on top of an optimal solution.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!