Matlab fmincon - 找不到可行的解决方案,但没有发现错误

时间:2013-02-09 16:19:46

标签: matlab optimization error-handling

我正在使用优化功能“fmincon”,在某些情况下它不会收敛。我必须识别这些情况并采取必要的措施,但所有使用的方法都无法捕获错误,因此我继续得到错误:

No feasible solution found.

fmincon stopped because the size of the current search direction is less than
twice the default value of the step size tolerance but constraints are not 
satisfied to within the selected value of the constraint tolerance.

首先,我尝试选择函数的exitflag:如果它返回一个已知错误(-1,1,0 ...),但每次出现错误时,返回的exitflag都有一个正确的值。

[x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options);
if exitflag == 0
    do something;
end

然后我尝试使用“try / catch”结构,但在这种情况下,代码继续运行,没有错误是正确的...

try %start try/catch
    [x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options);
catch err
   disp(err.identifier);
       ... actions 
end  % end try/catch

欢迎任何建议。

ps:使用的选项是:

options = optimset(oldopts,'Display','notify', 'Algorithm','active-set', 'MaxFunEvals', 10000);

2 个答案:

答案 0 :(得分:0)

  1. oldopts中的内容是什么?
  2. is less than twice the default value of the step size tolerance建议您更改步长或公差值。有几种方法可以解决这个问题:猜测或显示迭代显示。

    optimset(oldopts,'Display','iter' ...% or 'iter-detailed'
    
  3. 找出想要更改的内容后,可以使用以下内容进行设置:

    optimset(options,'stepsize', 1e-2) % or optimset(options,'tolX', 1e-e)...
    
  4. 停止查看退出标志以抛出错误。错误是收敛或迭代问题。

  5. 问问自己算法是否能够使用图形方法收敛(如果可能)

  6. RTM:http://www.mathworks.com/help/optim/ug/when-the-solver-fails.html

答案 1 :(得分:0)

根据the docs,你应该关注exitFlag == -2而不是0来检查这种情况:

[x,fval,exitflag] = fmincon(@(x) costFunction(x,INPUTS),x0,A,b,[],[],lb,ub,[],options);
if exitflag == -2
    %// Handle non-convergence
else
    %// Converged
end