-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstrained_bcktrck_test.asv
More file actions
82 lines (53 loc) · 1.63 KB
/
constrained_bcktrck_test.asv
File metadata and controls
82 lines (53 loc) · 1.63 KB
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
%% LOADING THE VARIABLES FOR THE TEST
clear
clc
% Init. Armijo's parameters
alpha0 = 0.4;
c1 = 1e-4;
rho = 0.8;
btmax = 50;
disp('**** PARAMETERS: alpha c1 rho btmax *****')
format short
[alpha0 c1 rho btmax]
for n = [1e+4 , 1e+6]
% Variables for data visualization
iterations = zeros(6,1);
time = zeros(6,1);
res = zeros(6,1);
fres = zeros(6,1);
minx = zeros(6,1);
i = 1;
for a = [2, 4, 6, 8, 10, 12]
tic
x0 = rand(1,n)';%+3*rand(1,n)'; % starting point outside the constraint
kmax = 1000;
tollgrad = 1e-12;
h = 10^(-a)*norm(x0);
f = @(x)sum(1/4*x.^4 +1/2*x.^2-x);
f_component = @(x) (1/4*x.^4 +1/2*x.^2-x);
%finite difference
gradf = @(x) findiff_grad(f_component, x, h, 'fw');
% exact derivatives
% gradf = @(x) (x.^3 + x -1);
%set constraints
mins= ones(n,1);
maxs= ones(n,1)*2;
%% RUN THE STEEPEST DESCENT
gamma = 0.1;
tolx = 1e-6;
% Projection function
Pi_X = @(x) box_projection(x,mins,maxs);
[xk, fk, gradfk_norm, deltaxk_norm, k, btseq] = ...
constr_steepest_desc_bcktrck(x0, f, gradf, alpha0, kmax, ...
tollgrad, c1, rho, btmax, gamma, tolx, Pi_X);
% outpu
time(i) = toc;
iterations(i) = k;
fres(i) = fk;
minx(i) = min(xk);
i = i+1;
end
disp(['**** STEEPEST DESCENT N:',num2str(n),' *****'])
format short
[time iterations minx fres/1e4]
end