rosenbrock 704 Bytes
Newer Older
PLian's avatar
PLian committed
1
#!/usr/bin/env python3
2
3
4
5
6
7
8
9
10
11

"""
rosenbrock - compute the value of the rosenbrock function for a given X and Y

Usage:
  rosenbrock --x=<x> --y=<y>

"""

from docopt import docopt
12
13
14
import time
import random

15
16
17
18
19
20
21
22
23

def rosenbrock(x, y):
    """
    This R^2 -> R^1 function should be compatible with algopy.
    http://en.wikipedia.org/wiki/Rosenbrock_function
    A generalized implementation is available
    as the scipy.optimize.rosen function
    """
    a = 1. - x
24
25
    b = y - x * x
    return a * a + b * b * 100.
26
27
28
29


def main():
    arguments = docopt(__doc__)
30
    time.sleep(random.random() * 10)
PLian's avatar
PLian committed
31
    print(rosenbrock(float(arguments['--x']), float(arguments['--y'])))
32

33

34
35
if __name__ == '__main__':
    main()