CEC2013-benchmark基准测试函数及代码

可以用CEC13BenchMark来测试自己的算法。

20个具有不同特征的基准测试函数(包括几个相同但尺寸大小不同的函数)来评估小生境算法

函数

  • F 1 : F_1: F1:Five-Uneven-Peak Trap (1D)
  • F 2 : F_2: F2:Equal Maxima (1D)
  • F 3 : F_3: F3:Uneven Decreasing Maxima (1D)
  • F 4 : F_4: F4:Himmelblau (2D)
  • F 5 : F_5: F5:Six-Hump Camel Back (2D)
  • F 6 : F_6: F6:Shubert (2D,3D)
  • F 7 : F_7: F7:Vincent (2D,3D)
  • F 8 : F_8: F8:Modified rastrigin - All Global Optima (2D)
  • F 9 : F_9: F9:Composition Function 1 (2D)
  • F 10 : F_{10}: F10:Composition Function 2 (2D)
  • F 11 : F_{11}: F11:Composition Function 3 (2D,3d,5D,10D)
  • F 12 : F_{12}: F12:Composition Function 4 (3D,5d,10D,20D)

公式

  • F 1 : F_1: F1:Five-Uneven-Peak Trap (1D)

    • F i = { 80 ( 2.5 − x ) f o r 0 ⩽ x < 2.5 64 ( x − 2.5 ) f o r 2.5 ⩽ x < 5.0 64 ( 7.5 − x ) f o r 5.0 ⩽ x < 7.5 28 ( x − 7.5 ) f o r 7.5 ⩽ x < 12.5 28 ( 17.5 − x ) f o r 12.5 ⩽ x < 17.5 32 ( x − 17.5 ) f o r 17.5 ⩽ x < 22.5 32 ( 27.5 − x ) f o r 22.5 ⩽ x < 27.5 80 ( x − 27.5 ) f o r 27.5 ⩽ x < 30 F_i = \begin{cases} 80(2.5-x) & for 0\leqslant x <2.5\\ 64(x-2.5) & for 2.5\leqslant x <5.0\\ 64(7.5-x) & for 5.0\leqslant x <7.5\\ 28(x-7.5) & for 7.5\leqslant x <12.5\\ 28(17.5-x) & for 12.5\leqslant x <17.5\\ 32(x-17.5) & for 17.5\leqslant x <22.5\\ 32(27.5-x) & for 22.5\leqslant x <27.5\\ 80(x-27.5) & for 27.5\leqslant x <30\\ \end{cases} Fi=80(2.5x)64(x2.5)64(7.5x)28(x7.5)28(17.5x)32(x17.5)32(27.5x)80(x27.5)for0x<2.5for2.5x<5.0for5.0x<7.5for7.5x<12.5for12.5x<17.5for17.5x<22.5for22.5x<27.5for27.5x<30

    • x ϵ [ 0 , 30 ] x\epsilon[0,30] xϵ[0,30]

  • F 2 : F_2: F2:Equal Maxima (1D)

    • F 2 ( x ) = sin ⁡ 6 ( 5 π x ) F_2(x)=\sin^6(5\pi x) F2(x)=sin6(5πx)

    • x ϵ [ 0 , 1 ] x\epsilon[0,1] xϵ[0,1]

  • F 3 : F_3: F3:Uneven Decreasing Maxima (1D)

    • F 3 ( x ) = exp ⁡ ( − 2 log ⁡ ( 2 ) ( x − 0.08 0.854 ) 2 ) sin ⁡ 6 ( 5 π ( x 3 / 4 − 0.05 ) ) F_3(x)=\exp(-2\log(2)(\frac{x-0.08}{0.854})^2) \sin^6(5\pi (x^{3/4}-0.05)) F3(x)=exp(2log(2)(0.854x0.08)2)sin6(5π(x3/40.05))

    • x ϵ [ 0 , 1 ] x\epsilon[0,1] xϵ[0,1]

  • F 4 : F_4: F4:Himmelblau (2D)

    • F 4 ( x , y ) = 200 − ( x 2 + y − 11 ) 2 − ( x + y 2 − 7 ) 2 F_4(x,y)=200-(x^2+y-11)^2-(x+y^2-7)^2 F4(x,y)=200(x2+y11)2(x+y27)2

    • x ϵ [ − 6 , 6 ] x\epsilon[-6,6] xϵ[6,6]

  • F 5 : F_5: F5:Six-Hump Camel Back (2D)

    • F 5 ( x , y ) = − 4 [ ( 4 − 2.1 x 2 + x 4 3 ) x 2 + x y + ( 4 y 2 − 4 ) y 2 ] F_5(x,y)=-4[(4-2.1x^2+\frac{x^4}{3})x^2 +xy+(4 y^2-4)y^2] F5(x,y)=4[(42.1x2+3x4)x2+xy+(4y24)y2]

    • x ϵ [ − 1.9 , 1.9 ] x\epsilon[-1.9,1.9] xϵ[1.9,1.9] y ϵ [ − 1.1 , 1.1 ] y\epsilon[-1.1,1.1] yϵ[1.1,1.1]

  • F 6 : F_6: F6:Shubert (2D,3D)

    • F 6 ( x ⃗ ) = − ∏ i = 1 D ∑ j = 1 5 j cos ⁡ [ ( j + 1 ) x i + j ] F_6(\vec{x})=- \prod_{i=1}^D\sum_{j=1}^5j\cos[(j+1)x_i+j] F6(x )=i=1Dj=15jcos[(j+1)xi+j]

    • x i ϵ [ − 10 , 10 ] D , i = 1 , 2 , . . . , D x_i\epsilon[-10,10]^D,i=1,2,...,D xiϵ[10,10]D,i=1,2,...,D

  • F 7 : F_7: F7:Vincent (2D,3D)

    • F 7 ( x ⃗ ) = 1 D ∑ i = 1 D sin ⁡ ( 10 log ⁡ ( x i ) ) F_7(\vec x)=\frac{1}{D}\sum_{i=1}^D\sin(10\log(x_i)) F7(x )=D1i=1Dsin(10log(xi))

    • x i ϵ [ 0.25 , 10 ] D , i = 1 , 2 , . . . , D x_i\epsilon[0.25,10]^D,i=1,2,...,D xiϵ[0.25,10]D,i=1,2,...,D

  • F 8 : F_8: F8:Modified rastrigin - All Global Optima (2D)

    • F 9 ( x ⃗ ) = − ∑ i = 1 D ( 10 + 9 cos ⁡ ( 2 π k i x i ) ) F_9(\vec x)=-\sum_{i=1}^D(10+9\cos(2\pi k_i x_i)) F9(x )=i=1D(10+9cos(2πkixi))

    • x i ϵ [ 0 , 1 ] D , i = 1 , 2 , . . . , D x_i\epsilon[0,1]^D,i=1,2,...,D xiϵ[0,1]D,i=1,2,...,D

  • F 9 : F_9: F9:Composition Function 1 (2D)

    • 6个函数组成

    • f1-f2:Grienwank’s Function f3-f4:Weierstrass function f5-f6:Sphere function

    • A D = [ − 5 , 5 ] D σ i = 1 , ∀ i ϵ { 1 , 2 , . . . , n } λ = [ 1 , 1 , 8 , 8 , 1 / 5 , 1 / 5 ] A_D=[-5,5]^D \\ \sigma_i = 1,\forall_i \epsilon{\{1,2,...,n}\}\\ \lambda = [1,1,8,8,1/5,1/5] AD=[5,5]Dσi=1,iϵ{1,2,...,n}λ=[1,1,8,8,1/5,1/5]

  • F 10 : F_{10}: F10:Composition Function 2 (2D)

    • 8个函数组成

    • f1-f2:Restigin’s function f3-f4:Weierstrass function f5-f6:Grienwank’s Function f7-f8:Sphere function

    • A D = [ − 5 , 5 ] D σ i = 1 , ∀ i ϵ { 1 , 2 , . . . , n } λ = [ 1 , 1 , 10 , 10 , 1 / 10 , 1 / 10 , 1 / 7 , 1 / 7 ] A_D=[-5,5]^D \\ \sigma_i = 1,\forall_i \epsilon{\{1,2,...,n}\}\\ \lambda = [1,1,10,10,1/10,1/10,1/7,1/7] AD=[5,5]Dσi=1,iϵ{1,2,...,n}λ=[1,1,10,10,1/10,1/10,1/7,1/7]

  • F 11 : F_{11}: F11:Composition Function 3 (2D,3d,5D,10D)

    • 6个函数组成

    • f1-f2:EF8F2 function f3-f4:Weierstrass function f5-f6:Grienwank’s Function

    • A D = [ − 5 , 5 ] D σ i = [ 1 , 1 , 2 , 2 , 2 , 2 ] λ = [ 1 / 4 , 1 / 10 , 1 , 2 , 5 ] A_D=[-5,5]^D \\ \sigma_i = [1,1,2,2,2,2]\\ \lambda = [1/4,1/10,1,2,5] AD=[5,5]Dσi=[1,1,2,2,2,2]λ=[1/4,1/10,1,2,5]

  • F 12 : F_{12}: F12:Composition Function 4 (3D,5d,10D,20D)

    • 8个函数组成

    • f1-f2:Restigin’s function f3-f4:EF8F function f5-f6:Weierstrass function f7-f8:Grienwank’s Function

    • A D = [ − 5 , 5 ] D σ i = [ 1 , 1 , 1 , 1 , 1 , 2 , 2 , 2 ] λ = [ 4 , 1 , 4 , 1 , 1 / 10 , 1 / 5 , 1 / 10 , 1 / 40 ] A_D=[-5,5]^D \\ \sigma_i = [1,1,1,1,1,2,2,2]\\ \lambda = [4,1,4,1,1/10,1/5,1/10,1/40] AD=[5,5]Dσi=[1,1,1,1,1,2,2,2]λ=[4,1,4,1,1/10,1/5,1/10,1/40]


  • Sphere function

    • f S ( x ⃗ ) = ∑ i = 1 D x i 2 f_S(\vec x)=\sum_{i=1}^Dx_i^2 fS(x )=i=1Dxi2
  • Grienwank’s function

    • f G ( x ⃗ ) = ∑ i = 1 D x i 2 4000 − ∏ i = 1 D cos ⁡ ( x i i ) + 1 f_G(\vec x)=\sum_{i=1}^D\frac{x_i^2}{4000}-\prod_{i=1}^D \cos(\frac{x_i}{\sqrt{i}})+1 fG(x )=i=1D4000xi2i=1Dcos(i xi)+1
  • Restrigin’s function

    • f R ( x ⃗ ) = ∑ i = 1 D ( x i 2 − 10 cos ⁡ ( 2 π x i ) + 10 ) f_R(\vec x)=\sum_{i=1}^D(x_i^2-10\cos(2\pi x_i)+10) fR(x )=i=1D(xi210cos(2πxi)+10)
  • Weierstrass function

    • f W ( x ⃗ ) = ∑ i = 1 D ( ∑ k = 0 k m a x α k cos ⁡ ( 2 π β k ( x i + 0.5 ) ) ) − D ∑ k = 0 k m a x α k cos ⁡ ( 2 π β k ( 0.5 ) ) α = 0.5 , β = 3 , k m a x = 20 f_W(\vec x)=\sum_{i=1}^D(\sum_{k=0}^{kmax} \alpha^k\cos(2\pi \beta^k (x_i+0.5)))-D\sum_{k=0}^{kmax}\alpha^k\cos(2\pi \beta^k(0.5))\\ \alpha=0.5,\beta=3,kmax=20 fW(x )=i=1D(k=0kmaxαkcos(2πβk(xi+0.5)))Dk=0kmaxαkcos(2πβk(0.5))α=0.5,β=3,kmax=20
  • Expanded Griewank’s plus Rosenbrock’s function(EF8F2)

    • F 8 ( x ⃗ ) = ∑ i = 1 D x i 2 4000 − ∏ i = 1 D cos ⁡ ( x i i ) + 1 F 2 ( x ⃗ ) = ∑ i = 1 D ( 100 ( x i 2 − x i + 1 ) 2 ) + ( x i − 1 ) 2 E F 8 F 2 ( x ⃗ ) = F 8 F 2 ( x 1 , x 2 , . . . , x D ) = F 8 ( F 2 ( x 1 , x 2 ) ) + F 8 ( F 2 ( x 2 , x 3 ) ) + . . . + F 8 ( F 2 ( x D − 1 , x D ) ) + F 8 ( F 2 ( x D , x 1 ) ) F8(\vec x)=\sum_{i=1}^D\frac{x_i^2}{4000}-\prod_{i=1}^D\cos(\frac{x_i}{\sqrt i})+1\\ F2(\vec x)=\sum_{i=1}^D(100(x_i^2-x_{i+1})^2)+(x_i-1)^2\\ EF8F2(\vec x)=F8F2(x_1,x_2,...,x_D)=F8(F2(x_1,x_2))+F8(F2(x_2,x_3))+...+F8(F2(x_{D-1},x_D))+F8(F2(x_D,x_1)) F8(x )=i=1D4000xi2i=1Dcos(i xi)+1F2(x )=i=1D(100(xi2xi+1)2)+(xi1)2EF8F2(x )=F8F2(x1,x2,...,xD)=F8(F2(x1,x2))+F8(F2(x2,x3))+...+F8(F2(xD1,xD))+F8(F2(xD,x1))

python绘制基准测试函数

最近在学正好就绘制了一下

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


def draw_pic(x, y, title, x_min, x_max, y_min, y_max):
    plt.grid(True)  ##增加格点
    plt.xlim(x_min, x_max)
    plt.ylim(y_min, y_max)
    plt.title(title)
    plt.plot(x, y)
    plt.show()


def draw_pic_3D(x, y, z, title, z_min, z_max, offset):
    fig = plt.figure()
    ax = Axes3D(fig)
    # rstride代表row行步长  cstride代表colum列步长  camp 渐变颜色
    ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap = plt.get_cmap('rainbow'),color='orangered')
    # 绘制等高线
    ax.contour(x,y,z,offset=offset,colors='green')
    ax.set_zlim(z_min, z_max)
    ax.set_title(title)
    plt.show()


