Exemplo n.º 1
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.º 2
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.º 3
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])