admin 管理员组

文章数量: 1086019


2024年4月16日发(作者:js获取当前日期)

Matlab优化函数中options选项的修改

(2010-11-12 10:43:58)

转载▼

标签:

杂谈

通常在使用Matlab优化工具箱中的函数时,需要根据不同要求修改优化选

项,例如最大迭代次数、x处的终止容限等等。可通过 optimset 语句来修改优

化选项参数:

options=optimset(‘optionName’,’optionValue’);如:

options=optimset('tolx',1e-100);

options=optimset(options,'tolfun',1e-100);

后面还可以依此法添加很多选项信息。

下面举一个完整例子:求取f=4*x(1)^2+5*x(1)*x(2)+2*x(2)^2的最小值

---------------------------------------------------------------------

------------------------function [f,g]=ff3(x)

f=4*x(1)^2+5*x(1)*x(2)+2*x(2)^2;

if nargut >1

g(1)=8*x(1)+5*x(2);

g(2)=5*x(1)+4*x(2);

end

通过下面将优化选项结构j设置为’on’来得到梯度值。

options=optimset(‘Gradobj’,’on’);

x0=[1,1];

[x,fval,exitflag]=fminunc(@ff3,x0,options)

---------------------------------------------------------------------

------------------------

Options的参数描述(OPTIMSET):

%OPTIMSETPARAMETERS

�rivativeCheck- Compare user supplied derivatives (gradients orJacobian)

%to finite-differencing derivatives[ on | {off}]

%Diagnostics - Print diagnosticinformation about the function tobe

%minimized or solved [ on | {off}]

%DiffMaxChange - Maximum change invariables for finite

differencegradients

%[ positive scalar| {1e-1} ]

%DiffMinChange - Minimum change invariables for finite

differencegradients

%[ positive scalar| {1e-8} ]

%Display - Level of display [ off | iter| notify | final ]

%GoalsExactAchieve - Number of goals to achieve exactly (do not over- or

% under-achieve) [ positive scalar integer | {0}]

%GradConstr - Gradients for the nonlinear constraints defined by user

% [ on | {off} ]

%GradObj - Gradient(s) for the objective function(s) defined by user

% [ on | {off}]

%Hessian - Hessian for the objective function defined by user [ on |

{off} ]

%HessMult - Hessian multiply function defined by user

% [ function | {[]} ]

%HessPattern - Sparsity pattern of the Hessian for finite-differencing

% [ sparse matrix ]

%HessUpdate - Quasi-Newton updating scheme

% [ {bfgs} | dfp | gillmurray | steepdesc ]

%Jacobian - Jacobian for the objective function defined by user

% [ on | {off}]

%JacobMult - Jacobian multiply function defined by user

% [ function | {[]} ]

%JacobPattern - Sparsity pattern of the Jacobian for finite-differencing

% [ sparse matrix ]

%LargeScale - Use large-scale algorithm if possible [ {on} | off ]

%LevenbergMarquardt - Chooses Levenberg-Marquardt over Gauss-Newton

algorithm

% [ on | off]

%LineSearchType - Line search algorithm choice [ cubicpoly | {quadcubic} ]

%MaxFunEvals - Maximum number of function evaluations allowed

% [ positive integer ]

%MaxIter - Maximum number of iterations allowed [ positive integer ]

%MaxPCGIter - Maximum number of PCG iterations allowed [positive integer]

%MeritFunction - Use goal attainment/minimax merit function

% [ {multiobj} | singleobj ]

%MinAbsMax - Number of F(x) to minimize the worst case absolute values

% [ positive scalar integer | {0} ]

%PrecondBandWidth - Upper bandwidth of preconditioner for PCG

% [ positive integer | Inf | {0} ]

%TolCon - Termination tolerance on the constraint violation [ positive

scalar ]

%TolFun - Termination tolerance on the function value [ positive scalar ]

%TolPCG - Termination tolerance on the PCG iteration

% [ positive scalar | {0.1} ]

%TolX - Termination tolerance on X [ positive scalar ]

%TypicalX - Typical X values [ vector ]

---------------------------------------------------------------------

------------------------

注:

优化问题求解时常常需要对相对误差,使用算法等进行设置.Matlab提供了

options向量来对优化函数进行参数设置,options向来由18个元素.目前已经被

optimset和optimget代替,详情可查阅函数optimset和optimget

下面逐个说明各个参数的功能和取值.

Options(1)=0(默认值)

功能:控制显示,优化过程中控制输出信息,0表示不显示;1表示显示;-1表隐藏

信息.

Options(2)=1e-4

功能:控制x的精度,自变量x的最低精度终止条件.当所有终止条件都满足的时

候,优化终止.

Options(3)=1e-4

功能:控制 f 精度,目标函数f的最低精度终止条件.当所有终止条件都满足的

时候,优化终止.

options(4)=1e-7

功能:约束g的最低精度终止判别条件.当所有的终止条件都满足的时候,优化终

止.

options(5)=0

功能:选择主要优化算法.

options(6)=0

功能:SD算法控制.选择搜索方向算法.

options(7)=0

功能:搜索算法控制.选择线性搜索算法.

options(8)=N/A

功能:函数值,算法结束时极值点的函数值,attgoal和minimax而言,它包含一个

到达因子.

options(9)=0

功能:梯度检查控制.当值为1时,在最初的几个迭代周期,梯度将与有限差分计

算的结果比较,此时,梯度函数必须存在.

options(10)=N/A

功能:函数计算计数.

options(11)=N/A

功能:梯度计算计数.

options(12)=N/A

功能:限定计数,限定函数梯度计算或差分梯度计算的次数.

options(13)=0

功能:等式约束个数,等式约束必须放在g的前几个元素中.

options(14)=0*n

功能:最大迭代次数,该值缺省时被置为n的100倍,n为自变量x的个数,在fmins

中,缺省为n的200倍,在fminu中,为500n.

options(15)=0

功能:目标数,尽可能接近goals的目标数,由函数attgoal使用.

options(16)=1e-8

功能:最小摄动控制.有限差分梯度计算中的最小变化.对函数的梯度计算而言,

实际使用的摄动将自动调整以提高精度,它将在最小摄动和最大摄动之间变化.

options(17)=0,1

有限差分梯度计算中变量的最大变化.

options(18)=N/A

功能:步长控制,在第一步迭代被赋值为1或更小


本文标签: 功能 函数 控制