【问题标题】:Why does the rowsize of A matter in fmincon为什么 A 的行大小在 fmincon 中很重要
【发布时间】:2019-01-23 16:02:11
【问题描述】:

我有一个 Matlab 代码,它使用 fmincon 并有一些限制。这样我就可以修改我考虑过的代码,条件矩阵 A 中的行位置是否会产生影响

我设置了一个测试文件,这样我就可以更改一些变量。事实证明,条件的位置与结果无关,但 A 和 b 中的行数起了作用。我对此感到惊讶,因为我希望 A 和 b 中只有零的行会被取消。

fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
options1 = optimoptions('fmincon','Display','off');

A=zeros(2,2); %setup A
A(2,2)=1; %x2<0
b=[0 0]'; %setup b
x = fmincon(fun,[-1,2],A,b,[],[],[],[],[],options1);x

%change condition position inside A
A=zeros(2,2);    
A(1,2)=1; %x2<0
b=[0 0]';
x = fmincon(fun,[-1,2],A,b,[],[],[],[],[],options1);x 
% no change; the position doesn´t influence fmincon

%change row size of A
A=zeros(1,2);
A(1,2)=1; %x2<0
b=[0]';
x = fmincon(fun,[-1,2],A,b,[],[],[],[],[],options1);x 
%change in x2

%increase size of A
A=zeros(10,2);
A(1,2)=1; %x2<0
b=[0 0 0 0 0 0 0 0 0 0]';
x = fmincon(fun,[-1,2],A,b,[],[],[],[],[],options1);x 
%change in x2

有人可以向我解释为什么 fmincon 会受到行号的影响吗? A 和 b 中的“正确”行号是多少?变量数还是条件数?

编辑 出于完整性的原因:

我同意不同的值是可能的,因为迭代过程。不过,我可以找到差异大于公差的情况:

在函数中添加+log(x(2)

fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2+log(x(3));
options1 = optimoptions('fmincon','Display','off');

options = optimoptions('fmincon')

A=zeros(2,3); %setup A
A(2,3)=1; %x2<0
b=[0 0]'; %setup b
x = fmincon(fun,[-1,2,1],A,b,[],[],[],[],[],options1);x

%change row size of A
A=zeros(1,3);
A(1,3)=1; %x2<0
b=[0]';
x = fmincon(fun,[-1,2,1],A,b,[],[],[],[],[],options1);x 
%change in x2

%increase size of A
A=zeros(10,3);
A(1,3)=1; %x2<0
b=[0 0 0 0 0 0 0 0 0 0]';
x = fmincon(fun,[-1,2,1],A,b,[],[],[],[],[],options1);x 
%change in x2

x =
     -0.79876      **0.49156**   2.3103e-11
x =
     -0.79921      0.49143   1.1341e-11
x =
     -0.80253      **0.50099**   5.8733e-12

Matlab 支持告诉我,A 矩阵的行数不应多于条件。每个条件都使算法变得更加困难。

【问题讨论】:

    标签: matlab optimization fminsearch


    【解决方案1】:

    请注意,fmincom 不一定给出精确的解,而是根据特定标准的解的良好近似值。

    结果的差异是合理的,因为fmincon 是一种迭代算法,这些矩阵乘法(即使主要是零)最终将以不同的结果结束。 Matlab 实际上会做这些矩阵乘法,直到他找到最好的结果。所以这些结果都是正确的,因为它们都接近解决方案。

    x =
       0.161261791015350  -0.000000117317860
    
    x =
       0.161261791015350  -0.000000117317860
    
    x =
       0.161261838607809  -0.000000077614999
    
    x =
       0.161261877075196  -0.000000096088746
    

    您的结果差异在1.0e-07 左右,考虑到您没有指定停止标准,这是一个不错的结果。您可以使用命令查看默认情况下拥有的内容

    options = optimoptions('fmincon')
    

    我的结果是

    Default properties:
                    Algorithm: 'interior-point'
               CheckGradients: 0
          ConstraintTolerance: 1.0000e-06
                      Display: 'final'
     FiniteDifferenceStepSize: 'sqrt(eps)'
         FiniteDifferenceType: 'forward'
         HessianApproximation: 'bfgs'
                   HessianFcn: []
           HessianMultiplyFcn: []
                  HonorBounds: 1
       MaxFunctionEvaluations: 3000
                MaxIterations: 1000
               ObjectiveLimit: -1.0000e+20
          OptimalityTolerance: 1.0000e-06
                    OutputFcn: []
                      PlotFcn: []
                 ScaleProblem: 0
    SpecifyConstraintGradient: 0
     SpecifyObjectiveGradient: 0
                StepTolerance: 1.0000e-10
          SubproblemAlgorithm: 'factorization'
                     TypicalX: 'ones(numberOfVariables,1)'
                  UseParallel: 0
    

    例如,我可以通过以下选项获得更接近的结果:

    options1 = optimoptions('fmincon','Display','off', 'OptimalityTolerance', 1.0e-09);
    

    结果是

    x =
       0.161262015455003  -0.000000000243997
    
    x =
       0.161262015455003  -0.000000000243997
    
    x =
       0.161262015706777  -0.000000000007691
    
    x =
       0.161262015313928  -0.000000000234186
    

    您也可以尝试使用其他标准MaxFunctionEvaluationsMaxFunctionEvaluations 等,看看是否可以得到更接近的结果...

    【讨论】:

    • 感谢您的回答。做了一个小的编辑,以表明差异可以更大。但是你提供了一些非常有趣的线索!
    • @Martin,我很高兴能帮上忙 :-)。
    猜你喜欢
    • 1970-01-01
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 2016-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多