-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_CUR_rank.m
153 lines (136 loc) · 5.58 KB
/
main_CUR_rank.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
%% yijun@natt.oden.utexas.edu
% scp <file> yijun@natt.oden.utexas.edu:/h2/yijun/Documents/MATLAB/RandNLA/dataset/
% path = '/h2/yijun/Documents/MATLAB/RandNLA/CUR/';
% path_result_cache = '/h2/yijun/Documents/MATLAB/RandNLA/CUR/result_cache/';
% path_target = '/h2/yijun/Documents/MATLAB/RandNLA/dataset/';
% addpath('/h2/yijun/Documents/MATLAB/lapack')
%% load input data
clear; close;
% path = '/h2/yijun/Documents/MATLAB/RandNLA/CUR/';
% path_target = '/h2/yijun/Documents/MATLAB/RandNLA/dataset/';
path_target = '/Users/ydong/Documents/MATLAB/OdenUT/RandNLA/dataset/';
path = '/Users/ydong/Documents/MATLAB/OdenUT/RandNLA/CUR/';
algos = {'RSVDDEIM','LUPP','LUPP2pass','CPQR','CPQR2pass','RSVDLS','SRCUR'};
% algos = {'CPQRstream', 'LUPPstream', 'RSVDDEIMstream', 'RSVDLSstream'};
% tag = 'large';
% tag = 'snn-1e3-1e3_a2b1_k100_r1e3_s1e-3';
% tag = 'yaleface-64x64';
% tag = 'mnist-train';
% tag = 'hemholtz4000x4000';
tag = 'laplace4000x4000';
target = load(strcat(path_target, sprintf('target_%s.mat',tag)));
A = target.A;
k = load(sprintf('rank_%s.mat',tag)); k = k.k;
% test_CUR_rank(k, target, tag, algos)
% scp yijun@natt.oden.utexas.edu:/h2/yijun/Documents/MATLAB/RandNLA/CUR/*_ACTIVSg2000.mat
% tag = strcat(tag,'-srcur');
% algos = {'SRCUR','CPQR','LUPP','LUPP2pass','RSVDDEIM','RSVDLS'};
% algos = {'CPQRstream', 'LUPPstream', 'RSVDDEIMstream', 'RSVDLSstream'};
% test_CUR_rank(k, target, tag, algos);
%% load output data
time = load(sprintf('time_%s.mat',tag));
errfro = load(sprintf('errfro_%s.mat',tag));
err2 = load(sprintf('err2_%s.mat',tag));
%% % % % % % % % % % % Plots % % % % % % % % % %
algos = {'RSVDDEIM','LUPP','LUPP2pass','CPQR','CPQR2pass',...
...'RSVDLS','SRCUR'...
};
markers = {'o','s','d','^','v','>','<','p','h','+','*','x'};
legmap = struct('DetCPQR','Det-CPQR',...
'CPQR','Rand-CPQR',...
'CPQR2pass','Rand-CPQR-1piter',...
'CPQR2passOrtho','Rand-CPQR-1piter-ortho',...
'CSCPQR','CS-CPQR',...
'CPQRstream','Stream-CPQR',...
'CSCPQRstream','Stream-CPQR',...
...
'DetLUPP','Det-LUPP',...
'LUPP','Rand-LUPP',...
'LUPP2pass','Rand-LUPP-1piter',...
'LUPP2passOrtho','Rand-LUPP-1piter-ortho',...
'CSLUPP','CS-LUPP',...
'LUPPstream','Stream-LUPP',...
...
'SVDDEIM','SVD-DEIM',...
'RSVDDEIM','RSVD-DEIM',...
'CSSVDDEIM','CSSVD-DEIM',...
'RSVDDEIMstream','Stream-SVD-DEIM',...
'CSSVDDEIMstream','Stream-SVD-DEIM',...
...
'LUCP','Det-LUCP',...
'ACA','DenseSketch-ACA',...(stream)
'CSLUCP','SparseSketch-LUCP',...(stream)
...
'SVDLS','SVD-LS',...
'RSVDLS','RSVD-LS',...
'CSSVDLS','CSSVD-LS',...
'RSVDLSstream','Stream-SVD-LS',...
'CSSVDLSstream','Stream-SVD-LS',...
...
'SRCUR','SRCUR');
labels = arrayfun(@(i) legmap.(algos{i}), 1:length(algos), 'UniformOutput',false);
mkmap = struct('RSVDDEIM', strcat('m', markers{1},'-'), ...
'LUPP', strcat('c', markers{2},'-'), ...
'LUPP2pass', strcat('c', markers{2},':'), ...
'CPQR', strcat('r', markers{3},'-'), ...
'CPQR2pass', strcat('r', markers{3},':'), ...
'RSVDLS', strcat('g', markers{4},'-'), ...
'SRCUR', strcat('b', markers{5},'-'));
markers = arrayfun(@(i) mkmap.(algos{i}), 1:length(algos), 'UniformOutput',false);
sigma = target.sigma;
sfro = sqrt(cumsum(sigma.^2,'reverse'));
% tag = '$10^3 \times 10^3$ SNN($a=2,b=1,k=10^2$,rank$=10^3$)';
% tag = 'Random weighted Laplacian $n=1000, m=4n$';
% tag = 'Dense Gaussian matrix $1000 \times 1000$';
% frobenius norm
err = errfro;
optimal = sfro;
ed = length(k)-2;
figure()
semilogy(k, optimal(k+1)./optimal(1), 'k.-', 'MarkerSize',20, 'LineWidth', 1.5)
hold on
for aux = 1:length(algos)
semilogy(k, (err.(algos{aux}))./optimal(1), mkmap.(algos{aux}), 'LineWidth', 1.5)
end
hold off
xlim([k(1) k(ed)])
xlabel('$k$','interpreter','latex')
ylabel('$||A-CUR||_F/||A||_F$','interpreter','latex')
legend('$\sqrt{\sum_{i=k+1}^r \sigma_i^2}/\sqrt{\sum_{i=1}^r \sigma_i^2}$',...
labels{:},...
'interpreter','latex')
% title(sprintf('\\texttt{%s} Randomized',tag), 'interpreter','latex')
set(gca,'FontSize',22)
% spectral norm
err = err2;
optimal = sigma;
figure()
% subplot(1,2,1)
semilogy(k, optimal(k+1)./optimal(1), 'k.-', 'MarkerSize',20, 'LineWidth', 1.5)
hold on
for aux = 1:length(algos)
semilogy(k, (err.(algos{aux}))./optimal(1), mkmap.(algos{aux}), 'LineWidth', 1.5)
end
hold off
xlim([k(1) k(ed)])
xlabel('$k$','interpreter','latex')
ylabel('$||A-CUR||_2/||A||_2$','interpreter','latex')
% legend('$\sigma_{k+1}/\sigma_{1}$', labels{:}, 'interpreter','latex')
title('Spectral norm error', 'interpreter','latex')
set(gca,'FontSize',22)
% time
figure()
% subplot(1,2,2)
semilogy(k, time.(algos{1}), mkmap.(algos{aux}), 'LineWidth', 1.5)
hold on
for aux = 1:length(algos)
plot(k, time.(algos{aux}), mkmap.(algos{aux}), 'LineWidth', 1.5)
end
hold off
xlim([k(2) k(ed)])
xlabel('$k$','interpreter','latex')
ylabel('Time (s)','interpreter','latex')
% legend(labels{:}, 'interpreter','latex')
title('Runtime', 'interpreter','latex')
set(gca,'FontSize',22)
%% Appendix: experiments