Scipy BFGS求解30维CEC2013函数时精度损失问题求助
问题:Scipy BFGS求解CEC2013高维基准函数的精度损失问题
我正在使用Scipy的BFGS算法求解自行实现的CEC2013基准函数,但在30维情况下,Rotated Bent Cigar函数和Rotated Schaffers F7函数的求解效果极差,均出现精度损失问题。作为优化领域新手,已查阅大量资料仍无法解决,恳请帮助🙏
重现Rotated Bent Cigar问题
从Scipy导入BFGS后,使用np.ones(30)作为初始点(x0),为避免结果出现nan,将gtol设置为1e-9:
from scipy.optimize import fmin_bfgs import math import numpy as np fmin_bfgs(f3, np.ones(30), fprime=None, args=(), gtol=1e-9, norm=float('inf'), epsilon=math.sqrt(np.finfo(float).eps), maxiter=None, full_output=0, disp=1, retall=0, callback=None)
得到的输出
RuntimeWarning: overflow encountered in double_scalars Y = Z[0]**2 + 1e6 * np.sum(Z[1:]**2) - 1200 RuntimeWarning: overflow encountered in square Y = Z[0]**2 + 1e6 * np.sum(Z[1:]**2) - 1200 RuntimeWarning: invalid value encountered in subtract df = fun(x) - f0 Warning: Desired error not necessarily achieved due to precision loss. Current function value: 77457993654581510275072.000000 Iterations: 28 Function evaluations: 3524 Gradient evaluations: 113
重现Rotated Schaffers F7问题
对于Rotated Schaffers F7,使用默认的gtol=1e-5:
fmin_bfgs(f7, np.ones(30), fprime=None, args=(), gtol=1e-5, norm=float('inf'), epsilon=math.sqrt(np.finfo(float).eps), maxiter=None, full_output=0, disp=1, retall=0, callback=None)
得到的输出
Warning: Desired error not necessarily achieved due to precision loss. Current function value: 2406912647990380032.000000 Iterations: 1 Function evaluations: 1531 Gradient evaluations: 49
基准函数代码
def read_M(self, dim, m): return self.rotate_data[m * dim : (m + 1) * dim] def shift_data(self, dim, m): return np.array(self.sd[m * dim : (m + 1) * dim]) def carat(self, dim, alpha): # 不确定这个实现是否正确!!! return alpha ** (np.arange(dim)/(2*(dim-1))) def T_asy(self, X, Y, beta): D = len(X) for i in range(D): if X[i] > 0: Y[i] = X[i] ** (1 + beta * (i/(D-1)) * np.sqrt(X[i]) ) pass # Rotated Bent Cigar Function # 函数编号3 def f3(self,X): X_shift = X - self.O X_rotate = self.M1 @ X_shift self.T_asy(X_rotate, X_shift, 0.5) Z = self.M2 @ X_shift Y = Z[0]**2 + 1e6 * np.sum(Z[1:]**2) - 1200 return Y # Rotated Schaffers F7 Function # 函数编号7 def f7(self,X): d = len(X) X_shift = X - self.O X_rotate = self.M1 @ X_shift self.T_asy(X_rotate, X_shift, 0.5) Z = self.M2 @ (self.carat(d, 10) * X_shift) Z = np.sqrt(Z[:-1]**2 + Z[1:]**2) Y = (np.sum(np.sqrt(Z) + np.sqrt(Z) * np.sin(50 * Z**0.2)**2 ) / (d-1))**2 - 800 return Y
已尝试的方法
- 调小
epsilon的值,但无效果
内容的提问来源于stack exchange,提问作者Vicky
相关产品推荐
相关产品推荐