def get_x_and_y(x_min, x_max, y_min, y_max):
    x = np.arange(x_min, x_max, 0.1)
    y = np.arange(y_min, y_max, 0.1)
    x, y = np.meshgrid(x, y)  # 生成网格点坐标矩阵
    return x, y


# 1
def Five_uneven_peak_Trap(x_min=0, x_max=30, y_min=0, y_max=200):
    x = np.linspace(0, 30, 1000)

    interval0 = [1 if (i >= 0.0) & (i < 2.5) else 0 for i in x]
    interval1 = [1 if (i >= 2.5) & (i < 5.0) else 0 for i in x]
    interval2 = [1 if (i >= 5.0) & (i < 7.5) else 0 for i in x]
    interval3 = [1 if (i >= 7.5) & (i < 12.5) else 0 for i in x]
    interval4 = [1 if (i >= 12.5) & (i < 17.5) else 0 for i in x]
    interval5 = [1 if (i >= 17.5) & (i < 22.5) else 0 for i in x]
    interval6 = [1 if (i >= 22.5) & (i < 27.5) else 0 for i in x]
    interval7 = [1 if (i >= 27.5) & (i < 30.0) else 0 for i in x]

    y = 80 * (2.5 - x) * interval0 + 64 * (x - 2.5) * interval1 + 64 * (7.5 - x) * interval2 + 28 * (
            x - 7.5) * interval3 + 28 * (17.5 - x) * interval4 + 32 * (x - 17.5) * interval5 + 32 * (
                27.5 - x) * interval6 + 80 * (x - 27.5) * interval7
    return x, y, 'Five-Uneven-Peak Trap', x_min, x_max, y_min, y_max


