【问题标题】:Stop fminsearch when objective function reach certain value当目标函数达到一定值时停止 fminsearch
【发布时间】:2019-04-07 17:10:54
【问题描述】:

当目标函数超过某个值(最小值或最大值)时如何停止 fminsearch

options = optimset('MaxFunEvals',9999);
[x,fval,exitflag,output]  =  fminsearch(@(var)objectiveFunction(variables), changingParameters,options);

如果我达到某个目标函数值(例如 1000)[在 9999 次迭代中],如何停止函数

我试过'TolFun',我不确定这是否正确

options = optimset('MaxFunEvals',999,'TolFun',1000);
[x,fval,exitflag,output]  =  fminsearch(@(var)objectiveFunction(variables), changingParameters,options);

【问题讨论】:

    标签: matlab optimization fminsearch


    【解决方案1】:

    您可以通过在options.OutputFcn 输入结构中放置适当的函数来手动停止搜索过程。这个函数在搜索的每次迭代中被调用,并允许返回信号表明搜索将被终止。例如,您可以定义

    function stop = custom_stop_fun(~, optimValues, ~)
    if optimValues.fval >= 1000
        stop = true;
    else
        stop = false;
    end
    end
    

    然后通过设置

    options.OutputFcn = @custom_stop_fun;
    

    查看完整的OutputFcndocumentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-20
      • 1970-01-01
      • 2015-12-29
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多