1
2
3
4
5
6 """
7 Class defining the Powell function
8 """
9
10 import numpy
11 from numpy.testing import *
12 set_package_path()
13 from optimizers import criterion, step, optimizer, line_search
14 restore_path()
15
16
18 """
19 The Powell function
20 """
22 """
23 Get the value of the Powell function at a specific point
24 """
25 return (x[0] + 10* x[1])**2 + 5 * (x[2] - x[3])**2 + (x[1] - 2 * x[2])**4 + 10 * (x[0] - x[3])**4
26
28 """
29 Evaluates the gradient of the function
30 """
31 return numpy.array([2 * (x[0] + 10 * x[1]) + 40 * (x[0] - x[3])**3, 20 * (x[0] + 10 * x[1]) + 4 * (x[1] - x[2])**3, 10 * (x[2] - x[3]) - 8 * (x[1] - 2 * x[2])**3, 10 * (x[2] - x[3]) - 40 * (x[0] - x[3])**3], dtype = numpy.float)
32
34 """
35 Evaluates the gradient of the function
36 """
37 print x, self(x)
38 return numpy.array([[2 + 120 * (x[0] - x[3]) ** 2, 20, 0, -120 * (x[0] - x[3]) ** 2], [20, 200 + 12 * (x[1] - 2 * x[2]) ** 2, -24 * (x[1] - 2 * x[2]) ** 2, 0], [0, -24 * (x[1] - 2 * x[2]) ** 2, 10 + 48 * (x[1] - 2 * x[2]) ** 2, -10], [-120 * (x[0] - x[3]) ** 2, 0, -10, -10 + 120 * (x[0] - x[3])**2]], dtype = numpy.float)
39
41 """
42 Global test class with the Powell function
43 """
52
53 if __name__ == "__main__":
54 NumpyTest().run()
55