メインコンテンツ

このページは機械翻訳を使用して翻訳されました。最新版の英語を参照するには、ここをクリックします。

多次元関数のサロゲート最適化

この例では、最小化問題における 3 つの推奨ソルバーの動作を示します。目的関数は multirosenbrock 関数です。

type multirosenbrock
function F = multirosenbrock(x)
% This function is a multidimensional generalization of Rosenbrock's
% function. It operates in a vectorized manner, assuming that x is a matrix
% whose rows are the individuals.

% Copyright 2014 by The MathWorks, Inc.

N = size(x,2); % assumes x is a row vector or 2-D matrix
if mod(N,2) % if N is odd
    error('Input rows must have an even number of elements')
end

odds  = 1:2:N-1;
evens = 2:2:N;
F = zeros(size(x));
F(:,odds)  = 1-x(:,odds);
F(:,evens) = 10*(x(:,evens)-x(:,odds).^2);
F = sum(F.^2,2);

multirosenbrock 関数には、点 [1,1,...,1] で 0 という単一の局所的最小値があります。最大関数数がわずか 200 という難しい状況で、一般的な非線形問題に対する 3 つの最良のソルバーが、この 20 次元関数に対してどれだけうまく機能するかを確認します。

問題を設定します。

N = 20; % any even number
mf = 200; % max fun evals
fun = @multirosenbrock;
lb = -3*ones(1,N);
ub = -lb;
rng default
x0 = -3*rand(1,N);

surrogateopt のオプションを設定して、関数評価を 200 回だけ使用し、ソルバーを実行します。

options = optimoptions('surrogateopt','MaxFunctionEvaluations',mf);
[xm,fvalm,~,~,pop] = surrogateopt(fun,lb,ub,options);

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: 8.84977, xlabel Iteration, ylabel Function value contains an object of type scatter. This object represents Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 
'options.MaxFunctionEvaluations'.

最適化を監視するためのプロット関数を含む、patternsearch にも同様のオプションを設定します。

psopts = optimoptions('patternsearch','PlotFcn','psplotbestf','MaxFunctionEvaluations',mf);
[psol,pfval] = patternsearch(fun,x0,[],[],[],[],lb,ub,[],psopts);
patternsearch stopped because it exceeded options.MaxFunctionEvaluations.

Figure Pattern Search contains an axes object. The axes object with title Best Function Value: 774.8, xlabel Iteration, ylabel Function value contains an object of type scatter.

fmincon にも同様のオプションを設定します。

opts = optimoptions('fmincon','PlotFcn','optimplotfval','MaxFunctionEvaluations',mf);
[fmsol,fmfval,eflag,fmoutput] = fmincon(fun,x0,[],[],[],[],lb,ub,[],opts);

Figure Optimization Plot Function contains an axes object. The axes object with title Current Function Value: 493.704, xlabel Iteration, ylabel Function value contains an object of type scatter.

Solver stopped prematurely.

fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 2.000000e+02.

この極めて制限された数の関数評価では、surrogateopt ソリューションが 0 の真の最小値に最も近くなります。

table(fvalm,pfval,fmfval,'VariableNames',{'surrogateopt','patternsearch','fmincon'})
ans=1×3 table
    surrogateopt    patternsearch    fmincon
    ____________    _____________    _______

       8.8498           774.8         493.7 

さらに 200 回の関数評価を実行すると、他のソルバーが真の解に急速に近づく一方で、surrogateopt では大幅な改善が見られないことがわかります。ソルバーを以前のソリューションから再起動します。これにより、各最適化に 200 回の関数評価が追加されます。

options = optimoptions(options,'InitialPoints',pop);
[xm,fvalm,~,~,pop] = surrogateopt(fun,lb,ub,options);

Figure Optimization Plot Function contains an axes object. The axes object with title Best Function Value: 8.37539, xlabel Iteration, ylabel Function value contains an object of type scatter. This object represents Best function value.

surrogateopt stopped because it exceeded the function evaluation limit set by 
'options.MaxFunctionEvaluations'.
[psol,pfval] = patternsearch(fun,psol,[],[],[],[],lb,ub,[],psopts);
patternsearch stopped because it exceeded options.MaxFunctionEvaluations.

Figure Pattern Search contains an axes object. The axes object with title Best Function Value: 326.729, xlabel Iteration, ylabel Function value contains an object of type scatter.

[fmsol,fmfval,eflag,fmoutput] = fmincon(fun,fmsol,[],[],[],[],lb,ub,[],opts);

Figure Optimization Plot Function contains an axes object. The axes object with title Current Function Value: 8.59887, xlabel Iteration, ylabel Function value contains an object of type scatter.

Solver stopped prematurely.

fmincon stopped because it exceeded the function evaluation limit,
options.MaxFunctionEvaluations = 2.000000e+02.
table(fvalm,pfval,fmfval,'VariableNames',{'surrogateopt','patternsearch','fmincon'})
ans=1×3 table
    surrogateopt    patternsearch    fmincon
    ____________    _____________    _______

       8.3754          326.73        8.5989 

参考

トピック