How to pass more parameters than the existing ones to output function of fmincon?

9 ビュー (過去 30 日間)
The above link is to the documentation of Output Functions, a function that is evaluated at each individual iteration of fmincon. The parameters passed to it by default are x, optimValues and state.
1. How to pass extra parameters to this function?
2. Is there any way to compute a partial stepsize? Say numel(x) = 60 and I want to calculate stepsize norm(x(1:10)-xk(1:10)), is it possible? Because optimValues.stepsize calculates norm(x-xk) which is taking into account the entire vector.

採用された回答

Alan Weiss
Alan Weiss 2018 年 7 月 17 日
To pass external parameters, use the documented ways. You can also use persistent variables within an output function.
Alan Weiss
MATLAB mathematical toolbox documentation
  1 件のコメント
Viswanath Hariharan
Viswanath Hariharan 2018 年 7 月 17 日
I'm thinking I'll persistent variables to compute partial step size within outputfunction. But I'm using this within parfor. Will this still work? If not, how do I do it?

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2018 年 7 月 17 日
編集済み: Matt J 2018 年 7 月 17 日
Is there any way to compute a partial stepsize?
One way is to modify the example at the link you posted:
case 'iter'
% Concatenate current point and objective function
% value with history. x must be a row vector.
history.x = [history.x; x(1:10)]; %only save 10 elements
history.x(1:end-2,:)=[]; %only save the last 2 iterations
if size(history,1)>1
partial_stepsize=norm( history.x(2,:) - history.x(1,:) );
end
  6 件のコメント
Pri_Comet
Pri_Comet 2019 年 4 月 1 日
Viswanath, I fixed that by making 'history' a global variable.
Apparently, passing it to the output function that way you've done restricts its size. As a result, concatenate doesn't work as it can't add more rows -- row 1 stays at initial value and row 2 gets updated with current value.
Making it global removes this restriction. Hope this helps.
Matt J
Matt J 2019 年 4 月 1 日
Making it global removes this restriction.
That sounds doubtful to me. There shouldn't be a difference in memory limitations between global variables and other variable types.

サインインしてコメントする。

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by