# 2
def Equal_maxima(x_min=0, x_max=1, y_min=0, y_max=1):
    x = np.linspace(0, 1, 1000)
    y = np.sin(5 * np.pi * x) ** 6
    return x, y, 'Equal Maxima', x_min, x_max, y_min, y_max


# 3
def Uneven_decreasing_maxima(x_min=0, x_max=1, y_min=0, y_max=1):
    x = np.linspace(0, 1, 1000)
    y = np.exp(-2 * np.log(2) * ((x - 0.08) / 0.854) ** 2) * (np.sin(5 * np.pi * (x ** (3 / 4)) - 0.05)) ** 6
    return x, y, 'Uneven Decreasing Maxima', x_min, x_max, y_min, y_max


# 4
def Himmelblau(z_min=-2000, z_max=0, offset=-2000):
    x, y = get_x_and_y(-6, 6, -6, 6)
    z = 200 - (x ** 2 + y - 11) ** 2 - (x + y ** 2 - 7) ** 2
    return x, y, z, 'Himmelblau', z_min, z_max, offset


# 5
def Six_hump_camel_back(z_min=-25, z_max=5, offset=-25):
    x, y = get_x_and_y(-1.9, 1.9, -1.1, 1.1)
    z = -4 * ((4 - 2.1 * (x ** 2) + ((x ** 4) / 3)) * (x ** 2) + x * y + (4 * (y ** 2) - 4) * (y ** 2))
    return x, y, z, 'Six_HUmp Camel Back', z_min, z_max, offset


