Main Content

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

MultiStart の開始点を指定する、問題ベース

問題ベースのアプローチで MultiStart を使用して問題を解決する場合、次のいずれかまたは両方の手法を使用して開始点を指定できます。

  • optimvalues 関数を使用して OptimizationValues オブジェクトのベクトルを作成します。このベクトルを x0 引数として solve に渡します。

  • solve を呼び出すときに、 MinNumStartPoints 名前値引数を設定します。MinNumStartPointsx0 のポイント数を超える場合、solve は問題の範囲内でランダムに追加のポイントを作成します。

初期点のベクトル

この例では、-10 から 10 までの整数値で構成される変数 x と、–5/2 から 5/2 までの半整数値で構成される変数 y のグリッドとして初期ポイント ベクトルを作成します。optimvalues 関数には問題が必要なので、目的関数 peaks(x,y) を使用して最適化問題を作成します。

optimvalues のポイントは、ポイント数の次元 (インデックス) が最後になるように指定する必要があります。例えば、nポイントを持つスカラーtの複数の値を指定するには、次のように指定します。

[t(1)t(2)...t(n)] (これは 1 行 n 列で、n が最後のインデックスです。)

長さ2のベクトル変数wに複数の値を与えるには、次のように指定します。

[w(1,1)w(1,2)w(1,3)w(1,n)w(2,1)w(2,2)w(2,3)w(2,n)] (これは 2 行 n 列で、n が最後のインデックスです。)

この規則は行ベクトルにも当てはまります。つまり、複数の行ベクトルを、それぞれが列ベクトルであるかのように指定します。

2行3列の行列Aの複数の値を与えるには、次のように指定します。

[A(1,1,1)A(1,2,1)A(1,3,1)A(2,1,1)A(2,2,1)A(2,3,1)][A(1,1,2)A(1,2,2)A(1,3,2)A(2,1,2)A(2,2,2)A(2,3,2)][A(1,1,n)A(1,2,n)A(1,3,n)A(2,1,n)A(2,2,n)A(2,3,n)](これは 2 x 3 x n で、n が最後のインデックスです。)

この例では、スカラー t の例と同様に、スカラー変数 xy の複数の値を行ベクトルとして指定するようにしてください。

x = optimvar("x",LowerBound=-10,UpperBound=10);
y = optimvar("y",LowerBound=-5/2,UpperBound=5/2);
prob = optimproblem(Objective=peaks(x,y));
xval = -10:10;
yval = (-5:5)/2;
[x0x,x0y] = meshgrid(xval,yval);
% Convert x0x and x0y to row vectors for optimvalues
x0 = optimvalues(prob,x=x0x(:)',y=x0y(:)');

x0 内のすべての点から始めて最小化問題を解きます。

ms = MultiStart;
[sol,fval,eflag,output] = solve(prob,x0,ms)
Solving problem using MultiStart.

MultiStart completed the runs from all start points. 

All 231 local solver runs converged with a positive local solver exitflag.
sol = struct with fields:
    x: 0.2283
    y: -1.6255

fval = -6.5511
eflag = 
    LocalMinimumFoundAllConverged

output = struct with fields:
                funcCount: 2230
         localSolverTotal: 231
       localSolverSuccess: 231
    localSolverIncomplete: 0
    localSolverNoSolution: 0
                  message: 'MultiStart completed the runs from all start points. ...'
                    local: [1x1 struct]
      objectiveDerivative: "reverse-AD"
     constraintDerivative: "closed-form"
             globalSolver: 'MultiStart'
                   solver: 'fmincon'

ランダムスタートポイント

もう一度問題を解きます。今回は 25 個のランダムな初期点から MultiStart を使用します。solve の初期点を [–1,2] に設定します。

init.x = -1;
init.y = 2;
rng default % For reproducibility
[sol2,fval2,eflag2,output2] = solve(prob,init,ms,MinNumStartPoints=25)
Solving problem using MultiStart.

MultiStart completed the runs from all start points. 

All 25 local solver runs converged with a positive local solver exitflag.
sol2 = struct with fields:
    x: 0.2283
    y: -1.6255

fval2 = -6.5511
eflag2 = 
    LocalMinimumFoundAllConverged

output2 = struct with fields:
                funcCount: 161
         localSolverTotal: 25
       localSolverSuccess: 25
    localSolverIncomplete: 0
    localSolverNoSolution: 0
                  message: 'MultiStart completed the runs from all start points. ...'
                    local: [1x1 struct]
      objectiveDerivative: "reverse-AD"
     constraintDerivative: "closed-form"
             globalSolver: 'MultiStart'
                   solver: 'fmincon'

今回は、MultiStart は 25 個の疑似ランダム初期ポイントから実行されます。解は以前と同じです。

参考

| |

関連するトピック