15.6.1.1 多元函数优化
Optim包的函数类似于R的, 可以用来求多元函数的无约束极值或矩形约束的极值, 一元函数区间内的极值, 复函数极值, 流形上的极值。
The Optim package has a function similar to that of R, which can be used to obtain a non-binding polar or rectangular binding value for multiple functions, a polar value within a single function range, a secondary function polar value, a polar value on the flow.
可用的优化方法包括:
Possible optimization methods include:
- ,是不依赖梯度信息的单纯型方法,只需要目标函数本身;
- , , 这是著名的拟牛顿法, 是内存开销有限版本;
- , 共轭梯度法;
- , 最速下降法,还有, ;
- ,牛顿法,需要梯度函数与海色阵函数,海色阵函数不可省略, 还有,此方法克服了当函数不能用二次多项式近似时的困难;
- ,模拟退火法,用于求解全局最值, 只需要目标函数本身,速度慢。 , 是类似方法;
- ,矩形约束的优化;
- 为非线性约束的内点法加牛顿法;
- 和为一元函数优化;
- …………
用户可以提供梯度函数以及海色阵用来加速收敛。 结果是类似R的list类型的一个结构。
Users can provide gradient functions as well as sea colour arrays to speed up the recovery. The result is a structure similar to the R-list type.
举例说明。 考虑二元函数 \(f(x, y)=(x - a)^2 + b (y - x^2)^2\)的最小值问题。 显然唯一的最小值点为\((a, a^2)\)。 用Optim的函数进行数值求解。 这个二元函数的最小值点在很长、很窄、底部平坦的山谷内, 对迭代算法来说有一定困难。 取\(a=1, b=100\), 最小值点在\((1,1)\)。 取初值为\((0,0)\)。
Consider the question of the minimum value of the binary function
目标函数定义: Target function definition: 使用默认的设置进行优化: Optimize using default settings: 可以看出在没有选用具体优化方法的情况下用了Nelder-Mead方法,
迭代了60次。
的结果如果保存在变量中,
可以用获得最小值点(总是一个向量),
用获得最小值。
结果中还有用于检查是否收敛的输出,
详见Optim包的文档。 You can see that the Neder-Mead method was used 60 times without selecting a specific optimization method. The result, if saved in the variable, is to get the lowest point (always a vector) and the lowest value. 最小值点: Minimum point of value: 改用BFGS方法,使用普通数值微分计算梯度: Conversion to BFGS method to calculate the gradient using normal numeric fractions: 只迭代了16次,但是计算数值微分也会涉及到比较多的目标函数计算。
可以人为给出梯度函数: Only 16 times have passed, but the computational fractions also involve more target functions. An artificial gradient function can be given: 还可以由用户提供一个海色阵函数,
这时方法为牛顿法,调用如 The user can also provide a sea colour array function, which is called by Newton method. 不会用数值微分法计算海色阵,
因为两次数值微分造成很大误差。
如果目标函数完全用Julia编写并且不调用C代码和Fortran代码,
则目标函数的梯度函数和海色阵函数可以自动微分方法获得精确函数,
这需要函数的自变量支持一般的类型,
不能声明为一个具体的类型。
这在背后利用了包计算精确一阶和二阶微分。
如 No numerical differentials are used to calculate the sea colour arrays, because two numerical fractions are a major error. If the target function is entirely based on Julia and does not call C and Fortran codes, the target function's gradient function and the sea colour array function can automatically obtain the exact function differentials, which require the function's own variable to support the normal type, which cannot be stated as a specific type. This uses the package to calculate the exact first and second fractions, e.g., behind it. 支持比较简单的矩形约束优化,
所谓矩形约束(box constraint),
是指每个坐标分量属于一个区间,
可以用和表示无穷区间。
这种约束优化用的是简单的内点法。 In support of a simpler rectangular constraint optimization, the rectangular constraint (box constraint), which means that each coordinate fraction belongs to a single area and can be used and expressed as an infinity zone, is optimized using a simple internal point method. 例如,上面的例子函数本来是无约束的,
但是如果我们要求解在矩形\([1.25, \infty) imes [-2.1, \infty)\)中,
这个范围已经不包含全局最小值点。
约束优化程序如下: For example, the above example function would have been non-binding, but if we had asked for a rectangle in the rectangular (1.25, \infty) events[-2.1, \infty) , this range no longer contained the lowest value point in the global context. The constraint optimisation procedure is as follows: 可见结果在约束的左边界处达到。 Visible results are achieved at the bounds of the left boundary. 控制迭代精度等选项,
可以使用的控制选项,如 Controls overlap accuracy, control options that can be used, e.g. 此例因为设置了太小的迭代次数限制导致没有收敛。
实际上,
最速下降法迭代一万次也没有收敛。
这是因为最速下降法收敛速度慢,
而且目标函数也比较复杂。 In fact, the most rapid drop has failed to occur 10,000 times. This is because the most rapid drop is slow and the target function is complex.
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论