Skip to content
No description, website, or topics provided.
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
img
DE.py
functions.py
readme.md

readme.md

Differential evolution in Python

An evolutionary algorithm that optimizes the solution by iteratively optimizing its previous best candidates

Functions

Ackleys Function
def Ackley(x):
    sum = 0.0
    sumSquare = 0.0
    sumCos = 0.0
    for i in range(len(x)):
        sumSquare += x[i] * x[i]
        sumCos += np.cos(2 * np.pi * x[i])
    sum = -20.0 * np.exp(-0.2 * np.sqrt(sumSquare / len(x))) - np.exp(sumCos / len(x)) + 20 + np.e
    return sum

Ackley

Bent Cigar Function
def BC(x):
    sum = 0.0
    sum += x[1] ** 2
    for i in range(2, len(x) + 1):
        sum += (x[i - 1] ** 2)
    sum *= (10**6)
    return sum

Bent Cigar

Discus Function
def Discus(x):
    sum = 0.0
    for i in range(2, len(x)+1):
        sum += x[i-1] ** 2
    sum += (10**6) * (x[i-1] ** 2)
    return sum

Discus

Griewank Function
def Griewank(x):
    sum = 1.0
    innerSum = 0.0
    innerProduct = 1.0
    for i in range(len(x)):
        innerSum += x[i] ** 2
        innerProduct *= np.cos(x[i] / np.sqrt(i + 1))
    sum += innerSum * (1.0 / 4000.0) - innerProduct
    return sum

Griewank

High Conditioned Elliptic
def HC(x):
    sum = 0.0
    for i in range(1, len(x) + 1):
        sum += ((10 ** 6) ** ((i - 1) / (len(x) - 1))) * x[i - 1] ** 2
    return sum

High Conditioned

Katsuura Function
def Katsuura(x):
    sum = 0.0
    product = 1.0
    for i in range(len(x)):
        summation = 0
        for j in range(1, 32):
            term = 2 ** j * x[i]
            summation += np.absolute(term - np.round(term)) / (2 ** j)
        #product *= np.pow(1 + ((i + 1) * summation), 10 / np.pow(len(x), 1.2))
        product *= (1 + ((i + 1) * summation) ** (10 / (len(x) ** 1.2)))
    sum = (10.0 / len(x) * len(x)) * product - (10.0 / len(x) * len(x))
    return sum

Katsuura

Rastrigin Function
def Rastrigin(x):
    sum = 0.0
    for i in range(len(x)):
        sum += x[i] ** 2 - (10.0 * np.cos(2 * np.pi * x[i]))
    sum += 10 * len(x)
    return sum

Rastrigin

Rosenbrock Function
def Rosenbrock(x):
    sum = 0.0
    for i in range(len(x) - 1):
        sum += ((100 * (x[i + 1] - x[i] ** 2) * (x[i + 1] - x[i] ** 2)) + ((x[i] - 1.0) * (x[i] - 1.0)));
    return sum

Rosenbrock

Weierstrass Function
def Weierstrass(x):
    a = 0.5
    b = 3
    k_max = 20

    sum = 0
    for i in range(len(x)):
        for k in range(k_max):
            sum += a ** k * np.cos(2 * np.pi * b ** k * (x[i] + 0.5))

    constant = 0
    for k in range(k_max):
        constant += a ** k * np.cos(2 * np.pi * b ** k * 0.5)
    sum -= len(x) * constant
    return sum

Weierstrass

You can’t perform that action at this time.