-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.m
166 lines (146 loc) · 5.22 KB
/
demo.m
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
format longE
% setup the path to include the 'utils' directory
directory = pwd
addpath(genpath(directory))
% define rosenbrock function
function [f,startp,xmin,fmin,domains] = f1_sym()
syms x1 x2
f = 100*(x2-x1^2)^2 + (1-x1)^2;
startp = [-1.8,-1.8]';
xmin = [1,1]';
fmin = 0;
domains = {[-inf,inf], [-inf,inf]};
end
function [f,startp,xmin,fmin,domains] = rosen_extended_sym(n)
x1 = sym('x1');
x2 = sym('x2');
f = 100*(x2-x1^2)^2 + (1-x1)^2;
startp = [-1.2,1];
xmin = [1,1];
domains = {[-inf,inf], [-inf,inf]};
for i = 3:n
sym_ith = sym(['x',num2str(i)]);
if i == 3
sym_ith_prev = x2;
else
sym_ith_prev = sym(['x',num2str(i-1)]);
end
f += (1 - sym_ith_prev)^2 + 100*(sym_ith - sym_ith_prev^2)^2;
if mod(i,2) == 0
startp(end+1) = 1;
else
startp(end+1) = -1.2;
end
xmin(end+1) = 1;
domains{end+1} = [-inf,inf];
end
startp = startp';
xmin = xmin';
fmin = 0;
end
function [f,startp,xmin,fmin,domains] = rosen2()
[f,startp,xmin,fmin,domains] = rosen_extended_sym(2);
end
config.a = 1;
config.rho = 0.5;
config.c = 0.1;
config.eps = 1e-16;
config.max_iters = 200;
config.max_iters_step_size = 100;
search_x = -1.2:0.1:1.2;
search_y = -1.2:0.1:1.2;
[f1,startp,xmin,fmin,domains] = f1_sym();
% fmin 0: (a=1,rho=0.5,c=0.1,eps=1e-16,max_iters=200,max_iters_step_size=100)
% [xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"newton", "backtracking_armijo",config);
% fmin 1e-6: (a=1,rho=0.5,c=0.1,eps=1e-16,max_iters=5000,max_iters_step_size=50), the last one doesn't matter, usually the backtracking finds a solution within 8 iters
% fmin 5.41e-8: (a=1,rho=0.6,c=0.1,eps=1e-16, max_iters=5000,max_iters_step_size=50)
% fmin 4.42e-12: (a=1,rho=0.6,c=0.1,eps=1e-16, max_iters=1e4,max_iters_step_size=50)
% fmin 2.25e-10: (a=1,rho=0.7,c=0.1,eps=1e-16,max_iters=1e4,max_iters_step_size=50)
% increasing the numbers of iterations it is converging
config.a = 1;
config.rho = 0.6;
config.c = 0.1;
config.eps=1e-16;
config.max_iters = 1000;
config.max_iters_step_size = 50;
% [xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"steepest", "backtracking_armijo",config);
% fmin 3e-31 (a=1,rho=2,c1=1e-4,c2=0.9,eps=1e-16,max_iters=1000,max_iters_step_size=50,max_iters_zoom=10)
config.a = 1;
config.rho = 2;
config.c1 = 1e-4;
config.c2 = 0.9;
config.eps=1e-16;
config.max_iters = 1000;
config.max_iters_step_size = 50;
config.max_iters_zoom = 10;
% [xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"newton", "wolfe_strong",config);
% fmin 6.86e-03 (a=1,rho=2,c1=1e-4,c2=0.9,eps=1e-16,max_iters=1000,max_iters_step_size=50,max_iters_zoom=10)
% fmin 9.73e-04 (a=1,rho=2,c1=1e-4,c2=0.9,eps=1e-16,max_iters=1e4,max_iters_step_size=50,max_iters_zoom=10)
config.a = 1;
config.rho = 2;
config.c1 = 1e-4;
config.c2 = 0.9;
config.eps=1e-16;
config.max_iters = 1e4;
config.max_iters_step_size = 50;
config.max_iters_zoom = 10;
% [xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"steepest", "wolfe_strong",config);
% fmin 0 (a=1,rho=2,c1=1e-4,c2=0.9,rho=2,eps=1e-16,max_iters=1e4,max_iters_step_size=50,max_iters_zoom=10,memory_limit=50)
config.a = 1;
config.rho = 2;
config.c1 = 1e-4;
config.c2 = 0.9;
config.eps=1e-16;
config.max_iters = 1e4;
config.max_iters_step_size = 50;
config.max_iters_zoom = 10;
config.memory_limit = 50;
% [xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"newton", "grippo_wolfe_strong");
config.a = 1;
config.rho = 5;
config.c1 = 1e-4;
config.c2 = 0.9;
config.eps=1e-16;
config.max_iters = 200;
config.max_iters_step_size = 50;
config.max_iters_zoom = 50;
config.memory_limit = 50;
% [xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"steepest", "grippo_wolfe_strong",config);
% fmin 0 (a=1,rho=0.6,c=0.1,eps=1e-16,max_iters=1e4,max_iters_step_size=50,memory_limit=50)
config.a = 1;
config.rho = 0.6;
config.c = 0.1;
config.eps=1e-16;
config.max_iters = 1e4;
config.max_iters_step_size = 50;
config.memory_limit = 50;
% [xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"newton", "grippo_backtracking_armijo",config);
% fmin 4.76 (a=1,rho=0.6,c=0.1,eps=1e-16,max_iters=1e4,max_iters_step_size=50,memory_limit=50)
config.a = 1;
config.rho = 0.6;
config.c = 0.1;
config.eps=1e-16;
config.max_iters = 1000;
config.max_iters_step_size = 50;
config.memory_limit = 10;
[xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"steepest", "grippo_backtracking_armijo",config,"search_x",search_x,"search_y",search_y);
%
config.a = 1;
config.rho = 2;
config.c1 = 1e-4;
config.c2 = 0.9;
config.eps=1e-16;
config.max_iters = 100;
config.max_iters_step_size = 50;
config.max_iters_zoom = 10;
config.memory_limit = 20;
% [xmin, fmin] = minimize(rosen2, domains, [-1.2,1]',"steepest", "grippo_wolfe_strong",config,"search_x",search_x,"search_y",search_y);
% [xmin, fmin] = minimize(rosen2, domains, [-1.2,1]',"steepest", "grippo_wolfe_strong",config,"search_x",search_x,"search_y",search_y);
% fmin 6.43 (a=1,rho=0.6,c=0.1,eps=1e-16,max_iters=1e4,max_iters_step_size=50)
config.a = 1;
config.rho = 0.6;
config.c = 0.1;
config.eps=1e-16;
config.max_iters = 1e4;
config.max_iters_step_size = 50;
% [xmin, fmin] = minimize(f1, domains, [-1.8,-1.8]',"minimize", "hanger_zhang_backtracking_armijo",config,"search_x",search_x,"search_y",search_y);