主要内容

使用检查点文件

检查点重启

检查点文件包含关于优化过程的数据。要获取检查点文件,请使用CheckpointFile选择。

检查点文件的一个基本用途是在优化提前停止时恢复优化。导致过早停止的原因可能是电源故障或崩溃等事件,或当您按下停止图形函数窗口中的按钮。

无论提前停止的原因是什么,重启过程都只是调用surrogateopt使用检查点文件名。

例如,假设您使用“check1”检查点文件,然后单击停止按钮在优化开始后不久。

选择= optimoptions (“surrogateopt”“CheckpointFile”“check1.mat”);磅=(6、8);乌兰巴托=磅;趣味性= @(x)100*(x(2) - x(1)^2 + (1 - x(1))^2;[x, fval exitflag、输出]= surrogateopt(有趣,磅、乌兰巴托、期权)
优化被绘图函数或输出函数停止。x = 0 0 fval = 1 exitflag = -1 output = struct with fields: elapsedtime: 15.3330 funccount: 30 constr违规:0 ineq: [1×0 double] rngstate: [1×1 struct] message: '优化被plot函数或输出函数停止。'

请注意

检查点是需要时间的。对于那些计算时间较短的函数,这种开销尤其明显。

要恢复优化,请调用surrogateopt“check1.mat”论点。

[x, fval exitflag,输出]= surrogateopt (“check1.mat”
Surrogateopt停止,因为它超过了'options. maxfunctionevaluments '设置的函数计算限制。x = 1.0186 1.0377 fval = 3.4902 -04 exitflag = 0 output = struct with fields: elapsedtime: 181.5824 funccount: 200 constrconfliction: 0 ineq: [1×0 double] rngstate: [1×1 struct] message: 'Surrogateopt stopped,因为它超过了由'options.MaxFunctionEvaluations'设置的函数评估限制。'

将选项更改为扩展或监视优化

您可以通过更改选项中的停止条件来扩展优化,不管它是否由于不可预见的事件而停止。您还可以通过在每次迭代中显示信息来监视优化。

请注意

surrogateopt允许您只更改有限的选项集。为了可靠性,更新原始的选项结构而不是创建新的选项。

有关重新启动时可更改的选项列表,请参见选择

例如,假设您想要扩展前面的优化,以运行总共400个函数求值。此外,您希望使用“surrogateoptplot”图的功能。

选择= optimoptions(选项,“MaxFunctionEvaluations”, 400,...“PlotFcn”“surrogateoptplot”);[x, fval exitflag,输出]= surrogateopt (“check1.mat”选择)
Surrogateopt停止,因为它超过了'options. maxfunctionevaluments '设置的函数计算限制。x = 1.0186 1.0377 fval = 3.4902 -04 exitflag = 0 output = struct with fields: elapsedtime: 959.7619 funccount: 400 constrconfliction: 0 ineq: [1×0 double] rngstate: [1×1 struct] message: 'Surrogateopt stopped because it exceeded the function evaluation limit set by 'options.MaxFunctionEvaluations'.'

新的plot函数从优化的开始绘制,即使您是在求解器停止在函数计算号200之后才开始绘制plot函数的。的“surrogateoptplot”Plot函数还显示优化停止的位置和从检查点文件重新启动的位置的评估编号。

稳健代理优化代码

若要仅在检查点文件存在时才从该文件重新启动代理优化,请使用以下代码逻辑。通过这种方式,您可以编写脚本来保持优化,即使是在崩溃或其他意外事件之后。

假设存在myfun、lb和ub如果isfile (“saveddata.mat”) [x,fval,exitflag,output] = surrogateopt(“saveddata.mat”);其他的选择= optimoptions (“surrogateopt”“CheckpointFile”“saveddata.mat”);[x, fval exitflag、输出]= surrogateopt (myfun、磅、乌兰巴托、期权);结束

另请参阅

相关的话题

Baidu
map