File: corana.py

package info (click to toggle)
python-bumps 1.0.0b2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,144 kB
  • sloc: python: 23,941; xml: 493; ansic: 373; makefile: 209; sh: 91; javascript: 90
file content (51 lines) | stat: -rw-r--r-- 1,168 bytes parent folder | download | duplicates (2)
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
47
48
49
50
51
#!/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.0, 1000.0, 10.0, 100.0]
    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