# 6   --2D---
def Shubert(z_min=-300, z_max=200, offset=-300):
    x, y = get_x_and_y(-10, 10, -10, 10)
    z1 = (1 * np.cos((1 + 1) * x + 1)) + (2 * np.cos((2 + 1) * x + 2)) + (3 * np.cos((3 + 1) * x + 3)) + (
            4 * np.cos((4 + 1) * x + 4)) + (5 * np.cos((5 + 1) * x + 5))
    z2 = (1 * np.cos((1 + 1) * y + 1)) + (2 * np.cos((2 + 1) * y + 2)) + (3 * np.cos((3 + 1) * y + 3)) + (
            4 * np.cos((4 + 1) * y + 4)) + (5 * np.cos((5 + 1) * y + 5))
    z = -(z1 * z2)
    return x, y, z, 'Shubert', z_min, z_max, offset


# 7 ---2D---
def Vincent(z_min=-1, z_max=1, offset=-1):
    x, y = get_x_and_y(0.25, 10, 0.25, 10)

    z1 = np.sin(10 * np.log(x))
    z2 = np.sin(10 * np.log(y))
    z = (z1 + z2) / 2
    return x, y, z, 'Vincent', z_min, z_max, offset


# 8 ---存在点问题----
def Modified_rastrigin_all_global_optima(z_min=-40, z_max=10, offset=-40):
    x, y = get_x_and_y(0, 1, 0, 1)
    z1 = 10 + 9 * np.cos(2 * np.pi * 3 * x)
    z2 = 10 + 9 * np.cos(2 * np.pi * 4 * y)
    z = -(z1 + z2)
    return x, y, z, 'Modified Rastrigin All Global Optima', z_min, z_max, offset


