メインコンテンツ

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

surrogateopt オプションを変更する

この例では、6 つの局所最小値を持つ 2 次元の問題に対して surrogateopt を実行して、大域的最小値を探索する方法を示します。この例では、より効果的に探索するためにいくつかのオプションを変更する方法を示します。

目的関数 sixmin を次のように定義します。

sixmin = @(x)(4*x(:,1).^2 - 2.1*x(:,1).^4 + x(:,1).^6/3 ...
    + x(:,1).*x(:,2) - 4*x(:,2).^2 + 4*x(:,2).^4);

関数をプロットします。

[X,Y] = meshgrid(linspace(-2.1,2.1),linspace(-1.2,1.2));
Z = sixmin([X(:),Y(:)]);
Z = reshape(Z,size(X));
surf(X,Y,Z,'EdgeColor','none')
view(-139,31)

Figure contains an axes object. The axes object contains an object of type surface.

この関数には 6 つの局所最小値と 2 つの大域的最小値があります。

各方向に [-2.1,2.1] で囲まれた領域内で 'surrogateoptplot' プロット関数を使用して、問題に対して surrogateopt を実行します。'surrogateoptplot' プロットを理解するには、surrogateoptplotを解釈する を参照してください。

rng default
lb = [-2.1,-2.1];
ub = -lb;
opts = optimoptions('surrogateopt','PlotFcn','surrogateoptplot');
[xs,fvals,eflags,outputs] = surrogateopt(sixmin,lb,ub,opts);

Figure Optimization Plot Function contains an axes object. The axes object with title Best: -1.03163 Incumbent: -0.805258 Current: 0.0541771, xlabel Number of Function Evaluations, ylabel Objective Function contains 6 objects of type line. One or more of the lines displays its values using only markers These objects represent Best, Incumbent, Random Samples, Adaptive Samples, Surrogate Reset.

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

MinSurrogatePoints オプションの値を小さく設定して、その変更によってソルバーが大域的最小値に早く到達できるかどうかを確認します。

opts.MinSurrogatePoints = 4;
[xs2,fvals2,eflags2,outputs2] = surrogateopt(sixmin,lb,ub,opts);

Figure Optimization Plot Function contains an axes object. The axes object with title Best: -1.03163 Incumbent: -1.03161 Current: -1.02506, xlabel Number of Function Evaluations, ylabel Objective Function contains 6 objects of type line. One or more of the lines displays its values using only markers These objects represent Best, Incumbent, Random Samples, Adaptive Samples, Surrogate Reset.

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

MinSurrogatePoints オプションを小さくしても、ソルバーの動作は目立った変化はありません。

MinSampleDistance オプションの値をもっと大きく設定してみてください。

opts.MinSampleDistance = 0.05;
[xs3,fvals3,eflags3,outputs3] = surrogateopt(sixmin,lb,ub,opts);

Figure Optimization Plot Function contains an axes object. The axes object with title Best: -0.896062 Incumbent: -0.0401772 Current: 24.5704, xlabel Number of Function Evaluations, ylabel Objective Function contains 12 objects of type line. One or more of the lines displays its values using only markers These objects represent Best, Incumbent, Random Samples, Adaptive Samples, Surrogate Reset.

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

MinSampleDistance オプションを変更すると、ソルバーに小さな影響があります。この設定により、サロゲートがより頻繁にリセットされ、最適な目的関数が以前よりもわずかに高くなります (悪くなります)。

並列処理を使用してみてください。sixmin 関数のバリアントである camelback 関数で、並列処理ありとなしの両方の実行時間を計測します。時間のかかる関数をシミュレートするために、camelback 関数では関数評価ごとに 1 秒の一時停止が追加されます。

type camelback
function y = camelback(x)

y = (4*x(1)^2 - 2.1*x(1)^4 + x(1)^6/3 ...
    + x(1)*x(2) - 4*x(2)^2 + 4*x(2)^4);
pause(1)
tic
opts = optimoptions('surrogateopt','UseParallel',true,'PlotFcn','surrogateoptplot');
[xs4,fvals4,eflags4,outputs4] = surrogateopt(@camelback,lb,ub,opts);

Figure Optimization Plot Function contains an axes object. The axes object with title Best: -1.03163 Incumbent: Inf Current: -1.0313, xlabel Number of Function Evaluations, ylabel Objective Function contains 6 objects of type line. One or more of the lines displays its values using only markers These objects represent Best, Incumbent, Random Samples, Adaptive Samples, Surrogate Reset.

surrogateopt stopped because it exceeded the function evaluation limit set by 
'options.MaxFunctionEvaluations'.
toc
Elapsed time is 40.111853 seconds.

同じ問題を連続して実行する場合のソルバーの時間を計測します。

opts.UseParallel = false;
tic
[xs5,fvals5,eflags5,outputs5] = surrogateopt(@camelback,lb,ub,opts);

Figure Optimization Plot Function contains an axes object. The axes object with title Best: -1.03163 Incumbent: -1.01521 Current: -1.01521, xlabel Number of Function Evaluations, ylabel Objective Function contains 6 objects of type line. One or more of the lines displays its values using only markers These objects represent Best, Incumbent, Random Samples, Adaptive Samples, Surrogate Reset.

surrogateopt stopped because it exceeded the function evaluation limit set by 
'options.MaxFunctionEvaluations'.
toc
Elapsed time is 224.924526 seconds.

時間のかかる目的関数の場合、並列処理により、結果に過度の影響を与えることなく、速度が大幅に向上します。

参考

トピック