File: corana.py

package info (click to toggle)
python-bumps 0.7.11-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,264 kB
  • sloc: python: 22,226; ansic: 4,973; cpp: 4,849; xml: 493; makefile: 163; perl: 108; sh: 101
file content (46 lines) | stat: -rw-r--r-- 1,154 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python

"""
Corana's function

References::
    [1] Storn, R. and Price, K. Differential Evolution - A Simple and Efficient
    Heuristic for Global Optimization over Continuous Spaces. Journal of Global
    Optimization 11: 341-359, 1997.

    [2] Storn, R. and Price, K.
    (Same title as above, but as a technical report.)
    http://www.icsi.berkeley.edu/~storn/deshort1.ps
"""
from math import pow, floor, copysign


def corana1d(x):
    """Corana in 1D; coeffs = (x,0,0,0)"""
    return corana4d([x[0], 0, 0, 0])

def corana2d(x):
    """Corana in 2D; coeffs = (x,0,y,0)"""
    return corana4d([x[0], 0, x[1], 0])

def corana3d(x):
    """Corana in 3D; coeffs = (x,0,y,z)"""
    return corana4d([x[0], 0, x[1], x[2]])

def corana4d(x):
    """
    evaluates the Corana function on [x0,x1,x2,x3]

    minimum is f(x)=0.0 at xi=0.0
    """
    d = [1., 1000., 10., 100.]
    r = 0
    for xj,dj in zip(x,d):
        zj =  floor( abs(xj/0.2) + 0.49999 ) * copysign(0.2,xj)
        if abs(xj-zj) < 0.05:
            r += 0.15 * pow(zj - copysign(0.05,zj), 2) * dj
        else:
            r += dj * xj * xj
    return r

# End of file