필터 지우기
필터 지우기

nonlinear constraints in fmincon

조회 수: 1 (최근 30일)
Patrick Mboma
Patrick Mboma 2013년 1월 14일
Hi all,
I have a function "myfunc" to minimize subject to a set of nonlinear constraints written in a function "myconstr". The problem is that myfunc is expensive to evaluate and "myconstr" uses as one of its inputs, the output of "myfunc". How can I deal with this problem efficiently if I want to use fmincon as the optimizer?
Here are some avenues that I am looking into but I am not satisfied with them:
  1. It is possible to write myconstr so that it re-evaluates myfunc but this would slowdown things even more.
  2. do the opposite: evaluate myconstr within myfunc and use a global variable, which I am reluctant in doing.
any ideas?
Thanks,
Pat.

채택된 답변

Alan Weiss
Alan Weiss 2013년 1월 14일
There is a section in the documentation dealing with exactly this issue.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 1
Patrick Mboma
Patrick Mboma 2013년 1월 14일
This is excellent. Thank you very much Alan.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ryan Livingston
Ryan Livingston 2013년 1월 14일
You could make a little wrapper around myfunc which maintains a previous value...or values
function out = callMyfunc(arg1, arg2)
persistent oldVal;
if isempty(oldVal)
oldVal = cell(1,2);
oldVal{1} = {arg1, arg2};
oldVal{2} = myfunc(arg1, arg2);
out = oldVal{2};
return;
end
% Check to see if we've evaluated this one before
if (isequal({arg1, arg2}, oldVal{1}))
out = oldVal{2}; %Use stored value
else
out = myfunc(arg1, arg2);
end
Alternatively, I could imagine just making a handle class which maintains the old values and passing that in and out of the calls to callMyfunc if you don't like the persistent idea. Then, you attempt to record each evaluation if the lookup fails.
  댓글 수: 1
Patrick Mboma
Patrick Mboma 2013년 1월 14일
Hi Ryan,
Thank you for the answer. In my opinion, persistent, global and handle all do the same thing, some of them are just much "cleaner" than the others but there is a price to pay in all of them. For the persistent example, I anticipate that a lot of time will be spent in evaluating "isequal({arg1,arg2},oldVal)"
In my ideal world, myfunc would return both its function value and the function value of the constraints. Until I find a better workaround, I am going to implement your persistent idea and see what it gives.
Thanks,
Pat.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by