0

当目标函数超过某个值(最小值或最大值)时如何停止 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);
4

1 回答 1

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;

查看完整的OutputFcn 文档

于 2019-04-07T09:10:54.000 回答