英文:
Ending fminsearch on a whim
问题
我想能够取消fminsearch(例如使用Ctrl + C),并保留到目前为止的最佳解决方案。有没有办法做到这一点?我不确定要设置什么样的容忍度,我更愿意“凭感觉”操作,当我对解决方案满意时按下Ctrl + C。Matlab似乎毫无收益地继续下去。
英文:
Id like to be able to cancel fminsearch (eg using ctrl+c) and retaining the best solution so far. Is there a way to do this? I dont know exactly what sort of tolerance I want to set, I'd much rather "play by ear" and ctrl+c when I'm satisfied with the solution. Matlab keeps going onnn and on and on for what seems to be no gain.
答案1
得分: 3
fminsearch
可以通过输出函数和绘图函数提前终止。要从用户获取交互式需求,最直接的方式是使用不必等待代码执行完成就更新的图形界面,因此使用绘图函数是实现这一目标的最直接方式。默认的绘图函数图形中包含"Stop"和"Pause"按钮,如文档示例所示:
fminsearch(funfcn, x, optimset('PlotFcns', @optimplotfval))
如果单击"Stop"按钮,fminsearch
将返回其最新迭代的结果,并默认显示以下信息:
Optimization terminated prematurely by user.
英文:
fminsearch
can be terminated early by both output functions and plot functions. To get an interactive demand from the user, use of graphical interfaces that don't wait until code is finished executing to update is basically essential, so using a plot function would be the most straightforward way of achieving this. The default plot function figure has "Stop" and "Pause" buttons built in, as seen in the documentation's example for calling:
fminsearch(funfcn,x,optimset('PlotFcns',@optimplotfval))
If the Stop button is clicked, fminsearch
returns the result of its latest iteration and by default displays the information:
Optimization terminated prematurely by user.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论