メインコンテンツ

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

最大世代数の設定と世代停止

MaxGenerations オプションは、遺伝的アルゴリズムが実行する世代の最大数を決定します。アルゴリズムの停止条件 を参照してください。MaxGenerations を増やすと最終結果が改善される可能性があります。関連する MaxStallGenerations オプションは、ga が進行しているかどうかを確認するために調べるステップ数を制御します。MaxStallGenerations を増やすと、アルゴリズムがより良い解決策を見つけるためにより多くの関数評価を必要とするときに、ga を続行できるようになります。

たとえば、デフォルトのパラメーターを持つ 10 個の変数を使用して rastriginsfcn を最適化します。ソルバーが最小値 0 に近づくにつれてどのように進行するかを観察するには、関数の対数を最適化します。

rng default % For reproducibility
fun = @(x)log(rastriginsfcn(x));
nvar = 10;
options = optimoptions('ga','PlotFcn',"gaplotbestf");
[x,fval] = ga(fun,nvar,[],[],[],[],[],[],[],options)
ga stopped because the average change in the fitness value is less than options.FunctionTolerance.

Figure Genetic Algorithm contains an axes object. The axes object with title Best: 1.45396 Mean: 4.52748, xlabel Generation, ylabel Fitness value contains 2 objects of type scatter. These objects represent Best fitness, Mean fitness.

x = 1×10

   -0.0495   -0.0670   -0.0485    0.0174   -0.0087    0.0275   -0.0383    0.0620   -1.0047   -0.0298

fval = 
1.4540

ga が原点の最適点に近づくと、停止します。より良いソリューションを得るには、ストール世代制限を 500 に設定し、世代制限を 1000 に設定します。

options = optimoptions(options,'MaxStallGenerations',500,'MaxGenerations',1000);
rng default % For reproducibility
[x,fval] = ga(fun,nvar,[],[],[],[],[],[],[],options)
ga stopped because it exceeded options.MaxGenerations.

Figure Genetic Algorithm contains an axes object. The axes object with title Best: -3.14667 Mean: -1.31642, xlabel Generation, ylabel Fitness value contains 2 objects of type scatter. These objects represent Best fitness, Mean fitness.

x = 1×10

    0.0025   -0.0039    0.0021   -0.0030   -0.0053    0.0033    0.0080    0.0012    0.0006    0.0088

fval = 
-3.1467

今回は、ソルバーは真の最小値にさらに近づきます。

参考

トピック