# Sphere Function
def Sphere(z_min = 0,z_max = 30,offset = 0):
    x,y = get_x_and_y( -3,3,-3,3)
    z = x ** 2 + y ** 2
    return x,y,z, "Sphere function", z_min, z_max, offset

# Grienwank's Function
def Grienwank(z_min = 0,z_max = 3,offset = 0):
    x, y = get_x_and_y(-10, 10, -10, 10)
    z = (x ** 2) /4000 + (y ** 2) / 4000 - np.cos(x / np.sqrt(1)) * np.cos(y / np.sqrt(2))+1
    return x,y,z, "Grienwank's function", z_min, z_max, offset

# restrigin function
def Rastrigin(z_min=0, z_max=100, offset=0):
    x, y = get_x_and_y(-5.52, 5.12, -5.12, 5.12)
    z = 2 * 10 + x ** 2 - 10 * np.cos(2 * np.pi * x) + y ** 2 - 10 * np.cos(2 * np.pi * y)
    return x,y,z, "Rastrigin function", z_min, z_max, offset

# Weierstrass Function
def Weierstrass(z_min=-5,z_max=5,offset=-5):
    x, y = get_x_and_y(-2, 2, -2, 2)
    a = 0.5
    b = 3
    kmax = 20
    z1,z2,z3 = 0,0,0
    for k1 in range(1,kmax+1):
        z_1 = (a ** k1) * np.cos(2 * np.pi * (b ** k1) * (x + 0.5))
        z_2 = (a ** k1) * np.cos(2 * np.pi * (b ** k1) * (y + 0.5))
        z1 += z_1
        z2 += z_2
    for k2 in range(1,kmax+1):
        z_3 = (a ** k2) * np.cos(2 * np.pi * (b ** k1) * 0.5)
        z3 += z_3
    z = z1 + z2 -z3
    return x,y,z, "Weierstrass Function", z_min, z_max, offset

