如何将 trust-region-reflective algorithm 换为 active-active set algorithmm

matlab中optimset函数的使用问题_matlab吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:72,837贴子:
matlab中optimset函数的使用问题收藏
[H,m]=solutionH(address);
% H为5*5的矩阵,m=5C=zeros(m,1);
lb=zeros(m,1);Aeq=ones(1,m);beq=1;K=quadprog(H,C,[],[],Aeq,beq,lb);运行到最后一行的时候提示Warning: Trust-region-reflective algorithm does not solve thistype of problem, using active-set algorithm. For more help,see Choosing the Algorithm in the documentation. & In quadprog at 368
In solutionK at 10 Warning: Your current settings will run a different algorithm(interior-point-convex) in a future release. & In quadprog at 372
In solutionK at 10 然后我把matlab的代码改为[H,m]=solutionH(address);C=zeros(m,1);lb=zeros(m,1);Aeq=ones(1,m);beq=1;options = optimset(trust-region-reflective,active-set);K=quadprog(H,C,[],[],Aeq,beq,lb,[],[],options);结果又提示Error using trust (line 27)Not enough input arguments.Error in solutionK (line 10)options = optimset(trust-region-reflective,active-set)我就没招了,难道是optimset函数的用法有问题?我是按照help里的弄的啊。请教大神指导,非常感谢!
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或查看: 2020|回复: 8|关注: 0
fmincon函数优化问题
本帖最后由 猴与云 于
20:10 编辑
我运行下面fmincon函数时一直找不到合适的解,想问问大家这种情况一般错误在哪?怎么解决?options=optimset('Display','iter','TolCon',1e-12,'TolX',1e-12);
[Z,fval]=fmincon(@RPM_obj,Z0,[],[],[],[],[],[],@RPM_con,options);复制代码下面是错误提示:
Warning: The default trust-region-reflective algorithm does not solve problems with the constraints you
have specified. FMINCON will use the active-set algorithm instead. For information on applicable
algorithms, see Choosing the Algorithm in the documentation.
& In fmincon at 486
&&In Low_RPM at 85
& && && && && && && && && && &&&Max& &&&Line search&&Directional&&First-order
Iter F-count& && &&&f(x)& &constraint& &steplength& &derivative& &optimality Procedure
& & 0& & 510& && &9.71932& &3.703e+021& && && && && && && && && && && && && &&&Infeasible start point
No feasible solution found.
fmincon stopped because the size of the current search direction is less than
twice the selected value of the step size tolerance but constraints are not
satisfied to within the selected value of the constraint tolerance.
&stopping criteria details&
Elapsed time is 2.139043 seconds.
Optimization stopped because the norm of the current search direction , 0.0,
is less than 2*options.TolX = 1.2, but the maximum constraint
violation, 3.1, exceeds options.TolCon = 1.2.
Optimization Metric& && && && && && && && && && && && && && && && &Options
norm(search direction) =&&0.00e+000& && && && && && && && & TolX =&&1e-012 (selected)
max(constraint violation)&&=&&3.70e+021& && && && && && & TolCon =&&1e-012 (selected)
关注者: 80
一般是初值不合理
一般是初值不合理
有可能是我的非线性约束有问题吗?我现在在排查看有没有非线性约束那出错。嗯嗯,谢谢版主,让我知道了另一个有可能出错的地方,
一般是初值不合理
版主我想问问您如何判断fmincon函数的初值满足非线性约束,因为我的初值是通过ga函数得到的,随机性比较大,ga搜索到初始值后用fmincon老是得不到合适的解,麻烦版主了,谢谢
关注者: 80
版主我想问问您如何判断fmincon函数的初值满足非线性约束,因为我的初值是通过ga函数得到的,随机性比较 ...
那你在 ga 优化时,也该指定相同的非线性约束,这样,才可能保证 ga 的解是满足非线性约束的
本帖最后由 猴与云 于
16:13 编辑
那你在 ga 优化时,也该指定相同的非线性约束,这样,才可能保证 ga 的解是满足非线性约束的 ...
版主,我按照你指点的思路又找了一次初值,但是找到了之后用fmincon函数优化还是迭代50次后就停止找不到合适的解,想问问版主有没有对初值不敏感或者不需要初始值的精确优化算法?我知道智能优化算法不需要初值,但是很容易得到局部最优,所以想问问还有啥其他的,
关注者: 80
版主,我按照你指点的思路又找了一次初值,但是找到了之后用fmincon函数优化还是迭代50次后就停止找不到合 ...
如果是matlab的话,我一般会考虑 GlobalSearch 或者 MultiStart
如果是matlab的话,我一般会考虑 GlobalSearch 或者 MultiStart
我用了GlobalSearch,但是效果也不是很好,还是找不到合适的解,感觉和fmincon函数效果差不多, options=optimset(options,'Display','iter','MaxIter',400,'TolFun',1e-4,'TolX',1e-4);
problem = createOptimProblem('fmincon','x0',Z0, 'objective','RPM_obj','lb',[],'ub',[], 'nonlcon','RPM_con1','options',options);
gs = GlobalS
[Z,f] = run(gs,problem);
复制代码这是我最后调用GlobalSearch函数。
如果是matlab的话,我一般会考虑 GlobalSearch 或者 MultiStart
您好!请教您一个matlab的优化问题,我现在做一个关于fmincon的优化的通用版,不管每次输入什么参数,边界条件和初始值都可以自己设置,这样的能实现吗?用GlobalSearch 或者 MultiStart能实现吗
站长推荐 /2
Powered by关于数学规划
数学规划模型是优化模型的一种,包括线性规划模型(目标函数和约束条件都是线性函数的优化问题);
非线性规划模型(目标函数或者约束条件是非线性的函数); 整数规划(决策变量是整数值得规划问题);
多目标规划(具有多个目标函数的规划问题) ;目标规划(具有不同优先级的目标和偏差的规划问题)
动态规划(求解多阶段决策问题的最优化方法) 。数学规划模型相对比较好理解,关键是要能熟练地求出模型的解。
以下是解线性规划模型的方法:
1.线性规划问题
线性规划问题的标准形式为:
sub.to:A*x&b
其中f、x、b、beq、lb、ub为向量,A、Aeq为矩阵。
MATLAB中,线性规划问题(Linear Programming)的求解使用的是函数linprog。
函数 linprog
linprog(f,A,b)&&&
%求min f ' *x&&&
sub.to A*x&=b&&
线性规划的最优解。
linprog(f,A,b,Aeq,beq)&&&
%等式约束 ,若没有不等式约束 ,则A=[ ],b=[ ]。
linprog(f,A,b,Aeq,beq,lb,ub)&&&
%指定x的范围 ,若没有等式约束 ,则Aeq=[ ],beq=[ ]
linprog(f,A,b,Aeq,beq,lb,ub,x0)&&&
%设置初值x0
linprog(f,A,b,Aeq,beq,lb,ub,x0,options)&&&&
% options为指定的优化参数
[x,fval] =
linprog(…)&&& %
返回目标函数最优值,即fval= f ' *x。
[x,lambda,exitflag] =
linprog(…)&&& %
lambda为解x的Lagrange乘子。
[x, lambda,fval,exitflag] =
linprog(…)&&& %
exitflag为终止迭代的错误条件。
[x,fval, lambda,exitflag,output] =
linprog(…)&&& %
output为关于优化的一些信息
若exitflag&0表示函数收敛于解x,exitflag=0表示超过函数估值或迭代的最大数字,exitflag&0表示函数不收敛于解x;若lambda=lower
表示下界lb,lambda=upper表示上界ub,lambda=ineqlin表示不等式约束,lambda=eqlin表示等式约束,lambda中的非0元素表示对应的约束是有效约束;output=iterations表示迭代次数,output=algorithm表示使用的运算规则,output=cgiterations表示PCG迭代次数。
2.非线性规划问题
利用函数fminbnd求有约束的一元函数的最小值
格式&&& x =
fminbnd(fun,x1,x2)&&
fminbnd(fun,x1,x2,options)&&&
% options为指定优化参数选项
[x,fval] =
fminbnd(…)&&& %
fval为目标函数的最小值
[x,fval,exitflag] =
fminbnd(…)&&&
%xitflag为终止迭代的条件
[x,fval,exitflag,output] =
fminbnd(…)&&& %
output为优化信息
利用函数fminsearch求无约束多元函数最小值
函数&& fminsearch
格式&& x =
fminsearch(fun,x0)&&&
%x0为初始点,fun为目标函数的表达式字符串或MATLAB自定义函数的函数柄。
fminsearch(fun,x0,options)&&&
% options查optimset
[x,fval] =
fminsearch(…)&&&
%最优点的函数值
[x,fval,exitflag] =
fminsearch(…)&&&
% exitflag与单变量情形一致
[x,fval,exitflag,output] =
fminsearch(…)&&
%output与单变量情形一致
注意:fminsearch采用了Nelder-Mead型简单搜寻法。
利用函数fminunc求多变量无约束函数最小值
函数&& fminunc
格式&& x =
fminunc(fun,x0)&&&
%返回给定初始点x0的最小函数值点
fminunc(fun,x0,options)&&&
% options为指定优化参数
[x,fval] =
fminunc(…)&&&
%fval最优点x处的函数值
[x,fval,exitflag] =
fminunc(…)&&& %
exitflag为终止迭代的条件,与上同。
[x,fval,exitflag,output] =
fminunc(…)&&&
%output为输出优化信息
[x,fval,exitflag,output,grad] =
fminunc(…)&&& %
grad为函数在解x处的梯度值
[x,fval,exitflag,output,grad,hessian] =
fminunc(…)&&&
%目标函数在解x处的海赛(Hessian)值
注意:当函数的阶数大于2时,使用fminunc比fminsearch更有效,但当所选函数高度不连续时,使用fminsearch效果较好。
利用fmincon求线性有约束的多元函数的最小值
函数&& fmincon
格式&& x =
fmincon(fun,x0,A,b)
x = fmincon(fun,x0,A,b,Aeq,beq)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
[x,fval] = fmincon(…)
[x,fval,exitflag] = fmincon(…)
[x,fval,exitflag,output] = fmincon(…)
[x,fval,exitflag,output,lambda] = fmincon(…)
[x,fval,exitflag,output,lambda,grad] = fmincon(…)
[x,fval,exitflag,output,lambda,grad,hessian] = fmincon(…)
函数&& fminbnd
格式&& x =
fminbnd(fun,x1,x2)&&&
%返回自变量x在区间 上函数fun取最小值时x值,fun为目标函数的表达式字符串或MATLAB自定义函数的函数柄。
fminbnd(fun,x1,x2,options)&&&
% options为指定优化参数选项
[x,fval] =
fminbnd(…)&&& %
fval为目标函数的最小值
[x,fval,exitflag] =
fminbnd(…)&&&
%xitflag为终止迭代的条件
[x,fval,exitflag,output] =
fminbnd(…)&&& %
output为优化信息
若参数exitflag&0,表示函数收敛于x,若exitflag=0,表示超过函数估计值或迭代的最大数字,exitflag&0表示函数不收敛于x;若参数output=iterations表示迭代次数,output=funccount表示函数赋值次数,output=algorithm表示所使用的算法。
3.二次规划问题
函数&& quadprog
格式&& x =
quadprog(H,f,A,b)&&&
%其中H,f,A,b为标准形中的参数,x为目标函数的最小值。
quadprog(H,f,A,b,Aeq,beq)&&&
�q,beq满足等约束条件 。
quadprog(H,f,A,b,Aeq,beq,lb,ub)&&&
% lb,ub分别为解x的下界与上界。
quadprog(H,f,A,b,Aeq,beq,lb,ub,x0)&&&
%x0为设置的初值
quadprog(H,f,A,b,Aeq,beq,lb,ub,x0,options)&&&
% options为指定的优化参数
[x,fval] =
quadprog(…)&&&
%fval为目标函数最优值
[x,fval,exitflag] =
quadprog(…)&&& %
exitflag与线性规划中参数意义相同
[x,fval,exitflag,output] =
quadprog(…)&&& %
output与线性规划中参数意义相同
[x,fval,exitflag,output,lambda] =
quadprog(…)&&& %
lambda与线性规划中参数意义相同
极小化极大(Minmax)问题
函数&& fminimax
格式&& x = fminimax(fun,x0)
x = fminimax(fun,x0,A,b)
x = fminimax(fun,x0,A,b,Aeq,beq)
x = fminimax(fun,x0,A,b,Aeq,beq,lb,ub)
x = fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)
x = fminimax(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)
[x,fval,maxfval] = fminimax(…)
[x,fval,maxfval,exitflag] = fminimax(…)
[x,fval,maxfval,exitflag,output] = fminimax(…)
[x,fval,maxfval,exitflag,output,lambda] = fminimax(…)
5.多目标规划问题
函数&& fgoalattain
格式&& x =
fgoalattain(fun,x0,goal,weight)
x = fgoalattain(fun,x0,goal,weight,A,b)
x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq)
x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub)
fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon)
fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon,options)
[x,fval] = fgoalattain(…)
[x,fval,attainfactor] = fgoalattain(…)
[x,fval,attainfactor,exitflag] = fgoalattain(…)
[x,fval,attainfactor,exitflag,output] = fgoalattain(…)
[x,fval,attainfactor,exitflag,output,lambda] =
fgoalattain(…)
6.最小二乘最优问题
有约束线性最小二乘
格式&& x =
lsqlin(C,d,A,b)&&&
%求在约束条件 下,方程Cx = d的最小二乘解x。
lsqlin(C,d,A,b,Aeq,beq)&&&
�q、beq满足等式约束 ,若没有不等式约束,则设A=[ ],b=[ ]。
lsqlin(C,d,A,b,Aeq,beq,lb,ub)&&&
%lb、ub满足 ,若没有等式约束,则Aeq=[ ],beq=[ ]。
lsqlin(C,d,A,b,Aeq,beq,lb,ub,x0)&&&
% x0为初始解向量,若x没有界,则lb=[ ],ub=[ ]。
lsqlin(C,d,A,b,Aeq,beq,lb,ub,x0,options)&&&
% options为指定优化参数
[x,resnorm] =
lsqlin(…)&&& %
resnorm=norm(C*x-d)^2,即2-范数。
[x,resnorm,residual] =
lsqlin(…)&&&
%residual=C*x-d,即残差。
[x,resnorm,residual,exitflag] =
lsqlin(…)&&&
%exitflag为终止迭代的条件
[x,resnorm,residual,exitflag,output] =
lsqlin(…)&&& %
output表示输出优化信息
[x,resnorm,residual,exitflag,output,lambda] =
lsqlin(…)&&& %
lambda为解x的Lagrange乘子
非线性数据(曲线)拟合
函数&& lsqcurvefit
格式&& x =
lsqcurvefit(fun,x0,xdata,ydata)
x = lsqcurvefit(fun,x0,xdata,ydata,lb,ub)
x = lsqcurvefit(fun,x0,xdata,ydata,lb,ub,options)
[x,resnorm] = lsqcurvefit(…)
[x,resnorm,residual] = lsqcurvefit(…)
[x,resnorm,residual,exitflag] = lsqcurvefit(…)
[x,resnorm,residual,exitflag,output] = lsqcurvefit(…)
[x,resnorm,residual,exitflag,output,lambda] = lsqcurvefit(…)
非线性最小二乘
函数&& lsqnonlin
格式&& x =
lsqnonlin(fun,x0)&&&
%x0为初始解向量;fun为
,i=1,2,…,m,fun返回向量值F,而不是平方和值,平方和隐含在算法中,fun的定义与前面相同。
lsqnonlin(fun,x0,lb,ub)&&&&
%lb、ub定义x的下界和上界: 。
lsqnonlin(fun,x0,lb,ub,options)&&&
%options为指定优化参数,若x没有界,则lb=[ ],ub=[ ]。
[x,resnorm] =
lsqnonlin(…)&&&&
% resnorm=sum(fun(x).^2),即解x处目标函数值。
[x,resnorm,residual] =
lsqnonlin(…)&&&
% residual=fun(x),即解x处fun的值。
[x,resnorm,residual,exitflag] =
lsqnonlin(…)&&&&
%exitflag为终止迭代条件。
[x,resnorm,residual,exitflag,output] =
lsqnonlin(…)&&&
%output输出优化信息。
[x,resnorm,residual,exitflag,output,lambda] =
lsqnonlin(…)&&&
%lambda为Lagrage乘子。
[x,resnorm,residual,exitflag,output,lambda,jacobian]
=lsqnonlin(…)&&&
%fun在解x处的Jacobian矩。
非负线性最小二乘
函数&& lsqnonneg
格式&& x =
lsqnonneg(C,d)&&&
%C为实矩阵,d为实向量
lsqnonneg(C,d,x0)&&&
% x0为初始值且大于0
lsqnonneg(C,d,x0,options)&&&
% options为指定优化参数
[x,resnorm] =
lsqnonneg(…)&&&
% resnorm=norm (C*x-d)^2
[x,resnorm,residual] =
lsqnonneg(…)&&&
%residual=C*x-d
[x,resnorm,residual,exitflag] = lsqnonneg(…)
[x,resnorm,residual,exitflag,output] = lsqnonneg(…)
[x,resnorm,residual,exitflag,output,lambda] = lsqnonneg(…)
6.非线性方程(组)求解
非线性方程的解
函数&& fzero
格式&& x = fzero
(fun,x0)&&&
%用fun定义表达式f(x),x0为初始解。
x = fzero (fun,x0,options)
[x,fval] =
fzero(…)&&&&&
%fval=f(x)
[x,fval,exitflag] = fzero(…)
[x,fval,exitflag,output] = fzero(…)
非线性方程组的解
函数&& fsolve
格式&& x =
fsolve(fun,x0)&&&
%用fun定义向量函数,其定义方式为:先定义方程函数function F = myfun (x)。
=[表达式1;表达式2;…表达式m]&&&
%保存为myfun.m,并用下面方式调用:x = fsolve(@myfun,x0),x0为初始估计值。
x = fsolve(fun,x0,options)
[x,fval] =
fsolve(…)&&&&&
%fval=F(x),即函数值向量
[x,fval,exitflag] = fsolve(…)
[x,fval,exitflag,output] = fsolve(…)
[x,fval,exitflag,output,jacobian] =
fsolve(…)&&& %
jacobian为解x处的Jacobian阵。
其余参数与前面参数相似。
%*************************************
quadprog - Quadratic programming
x = quadprog(H,f)
x = quadprog(H,f,A,b)
x = quadprog(H,f,A,b,Aeq,beq)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0,options)
x = quadprog(problem)
[x,fval] = quadprog(...)
[x,fval,exitflag] = quadprog(...)
[x,fval,exitflag,output] = quadprog(...)
[x,fval,exitflag,output,lambda] = quadprog(...)
Description
= quadprog(,)
returns a vector x that minimizes
1/2*x'*H*x&+&f'*x. H must be
positive definite for the problem to have a finite minimum.
= quadprog(,,,)
minimizes 1/2*x'*H*x&+&f'*x
subject to the restrictions
A*x&≤&b. A is a matrix of
doubles, b is a vector of doubles.
= quadprog(,,,,,)
solves the preceding problem subject to the additional restrictions
Aeq*x&=&beq. Aeq is a matrix of
doubles, beq is a vector of doubles. If no inequalities exist, set
A&=&[] and
= quadprog(,,,,,,,)
solves the preceding problem subject to the additional restrictions
lb&≤&x&≤&ub.
lb and ub are vectors of doubles, and the restrictions hold for
each component of x. If no equalities exist, set
Aeq&=&[] and
Note&& If the
specified input bounds for a problem are inconsistent, the output x
is x0 and the output fval is [].
Components of x0 that violate the bounds
lb&≤&x&≤&ub
are reset to the interior of the box defined by the bounds.
Components that respect the bounds are not changed.
= quadprog(,,,,,,,,)
solves the preceding problem starting from the vector x0. If no
bounds exist, set lb&=&[] and
ub&=&[]. Some quadprog algorithms
ignore x0. If you do not give x0, all components of x0 are set to a
point in the interior of the box defined by the bounds.
= quadprog(,,,,,,,,,)
solves the preceding problem with the optimization options
specified in the structure options. Use
to create options. If you do not want to give
an initial point, set
x = quadprog(problem) returns the minimum for problem, where
problem is a structure described in . Create problem
by exporting a problem from Optimization T see .
= quadprog(...) returns the value of the objective function at
fval = 0.5*x'*H*x + f'*x
= quadprog(...) returns a value exitflag that describes the exit
condition of quadprog.
= quadprog(...) returns a structure output that contains
information about the optimization.
= quadprog(...) returns a structure lambda whose fields contain the
Lagrange multipliers at the solution x.
Input Arguments
A symmetric matrix of doubles. Represents the quadratic in the
expression 1/2*x'*H*x&+&f'*x.
A vector of doubles. Represents the linear term in the
expression 1/2*x'*H*x&+&f'*x.
Matrix of doubles. Represents the linear coefficients in the
constraints A*x&≤&b.
Vector of doubles. Represents the constant vector in the
constraints A*x&≤&b.
Matrix of doubles. Represents the linear coefficients in the
constraints Aeq*x&=&beq.
Vector of doubles. Represents the constant vector in the
constraints Aeq*x&=&beq.
Vector of doubles. Represents the lower bounds elementwise in
lb&≤&x&≤&ub.
Vector of doubles. Represents the upper bounds elementwise in
lb&≤&x&≤&ub.
Vector of doubles. Optional. The initial point for some quadprog
algorithms.
Options structure created with .
All Algorithms
Choose the algorithm:
trust-region-reflective (default)
interior-point-convex
active-set
For information on choosing the algorithm, see .
Diagnostics
Display diagnostic information about the function to be
minimized or solved. The choices are 'on' or the default,
Level of display returned to the command line.
'off' displays no output
'final' (default) displays just the final output
The interior-point algorithm allows the Display setting to take
the value .
'iter' gives iterative display
'iter-detailed' gives iterative display with a detailed exit
'final-detailed' displays just the final output, with a detailed
exit message
Maximum number of iterations allowed, a positive integer. For a
trust-region-reflective equality-constrained problem, the default
value is 2*(numberOfVariables - numberOfEqualities). For all other
algorithms and problems, the default value is 200.
All Algorithms Except active-set
Termination tolerance on the function value, a positive scalar.
For a bound-constrained trust-region-reflective problem, the
default is 100*eps, about 2.2204e-14. For an equality-constrained
trust-region-reflective problem, the default is 1e-6. For
interior-point-convex, the default is 1e-8.
Termination tolerance on x, a positive scalar. The default for
trust-region-reflective is 100*eps, about 2.2204e-14. The default
for interior-point-convex is 1e-8.
trust-region-reflective Algorithm Only
Function handle for Hessian multiply function. For large-scale
structured problems, this function computes the Hessian matrix
product H*Y without actually forming H. The function is of the
W = hmfun(Hinfo,Y)
where Hinfo and possibly some additional parameters contain the
matrices used to compute H*Y.
for an example that uses this
MaxPCGIter
Maximum number of PCG (preconditioned conjugate gradient)
iterations, a positive scalar. The default is
max(1,floor(numberOfVariables/2)). For more information, see
PrecondBandWidth
Upper bandwidth of preconditioner for PCG, a nonnegative
integer. By default, quadprog uses diagonal preconditioning (upper
bandwidth 0). For some problems, increasing the bandwidth reduces
the number of PCG iterations. Setting PrecondBandWidth to Inf uses
a direct factorization (Cholesky) rather than the conjugate
gradients (CG). The direct factorization is computationally more
expensive than CG, but produces a better quality step towards the
Termination tolerance on the PCG iteration, a positive scalar.
The default is 0.1.
Typical x values. The number of elements in TypicalX is equal to
the number of elements in x0, the starting point. The default value
is ones(numberofvariables,1). quadprog uses TypicalX internally for
scaling. TypicalX has an effect only when x has unbounded
components, and when a TypicalX value for an unbounded component is
larger than 1.
interior-point-convex Algorithm Only
Tolerance on the constraint violation, a positive scalar. The
default is 1e-8.
Output Arguments
Vector that minimizes
1/2*x'*H*x&+&f'*x subject to all
bounds and linear constraints. x can be a local minimum for
nonconvex problems. For convex problems, x is a global minimum. For
more information, see .
Value of 1/2*x'*H*x&+&f'*x at
the solution x, a double.
Integer identifying the reason the algorithm terminated. The
values of exitflag and the corresponding reasons the algorithm
terminated:
All Algorithms:
Function converged to a solution x.
Number of iterations exceeded options.MaxIter.
Problem is infeasible.
Problem is unbounded.
interior-point-convex Algorithm:
Nonconvex problem detected.
trust-region-reflective Algorithm:
Change in the objective function value was smaller than
options.TolFun.
Current search direction was not a direction of descent. No
further progress could be made.
active-set Algorithm:
Local minimizer was found.
Magnitude of search direction became too small. No further
progress could be made. The problem is ill-posed or badly
conditioned.
Structure containing information about the optimization. The
fields are
iterations
Number of iterations taken
Optimization algorithm used
cgiterations
Total number of PCG iterations (large-scale algorithm only)
constrviolation
Maximum of constraint functions
firstorderopt
Measure of first-order optimality
Exit message
Structure containing the Lagrange multipliers at the solution x
(separated by constraint type). The fields are
Lower bounds lb
Upper bounds ub
Linear inequalities
Linear equalities
For more information, see .
This example shows how to solve a simple quadratic programming
problem. It finds values of x that minimize
subject to
0 ≤ x1, 0 ≤
This function can be written in matrix notation as
Enter the coefficient matrices:
H = [1 -1; -1 2]; f = [-2; -6];A = [1 1; -1 2; 2 1];b = [2; 2;
3];lb = zeros(2,1);
Set the options to use the 'active-set' algorithm with no
opts = optimset('Algorithm','active-set','Display','off');
Call quadprog:
[x,fval,exitflag,output,lambda] = ...
quadprog(H,f,A,b,[],[],lb,[],[],opts);
Examine the final point, function value, and exit flag:
x,fval,exitflagx = 0.3fval = -8.2222exitflag = 1
An exit flag of 1 means the result is a local minimum. Since H
is a positive definite matrix, this problem is convex, so the
minimum is a global minimum. You can see H is positive definite by
noting all its eigenvalues are positive:
eig(H)ans = 0.0
This example shows how to use the interior-point-convex
algorithm to solve a sparse quadratic program.
Generate a sparse symmetric matrix for the quadratic form.
v = sparse([1,-.25,0,0,0,0,0,-.25]);H = gallery('circul',v);
Include the linear term for the problem.
Include the constraint that the sum of the terms in the solution
x must be less than -2.
A = ones(1,8);b = -2;
Set options to use the interior-point-convex algorithm and
iterative display.
optimset('Algorithm','interior-point-convex','Display','iter');
Run the quadprog solver and observe the iterations.
[x fval eflag output lambda] =
quadprog(H,f,A,b,[],[],[],[],[],opts); First-order Total relative
Iter f(x) Feasibility optimality error 0 -2.0 1.000e+001
4.500e+000 1.200e+001 1 -2.1 0.000e+000 9.465e-002
9.465e-002 2 -2.1 0.000e+000 3.914e-005 3.914e-005 3
-2.1 0.000e+000 3.069e-015 6.883e-015 Minimum found that
satisfies the constraints.Optimization completed because the
objective function isnon-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.
Examine the solution:
fval,eflagfval = -26.3988eflag = 1
For the interior-point-convex algorithm, an exit flag of 1 means
the result is a global minimum
%*********************************************************
二次规划的标准形式为:
min&&f=(1/2)XTHX+fTX
约束条件:A.x=b,Aeq.x=beq,lb?x?ub
其中:c、b、beq、lb、ub、x是矢量,H、A、Aeq为矩阵。
在MATLAB中可以使用quadprog函数来求最小值。
x=quadprog (H,f,A,b)
x=quadprog (H,f,A,b,Aeq,beq)
x=quadprog (H,f,A,b,Aeq,beq,lb,ub)
x=quadprog (H,f,A,b,Aeq,beq,lb,ub,x0)
[x,fval]= quadprog (…)
[x,fval,exitflag]= quadprog (…)
[x,fval,exitflag,output]= quadprog (…)
[x,fval,exitflag,output,lambda]= quadprog (… )
其中:H,f,A,b为标准形中的参数,x为目标函数的最小值;x0为初值;Aeq,beq满足等式约束Aeq.x=beq;lb,ub满足lb?x?ub;fval为目标函数的最优值;
lambda是Lagrange乘数,它体现有效约束的个数;output输出优化信息;exitflag为终止迭代的条件:若exitflag&0,表示函数收敛于解x;若exitflag=0,表示超过函数估值或迭代的最大次数;exitflag&0表示函数不收敛于解x;output为优化信息:若参数output=iterations表示迭代次数,output=funccount表示函数赋值次数,output=algorithm表示所使用的算法。
&%***********************************************************************
如果某非线性规划的目标函数为自变量的二次函数,约束条件全是线性函数,就称这种规划为二次规划。其数学模型为:
&&&&&其中,H,&A,和Aeq为矩阵,f,&b,&beq,&lb,&ub,和x为向量。
9.2.4.2 相关函数介绍
quadprog函数
功能:求解二次规划问题。
x = quadprog(H,f,A,b)
x = quadprog(H,f,A,b,Aeq,beq)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0)
x = quadprog(H,f,A,b,Aeq,beq,lb,ub,x0,options)
[x,fval] = quadprog(...)
[x,fval,exitflag] = quadprog(...)
[x,fval,exitflag,output] = quadprog(...)
[x,fval,exitflag,output,lambda] = quadprog(...)
x = quadprog(H,f,A,b) 返回向量x,最小化函数 1/2*x'*H*x + f'*x ,其约束条件为 A*x
x = quadprog(H,f,A,b,Aeq,beq)仍然求解上面的问题,但添加了等式约束条件Aeq*x =
x = quadprog(H,f,A,b,lb,ub)定义设计变量的下界lb和上界ub,使得lb
&= x &= ub。
x = quadprog(H,f,A,b,lb,ub,x0)同上,并设置初值x0。
quadprog(H,f,A,b,lb,ub,x0,options)根据options参数指定的优化参数进行最小化。
[x,fval] = quadprog(...)返回解x处的目标函数值fval = 0.5*x'*H*x + f'*x。
[x,fval,exitflag] = quadprog(...)返回exitflag参数,描述计算的退出条件。
[x,fval,exitflag,output] = quadprog(...)返回包含优化信息的结构输出output。
[x,fval,exitflag,output,lambda] =
quadprog(...)返回解x处包含拉格朗日乘子的lambda参数。
各变量的意义同前。
1.&&&&&&&&&&一般地,如果问题不是严格凸性的,用quadprog函数得到的可能是局部最优解。
2.&&&&&&&&&&如果用Aeq和Beq明确地指定等式约束,而不是用lb和ub指定,则可以得到更好的数值解。
3.&&&&&&&&&&若x的组分没有上限或下限,则quadprog函数希望将对应的组分设置为Inf(对于上限)或-Inf(对于下限),而不是强制性地给予上限一个很大的数或给予下限一个很小的负数。
4.&&&&&&&&&&对于大型优化问题,若没有提供初值x0,或x0不是严格可行,则quadprog函数会选择一个新的初始可行点。
5.&&&&&&&&&&若为等式约束,且quadprog函数发现负曲度(negative
curvature),则优化过程终止,exitflag的值等于-1。
大型优化算法&&当优化问题只有上界和下界,而没有线性不等式或等式约束,则缺省算法为大型算法。或者,如果优化问题中只有线性等式,而没有上界和下界或线性不等式时,缺省算法也是大型算法。
本法是基于内部映射牛顿法(interior-reflective Newton method)的子空间置信域法(subspace
trust-region)。该法的具体算法请参见文献[2]。该法的每一次迭代都与用PCG法求解大型线性系统得到的近似解有关。
中型优化算法&&&quadprog函数使用活动集法,它也是一种投影法,首先通过求解线性规划问题来获得初始可行解。
1.&&&&&大型优化问题&&大型优化问题不允许约束上限和下限相等,如若lb(2)==ub(2),则给出以下出错信息:
&&&&&Equal
upper and lower bounds not permitted in this large-scale method.Use
equality constraints and the medium-scale method instead.
&&&&若优化模型中只有等式约束,仍然可以使用大型算法;如果模型中既有等式约束又有边界约束,则必须使用中型方法。
2.中型优化问题&&当解不可行时,quadprog函数给出以下警告:
&&&&&Warning:
The constraints there is no feasible
&&&&这里,quadprog函数生成使约束矛盾最坏程度最小的结果。
&&&&当等式约束不连续时,给出下面的警告信息:
&&&&Warning:
The equality constraints there is no feasible
&&&&当Hessian矩阵为负半定时,生成无边界解,给出下面的警告信息:
&&&&Warning:
The solution is unbouthe constraints are not
restrictive enough.
&&&&这里,quadprog函数返回满足约束条件的x值。
1.&&&&&&&&&&此时,显示水平只能选择'off'和'final',迭代参数'iter'不可用。
2.&&&&&&&&&&当问题不定或负定时,常常无解(此时exitflag参数给出一个负值,表示优化过程不收敛)。若正定解存在,则quadprog函数可能只给出局部极小值,因为问题可能时非凸的。
3.&&&&&&&&&&对于大型问题,不能依靠线性等式,因为Aeq必须是行满秩的,即Aeq的行数必须不多于列数。若不满足要求,必须调用中型算法进行计算。
9.2.4.3 应用实例
[例一]&求解下面的最优化问题:
首先,目标函数可以写成下面的矩阵形式:
输入下列系数矩阵:
H = [1 -1; -1 2]
f = [-2; -6]
A = [1 1; -1 2; 2 1]
b = [2; 2; 3]
lb = zeros(2,1)
然后调用二次规划函数quadratic:
[x,fval,exitflag,output,lambda] = quadprog(H,f,A,b,[],[],lb)
得问题的解
&&&&&0.6667
&&&&&1.3333
&&&&-8.2222
exitflag =
&&&&&&&iterations:
&&&&&&&&algorithm:
'medium-scale: active-set'
&&&&firstorderopt:
&&&&&cgiterations:
lambda.ineqlin
&&&&3.1111
&&&&0.4444
&&&&&&&&&0
lambda.lower
磁盘中本问题的M文件为opt24_1.m。
例3:计算下面二次规划问题
minf(x)= (1/2)x1^2+x2^2- x1x2-2x1-6x2
约束条件: x1+x2 &=?2;-x1+2x2 &=?2 ;2x1+x2
0?&= x1,0?&= x2
n解:把二次规划问题写成标准形式:(1/2)XTHX+fTX
这里:H= 1
&&&&&&&&&&&&&&&&&&
-6&&&&&&&&&&&&&x2
nH=[1 -1;-1 2];
f=[-2;-6];
A=[1 1;-1 2;2 1];
b=[2;2;3];
lb=zeros(2,1);
[x,fval,exitflag,output,lambda]=quadprog(H,f,A,b,[],[],lb)
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

我要回帖

更多关于 active set algorithm 的文章

 

随机推荐