このページは機械翻訳を使用して翻訳されました。最新版の英語を参照するには、ここをクリックします。
チェックポイントファイルの操作
再起動のチェックポイント
チェックポイント ファイルには、最適化プロセスに関するデータが含まれています。チェックポイント ファイルを取得するには、CheckpointFile オプションを使用します。
チェックポイント ファイルの基本的な用途の 1 つは、最適化が途中で停止した場合に最適化を再開することです。早期停止の原因としては、停電やクラッシュなどのイベント、またはプロット関数ウィンドウで Stop ボタンを押した場合などが考えられます。
早期停止の理由が何であれ、再起動の手順は、チェックポイント ファイル名を指定して surrogateopt を呼び出すだけです。
たとえば、'check1' チェックポイント ファイルを使用して最適化を実行し、最適化の開始直後に Stop ボタンをクリックするとします。
options = optimoptions('surrogateopt','CheckpointFile','check1.mat'); lb = [-6,-8]; ub = -lb; fun = @(x)100*(x(2) - x(1)^2)^2 + (1 - x(1))^2; [x,fval,exitflag,output] = surrogateopt(fun,lb,ub,options)
Optimization stopped by a plot function or output function.
x =
0 0
fval =
1
exitflag =
-1
output =
struct with fields:
elapsedtime: 6.7739
funccount: 18
constrviolation: 0
ineq: [1×0 double]
rngstate: [1×1 struct]
message: 'Optimization stopped by a plot function or output function.'
最適化を再開するには、'check1.mat' 引数を指定して surrogateopt を呼び出します。
[x,fval,exitflag,output] = surrogateopt('check1.mat')surrogateopt stopped because it exceeded the function evaluation limit set by
'options.MaxFunctionEvaluations'.
x =
0.8299 0.6861
fval =
0.0296
exitflag =
0
output =
struct with fields:
elapsedtime: 78.7419
funccount: 200
constrviolation: 0
ineq: [1×0 double]
rngstate: [1×1 struct]
message: 'surrogateopt stopped because it exceeded the function evaluation limit set by ↵'options.MaxFunctionEvaluations'.'
最適化を拡張または監視するためのオプションの変更
予期しないイベントにより停止したかどうかに関係なく、オプションの停止基準を変更することで最適化を拡張できます。各反復で情報を表示することで最適化を監視することもできます。
メモ
surrogateopt では、変更できるオプションは限定されています。信頼性を確保するため、新しいオプションを作成するのではなく、元のオプション構造を更新します。
再起動時に変更できるオプションのリストについては、opts を参照してください。
たとえば、以前の最適化を拡張して、合計 400 回の関数評価を実行するとします。さらに、'surrogateoptplot' プロット関数を使用して最適化を監視する必要があります。
opts = optimoptions(options,'MaxFunctionEvaluations',400,... 'PlotFcn','surrogateoptplot'); [x,fval,exitflag,output] = surrogateopt('check1.mat',opts)
surrogateopt stopped because it exceeded the function evaluation limit set by
'options.MaxFunctionEvaluations'.
x =
1.0369 1.0758
fval =
0.0014
exitflag =
0
output =
struct with fields:
elapsedtime: 177.8927
funccount: 400
constrviolation: 0
ineq: [1×0 double]
rngstate: [1×1 struct]
message: 'surrogateopt stopped because it exceeded the function evaluation limit set by ↵'options.MaxFunctionEvaluations'.'
新しいプロット関数は、ソルバーが関数評価番号 200 で停止した後にのみプロット関数を開始したにもかかわらず、最適化の最初からプロットします。'surrogateoptplot' プロット関数は、最適化が停止した場所と、チェックポイント ファイルから再開された場所の評価番号も表示します。
ロバストサロゲート最適化のコード
チェックポイント ファイルが存在する場合にのみ、そのファイルからサロゲート最適化を再開するには、次のコード ロジックを使用します。この方法では、クラッシュやその他の予期しないイベントが発生した後でも最適化を継続するためのスクリプトを作成できます。
% Assume that myfun, lb, and ub exist if isfile('saveddata.mat') [x,fval,exitflag,output] = surrogateopt('saveddata.mat'); else options = optimoptions("surrogateopt","CheckpointFile",'saveddata.mat'); [x,fval,exitflag,output] = surrogateopt(myfun,lb,ub,options); end