cec2017测试函数python
时间: 2023-06-22 10:21:47 浏览: 217
以下是 CEC2017 基准测试函数的 Python 实现示例:
```python
import numpy as np
def F1(x):
return np.sum(x**2)
def F2(x):
return np.sum(np.abs(x)) + np.prod(np.abs(x))
def F3(x):
dim = len(x)
return np.sum(100 * (x[1:dim] - x[0:dim-1]**2)**2 + (1 - x[0:dim-1])**2)
def F4(x):
return np.max(np.abs(x))
def F5(x):
dim = len(x)
return np.sum(100 * (x[1:dim] - 0.01*x[0:dim-1]**2)**2 + 0.01*(1-x[0:dim-1])**2)
def F6(x):
return np.sum(np.floor(x + 0.5)**2)
def F7(x):
dim = len(x)
return np.sum(np.arange(1, dim+1) * x**4) + np.random.rand()
def F8(x):
dim = len(x)
return -np.sum(np.sin(np.sqrt(np.abs(x)))) + 418.9829*dim
def F9(x):
dim = len(x)
return 1e6 * x[0]**2 + np.sum(x[1:dim]**2)
def F10(x):
dim = len(x)
return -np.sum(x * np.sin(np.sqrt(np.abs(x)))) + 2*dim
def F11(x):
dim = len(x)
return np.sum(np.abs(x)**np.arange(1, dim+1)) + np.random.rand()
def F12(x):
dim = len(x)
return np.sum((x**2 + np.roll(x**2, 1))**2)
def F13(x):
dim = len(x)
return 0.1 * (np.sin(3*np.pi*x[1])**2 + np.sum((x[0:dim-2]-1)**2 * (1+np.sin(3*np.pi*x[1:dim])**2)) + (x[dim-1]-1)**2*(1+np.sin(2*np.pi*x[dim-1])**2)) + np.sum(U(x, 10, 100, 4))
def F14(x):
dim = len(x)
return 0.1 * (np.sin(3*np.pi*x[1])**2 + np.sum((x[0:dim-2]-1)**2 * (1+np.sin(3*np.pi*x[1:dim])**2)) + (x[dim-1]-1)**2*(1+np.sin(2*np.pi*x[dim-1])**2)) + np.exp(np.sum(U(x, 5, 100, 4)))
def F15(x):
dim = len(x)
return -1 / (0.1 + np.sum((x-2)**2 - 10*np.cos(2*np.pi*(x-2)))) + np.exp(np.sum(U(x, 5, 100, 4)))
def U(x, a, k, m):
y = np.zeros(len(x))
for i in range(len(x)):
if x[i] > a:
y[i] = k * (x[i]-a)**m
elif x[i] < -a:
y[i] = k * (-x[i]-a)**m
else:
y[i] = 0
return y
```
其中,`U` 函数为辅助函数,用于实现 CEC2017 中的约束条件。具体的可以参考 CEC2017 的文档。
阅读全文