Exemplo n.º 1
0
def michalewicz(x):  # mich.m
    x = np.asarray_chkfinite(x)
    n = len(x)
    j = np.arange(1., n + 1)
    t1 = [ria.sin(v) for v in x]
    t2 = [ria.sin(j[i] * x[i]**2 / ria.pi()) for i in range(len(x))]
    t3 = [t1[i] * t2[i]**((2 * michalewicz_m)) for i in range(len(t1))]

    return -sum(t3)
Exemplo n.º 2
0
def ackley(x, a=20, b=0.2, c=2 * ria.pi()):
    #x = np.asarray_chkfinite(x)  # ValueError if any NaN or Inf
    #print (x)
    n = len(x)
    s1 = sum([v**2.0 for v in x])
    s2 = sum([ria.cos(c * v) for v in x])

    return -a * ria.exp(-b * (s1 / n)**(1.0 / 2.0)) - ria.exp(
        s2 / n) + a + ria.exp(1)
Exemplo n.º 3
0
def griewank(x, fr=4000):
    #x = np.asarray_chkfinite(x)
    n = len(x)
    j = np.arange(1., n + 1)
    s = sum([v**2 for v in x])
    v = []
    for i in range(len(x)):
        v.append(x[i] / ria.sqrt(j[i]))  #ria.sqrt
    p = prod(([ria.cos(xi) for xi in v]))
    return s / fr - p + 1
Exemplo n.º 4
0
def nesterov(x):
    """ Nesterov's nonsmooth Chebyshev-Rosenbrock function, Overton 2011 variant 2 """
    x = np.asarray_chkfinite(x)
    x0 = x[:-1]
    x1 = x[1:]
    t1 = ria.abs(1.0 - qm.midpoint(x[0])) / 4.0
    t2 = sum([
        ria.abs(qm.midpoint(x1[i] - 2.0 * ria.abs(qm.midpoint(x0[i])) + 1.0))
        for i in range(len(x1))
    ])
    return t1 + t2
Exemplo n.º 5
0
def perm(x, b=.5):
    x = np.asarray_chkfinite(x)
    n = len(x)
    j = np.arange(1., n + 1)
    xbyj = [((ria.abs(x[i])) / j[i]) for i in range(len(x))]
    return mean([
        mean((j**k + b) * (xbyj**k - 1.0))**2.0  #add media aritmetica em rdm
        for k in j / n
    ])
Exemplo n.º 6
0
def levy(x):
    x = np.asarray_chkfinite(x)
    n = len(x)
    z = 1 + (x - 1) / 4.0
    t1 = ria.sin(ria.pi() * z[0])**2
    t2_1 = [(v - 1)**2 for v in x]
    t2_1 = t2_1[:-1]
    t2_2 = [(1 + 10 * ria.sin(ria.pi() * v + 1)**2) for v in x]
    t2_2 = t2_2[:-1]
    t2_3 = [t2_1[i] * t2_2[i] for i in range(len(t2_2))]

    t2 = sum(t2_3)
    t3 = (z[-1] - 1)**2 * (1 + ria.sin(2 * ria.pi() * z[-1])**2)
    return t1 + t2 + t3
Exemplo n.º 7
0
def schwefel(x):  # schw.m
    x = np.asarray_chkfinite(x)
    n = len(x)
    return 418.9829 * n - sum([v * ria.sin(ria.sqrt(ria.abs(v))) for v in x])
Exemplo n.º 8
0
def rastrigin(x):  # rast.m
    x = np.asarray_chkfinite(x)
    n = len(x)
    return 10.0 * n + sum(
        [v**2.0 - 10.0 * ria.cos(2.0 * ria.pi() * v) for v in x])