-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_spectra_data.m
144 lines (121 loc) · 4.47 KB
/
test_spectra_data.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
%% Testing the working of iiCG, FISTA and ISTA on the Spectra Problem
% Closing all open figures
close all;
%{
-- If you do not have the spectra dataset on your MATLAB version, use the
'spectra.mat' file given in this repository. Use the following command
to import the dataset into your MATLAB workspace:
$ spectra = importdata('spectra.mat')
-- This code can be executed only after the dataset has been imported
into your workspace.
-- Use the following command to get an idea on what the dataset is about:
$ spectra.Description
%}
% Obtaining B and y values from the spectra dataset
Gamma = 0.1;
B = spectra.NIR; % 60 x 401
y = spectra.octane; % 60 x 1
% Forming A and b corresponding to the quadratic L1 problem form of the
% Spectra Problem.
A = B'*B + 2*Gamma*eye(size(B,2));
b = B'*y;
tau = 1* ones(size(B,2),1);
% Running iiCG
problem.Ax = @(x) A*x;
problem.tau = tau;
problem.b = b;
[out1,out2] = alg_ql1(problem);
fvals_iicg = out2.fValues;
% Running FISTA
tau = tau(1);
max_iter = length(fvals_iicg)+15;
[~,func_eval_fista,~,~,~] = FISTA(A,b,tau,Gamma,max_iter,'quad_l1');
% Running ISTA
tau = tau(1);
max_iter = length(fvals_iicg)+15;
[~,func_eval_ista,~,~] = ISTA(A,b,tau,Gamma,max_iter,'quad_l1');
% Finding the lowest function value among the 3 methods.
Fstar = min([min(fvals_iicg), min(func_eval_ista), min(func_eval_fista)]);
% Calculating tolerances
tol_iiCG = (fvals_iicg - Fstar)/abs(Fstar);
tol_fista = (func_eval_fista - Fstar)/abs(Fstar);
tol_ista = (func_eval_ista - Fstar)/abs(Fstar);
% Plotting the tolerance for each of ISTA, FISTA and iiCG
figure;
plot(tol_ista, 'r', 'LineWidth', 1.5);
hold on;
plot(tol_fista, 'k', 'LineWidth', 1.5);
hold on;
plot(tol_iiCG, 'b', 'LineWidth', 1.5);
legend('ISTA', 'FISTA', 'iiCG');
grid on;
xlabel('Number of Matrix-Vector Products', 'Interpreter','latex', 'FontSize', 13)
ylabel('Tolerance ($\frac{F(x^t)-F^*}{|F^*|}$)', 'Interpreter','latex', 'FontSize', 13)
title('Plot of Tolerance vs Matrix-Vector Products for Spectra Problem')
print('plots/tolvsMV','-dpng');
% Plotting with logarithmic y axis
figure;
semilogy(tol_ista, 'r', 'LineWidth', 1.5);
hold on;
semilogy(tol_fista, 'k', 'LineWidth', 1.5);
hold on;
semilogy(tol_iiCG, 'b', 'LineWidth', 1.5);
legend('ISTA', 'FISTA', 'iiCG');
grid on;
ylim([1e-12 inf]);
xlabel('Number of Matrix-Vector Products', 'Interpreter','latex', 'FontSize', 13)
ylabel('Tolerance ($\frac{F(x^t)-F^*}{|F^*|}$)', 'Interpreter','latex', 'FontSize', 13)
title('Plot of Tolerance vs Matrix-Vector Products for Spectra Problem')
print('plots/tolvsMV_log','-dpng');
% Plotting CG Move Count for iiCG
figure;
plot(out2.CGmvcount, 'LineWidth', 1.5);
grid on;
xlabel('Iterations')
ylabel('CG Move Count')
title('Plot of Number of CG moves vs Iterations for Spectra Problem')
print('plots/CG','-dpng');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Plotting for more number of iterations
% Running FISTA
tau = tau(1);
max_iter = 800;
[x_fista,func_eval_fista,~,~,~] = FISTA(A,b,tau,Gamma,max_iter,'quad_l1');
% Running ISTA
tau = tau(1);
max_iter = 800;
[x_ista,func_eval_ista,~,~] = ISTA(A,b,tau,Gamma,max_iter,'quad_l1');
% Finding the lowest function value among the 3 methods.
Fstar = min([min(fvals_iicg), min(func_eval_ista), min(func_eval_fista)]);
% Calculating tolerances
tol_iiCG = (fvals_iicg - Fstar)/abs(Fstar);
tol_fista = (func_eval_fista - Fstar)/abs(Fstar);
tol_ista = (func_eval_ista - Fstar)/abs(Fstar);
% Plotting the tolerance for each of ISTA, FISTA and iiCG
figure;
plot(tol_ista, 'r', 'LineWidth', 1.5);
hold on;
plot(tol_fista, 'k', 'LineWidth', 1.5);
hold on;
plot(tol_iiCG, 'b', 'LineWidth', 1.5);
legend('ISTA', 'FISTA', 'iiCG');
grid on;
xlabel('Number of Matrix-Vector Products', 'Interpreter','latex', 'FontSize', 13)
ylabel('Tolerance ($\frac{F(x^t)-F^*}{|F^*|}$)', 'Interpreter','latex', 'FontSize', 13)
title('Plot of Tolerance vs Matrix-Vector Products for Spectra Problem')
print('plots/tolvsMVlong','-dpng');
% Plotting with logarithmic y axis
figure;
semilogy(tol_ista, 'r', 'LineWidth', 1.5);
hold on;
semilogy(tol_fista, 'k', 'LineWidth', 1.5);
hold on;
semilogy(tol_iiCG, 'b', 'LineWidth', 1.5);
legend('ISTA', 'FISTA', 'iiCG');
grid on;
ylim([1e-12 inf]);
xlabel('Number of Matrix-Vector Products', 'Interpreter','latex', 'FontSize', 13)
ylabel('Tolerance ($\frac{F(x^t)-F^*}{|F^*|}$)', 'Interpreter','latex', 'FontSize', 13)
title('Plot of Tolerance vs Matrix-Vector Products for Spectra Problem')
print('plots/tolvsMV_loglong','-dpng');