大家好,又见面了,我是你们的朋友全栈君。
问题描述:在使用fmincon求解局部(全局)最优值时,我们需要在fmincon函数中输入初值x0,那么这个初值是否要像原始的牛顿法一样初值必须在可行域内(严格可行)?
MATLAB在Document (https://cn.mathworks.com/help/optim/ug/fmincon.html?s_tid=doc_ta)中是这样描述的:
大译:
初始点为实值(fmincon只能用于计算实数):
1、若使用内点法,如果 Honorbounds项为真 (正常为默认真),x0不在lb和ub内时,会将其移动到严格的上下界内。(此处并未说明x0必须满足线性和非线性约束)。
2、若使用信赖域反射算法,fimincon 会将不可行的x0重新设置为满足上下界或线性等式的可行初始点。(此处并未说明x0必须满足线性和非线性不等式约束)。
3、如果使用’sqp’, 或者’active-set’算法,同内点法。
这样我们可以得出结论,初始点可以不在上界ub和下界lb内(需要满足线性和非线性不等式)。若优化问题是可行域是凸集(convex set),目标函数是凸函数(convex function),则初值的选取不会对最优值造成影响。如果目标函数是一个非凸函数,想得到全局最优,就需要在最优点附近找初值,否则可能得到局部最优。
我们举一个凸优化的例子:
objective function(convex in constraints): y = sin(x)
constraint(convex)
bounds: 2.5<=x<=7
nonlinear constraint cos(x)<=0.4;
编程:
fun = @(x)sin(x);
lb = 2.5;
ub = 7;
A = [];
b = [];
Aeq = [];
beq = [];
nonlcon = @circlecon;
[x,fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
function [c,ceq] = circlecon(x)
c = cos(x)-0.4;
ceq = [];
1、当设 x0 = 0 得到结果:
Your initial point x0 is not between bounds lb and ub; FMINCON
shifted x0 to strictly satisfy the bounds.
First-order Norm of
Iter F-count f(x) Feasibility optimality step
0 2 -3.414013e-01 0.000e+00 8.765e-01
1 4 -9.358700e-01 0.000e+00 2.093e-01 8.623e-01
2 6 -9.972133e-01 0.000e+00 7.339e-02 2.854e-01
3 8 -9.997119e-01 0.000e+00 1.023e-02 5.067e-02
4 10 -9.999938e-01 0.000e+00 1.423e-03 2.048e-02
5 12 -1.000000e+00 0.000e+00 2.205e-05 3.467e-03
6 14 -1.000000e+00 0.000e+00 1.000e-05 3.129e-05
7 16 -1.000000e+00 0.000e+00 1.006e-07 2.460e-05
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
4.7124
fval =
-1.0000
2、当设 x0 = 3 得到结果:
Iter F-count f(x) Feasibility optimality step
0 2 1.411200e-01 0.000e+00 9.778e-01
1 4 -6.305350e-01 0.000e+00 6.608e-01 8.238e-01
2 7 -9.983306e-01 0.000e+00 2.018e-01 9.463e-01
3 9 -9.860621e-01 0.000e+00 6.715e-02 2.249e-01
4 11 -9.978028e-01 0.000e+00 2.966e-02 1.009e-01
5 13 -9.999612e-01 0.000e+00 3.837e-03 5.750e-02
6 15 -9.999998e-01 0.000e+00 2.715e-04 8.133e-03
7 17 -1.000000e+00 0.000e+00 2.447e-06 6.658e-04
8 19 -1.000000e+00 0.000e+00 2.004e-08 6.083e-06
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
x =
4.7124
fval =
-1.0000
可以看到,两次得到的都是全局最优解(提示是局部最小,实际是在满足限制条件的最小)。所以,fmincon的初始值x0可以任意取,只要保证为实数就行。
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/137442.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...