# Expanded Griewank's plus Rosenbrock's function (EF8F2)
def EF8F2(z_min = -100,z_max = 3000,offset = -100):
    x, y = get_x_and_y(-2, 2, -2, 2)
    f2 = 100 * ((x ** 2) - y) ** 2 + (x -1) ** 2
    z = 1 + (f2 ** 2) /4000 -np.cos(f2)
    return x,y,z, "F8F2", z_min, z_max, offset


# Five_uneven_peak_Trap
# x, y, title, x_min, x_max, y_min, y_max = Five_uneven_peak_Trap()

# Equal_maxima
# x, y, title, x_min, x_max, y_min, y_max = Equal_maxima()

# Uneven_decreasing_maxima
# x, y, title, x_min, x_max, y_min, y_max = Uneven_decreasing_maxima()

# draw_pic(x, y, title, x_min, x_max, y_min, y_max)

# -------------------------------------------------------
# Himmelblau
# x, y,z, title,z_min,z_max,offset = Himmelblau()

# Six_hump_camel_back
# x, y,z, title,z_min,z_max,offset = Six_hump_camel_back()

# Shubert
# x, y, z, title, z_min, z_max, offset = Shubert()

# Vincent
# x, y,z, title,z_min,z_max,offset = Vincent()

# Modified_rastrigin_all_global_optima
# x, y,z, title,z_min,z_max,offset = Modified_rastrigin_all_global_optima()

# Sphere Function
# x, y,z, title,z_min,z_max,offset = Sphere()

# Grienwank's Function
# x, y,z, title,z_min,z_max,offset = Grienwank()

# Rastrigin Function
# x, y,z, title,z_min,z_max,offset = Rastrigin()

# Weierstrass Function
# x, y,z, title,z_min,z_max,offset = Weierstrass()

# EF8F2
x,y,z,title, z_min, z_max, offset = EF8F2()


draw_pic_3D(x, y, z, title, z_min, z_max, offset)

效果图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

转载请注明出处,多谢☺️

加油

  • 18
    点赞
  • 93
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值