我已经建立了一个线性等式约束的优化问题,如下所示
sol0 = minimize(objective, x0, args=mock_df, method='trust-constr',
bounds=bnds, constraints=cons,
options={'maxiter': 250, 'verbose': 3})
是加权和函数,其objective
系数/权重将被优化以使其最小化。由于我对系数和约束都有界限,因此我使用trust-constr
了scipy.optimize.minimize
.
最小化有效,但我不理解终止标准。根据trust-constr
文档,它应该终止于xtol
算法将在 时终止
tr_radius < xtol
,其中tr_radius
是算法中使用的信任区域的半径。默认值为 1e-8。
但是,verbose
输出显示,终止确实是由barrier_tol
参数触发的,如下面的清单所示
| niter |f evals|CG iter| obj func |tr radius | opt | c viol | penalty |barrier param|CG stop|
|-------|-------|-------|-------------|----------|----------|----------|----------|-------------|-------|
C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\_trustregion_constr\projections.py:182: UserWarning: Singular Jacobian matrix. Using SVD decomposition to perform the factorizations.
warn('Singular Jacobian matrix. Using SVD decomposition to ' +
| 1 | 31 | 0 | -4.4450e+02 | 1.00e+00 | 7.61e+02 | 5.00e-01 | 1.00e+00 | 1.00e-01 | 0 |
C:\ProgramData\Anaconda3\lib\site-packages\scipy\optimize\_hessian_update_strategy.py:187: UserWarning: delta_grad == 0.0. Check if the approximated function is linear. If the function is linear better results can be obtained by defining the Hessian as zero instead of using quasi-Newton approximations.
'approximations.', UserWarning)
| 2 | 62 | 1 | -2.2830e+03 | 6.99e+00 | 3.64e+02 | 7.28e-01 | 1.00e+00 | 1.00e-01 | 2 |
| 3 | 93 | 2 | -9.7651e+03 | 3.42e+01 | 5.52e+01 | 5.33e+00 | 1.00e+00 | 1.00e-01 | 2 |
| 4 | 124 | 26 | -4.9999e+03 | 3.42e+01 | 8.23e+01 | 9.29e-01 | 3.48e+16 | 1.00e-01 | 1 |
| 5 | 155 | 50 | -4.1486e+03 | 3.42e+01 | 5.04e+01 | 2.08e-01 | 3.48e+16 | 1.00e-01 | 1 |
...
| 56 | 1674 | 1127 | -1.6146e+03 | 1.77e-08 | 4.49e+00 | 3.55e-15 | 3.66e+33 | 1.00e-01 | 1 |
| 57 | 1705 | 1151 | -1.6146e+03 | 1.77e-09 | 4.49e+00 | 3.55e-15 | 3.66e+33 | 1.00e-01 | 1 |
| 58 | 1736 | 1151 | -1.6146e+03 | 1.00e+00 | 4.42e+00 | 3.55e-15 | 1.00e+00 | 2.00e-02 | 0 |
| 59 | 1767 | 1175 | -1.6146e+03 | 1.00e-01 | 4.42e+00 | 3.55e-15 | 1.00e+00 | 2.00e-02 | 1 |
| 60 | 1798 | 1199 | -1.6146e+03 | 1.00e-02 | 4.42e+00 | 3.55e-15 | 1.00e+00 | 2.00e-02 | 1 |
...
| 66 | 1984 | 1343 | -1.6146e+03 | 1.00e-08 | 4.42e+00 | 3.55e-15 | 1.00e+00 | 2.00e-02 | 1 |
| 67 | 2015 | 1367 | -1.6146e+03 | 1.00e-09 | 4.42e+00 | 3.55e-15 | 1.00e+00 | 2.00e-02 | 1 |
| 68 | 2046 | 1367 | -1.6146e+03 | 1.00e+00 | 4.36e+00 | 3.55e-15 | 1.00e+00 | 4.00e-03 | 0 |
| 69 | 2077 | 1391 | -1.6146e+03 | 1.00e-01 | 4.36e+00 | 3.55e-15 | 1.00e+00 | 4.00e-03 | 1 |
...
| 77 | 2325 | 1583 | -1.6146e+03 | 1.00e-09 | 4.36e+00 | 3.55e-15 | 1.00e+00 | 4.00e-03 | 1 |
| 78 | 2356 | 1583 | -1.6146e+03 | 1.00e+00 | 4.35e+00 | 3.55e-15 | 1.00e+00 | 8.00e-04 | 0 |
| 79 | 2387 | 1607 | -1.6146e+03 | 1.00e-01 | 4.35e+00 | 3.55e-15 | 1.00e+00 | 8.00e-04 | 1 |
...
| 87 | 2635 | 1799 | -1.6146e+03 | 1.00e-09 | 4.35e+00 | 3.55e-15 | 1.00e+00 | 8.00e-04 | 1 |
| 88 | 2666 | 1799 | -1.6146e+03 | 1.00e+00 | 4.34e+00 | 3.55e-15 | 1.00e+00 | 1.60e-04 | 0 |
| 89 | 2697 | 1823 | -1.6146e+03 | 1.00e-01 | 4.34e+00 | 3.55e-15 | 1.00e+00 | 1.60e-04 | 1 |
...
| 97 | 2945 | 2015 | -1.6146e+03 | 1.00e-09 | 4.34e+00 | 3.55e-15 | 1.00e+00 | 1.60e-04 | 1 |
| 98 | 2976 | 2015 | -1.6146e+03 | 1.00e+00 | 4.34e+00 | 3.55e-15 | 1.00e+00 | 3.20e-05 | 0 |
| 99 | 3007 | 2039 | -1.6146e+03 | 1.00e-01 | 4.34e+00 | 3.55e-15 | 1.00e+00 | 3.20e-05 | 1 |
...
| 167 | 5053 | 3527 | -1.6146e+03 | 1.00e-07 | 1.35e+01 | 2.12e-11 | 1.00e+00 | 2.05e-09 | 1 |
| 168 | 5084 | 3551 | -1.6146e+03 | 1.00e-08 | 1.35e+01 | 2.12e-11 | 1.00e+00 | 2.05e-09 | 1 |
| 169 | 5115 | 3575 | -1.6146e+03 | 1.00e-09 | 1.35e+01 | 2.12e-11 | 1.00e+00 | 2.05e-09 | 1 |
`xtol` termination condition is satisfied.
Number of iterations: 169, function evaluations: 5115, CG iterations: 3575, optimality: 1.35e+01, constraint violation: 2.12e-11, execution time: 3.8e+02 s.
很明显,一旦 ,tr_radius < xtol
被tr_radius
重置为其默认值1
并且barrier param
被减小。一旦barrier param < barrier_tol
(即 1e-8) 和tr_radius < xtol
,优化成功终止。该文件说关于barrier_tol
当存在不等式约束时,算法将仅在障碍参数小于 时终止
barrier_tol
。
这将解释在不等式约束的情况下的行为,但我所有的约束都是定义为字典的等式约束
con0 = {'type': 'eq', 'fun': constraint0}
有足够深入的人trust-constr
向我解释这个吗?