-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_non_unimodal_fun.py
58 lines (50 loc) · 1.62 KB
/
example_non_unimodal_fun.py
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
52
53
54
55
56
57
58
"""
Author: Andrijan Ostrun
Year: 2017.
"""
from models import *
from nonlinear_optimizations import *
import collections
#########################################################
# Example 3:
# This example show the problems with some algorithms
# which can not find the real minimum of the function.
# Function used in this example (f4) is not unimodal
# thus function has a lots of local minimums but one
# global minimum which only Simplex algorithm (in this example)
# can find.
#
# function: f4
# -> Simplex Nelder-Mead minimization
# -> Hooke-Jeeves minimization
# -> Coordinate Axis search minimization
#
#########################################################
table = collections.OrderedDict()
for i in range(3, 4):
fun = functions[i]
x0 = [5, 5]
results = {}
tmp = []
# print("Simpleks:")
tmp.append(simplex_nelder_mead(x0, fun, print_stats=False))
tmp.append('iterations: ' + str(fun.iterations))
results['simplex'] = tmp.copy()
tmp.clear()
# print("Hooke-Jeeves:")
tmp.append(hooke_jeeves(x0, fun, print_stats=False))
tmp.append('iterations: ' + str(fun.iterations))
results['hookes'] = tmp.copy()
tmp.clear()
#print("Coordinate axis:")
tmp.append(coordinate_axis_search(x0, fun, print_stats=False))
tmp.append('iterations: ' + str(fun.iterations))
results['coordinate'] = tmp.copy()
tmp.clear()
table["f{}".format(i+1)] = results.copy()
results.clear()
for k, v in table.items():
print(k + ":")
for k1, v1 in v.items():
print("\t" + k1, v1)
####################################################################