-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex_bootstrap.m
More file actions
173 lines (131 loc) · 3.67 KB
/
Copy pathex_bootstrap.m
File metadata and controls
173 lines (131 loc) · 3.67 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
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
167
168
169
170
171
172
%% Computes multiscale representation of a video.
%% Requires the TT-toolbox to be installed
clc; clf; clear all; close all
levels = 8;
d = 3;
n = 2^(levels-1);
A = zeros(n*[1,1,10]);
for imgn = 1775:3054
name = sprintf('Bootstrap/b%05d.bmp', imgn);
tmp = imread(name);
tmp = im2double(rgb2gray(tmp));
tmp = imresize(tmp,[n n]);
A(:, :, imgn+1-1775) = tmp;
end
A_orig = A;
disp('loaded data')
A = tt_tensor(A)
disp('converted TT')
%%
rank_tol = 1e-6;
maxiter = 200;%100;%maximum number of iterations
conv_tol = 1e-6;
scale_ranks = [50:45:320 410:90:680];%maximum TT-rank for each scale
%errors
error_multi = zeros(length(scale_ranks),1);
error_TT = zeros(length(scale_ranks),1);
%storage costs
storage_multi = zeros(length(scale_ranks),1);
storage_TT = zeros(length(scale_ranks),1);
%computation times
times_multi = zeros(length(scale_ranks),1);
times_TT = zeros(length(scale_ranks),1);
for sind = 1:length(scale_ranks)
scale_rank = scale_ranks(sind)
warning('off')
m = levels;
levels_to_use = (levels-m+1):levels;
rank_list = [zeros(levels-m,1); scale_rank*ones(m,1)];
%compute the multiscale representation
tic
res2 = iterate_multiscale_TT(A, levels, levels_to_use, maxiter, rank_list, conv_tol, 0);
t1 = toc;
times_multi(sind) = t1;
%convert to full tensor to check accuracy
A1 = res2{1};
for k = 2:levels
A1 = downscale_TT(A1) + res2{k};
end
toc
%compare to tensor-train representation
tic
Adirect = (round(A,1e-16, ceil(0.95*sqrt(2)*scale_rank)));
t1 = toc;
times_TT(sind) = t1;
%compute accuracies
error_multi(sind) = norm(A-A1)/norm(A);
error_TT(sind) = norm(A-Adirect)/norm(A);
%compute storage-costs
st = 0;
for k = 1:levels
st = st + storage_size_osel(round(res2{k}, 1e-16));
end
%plot during loop
storage_multi(sind) = st;
storage_TT(sind) = storage_size_osel(Adirect);
figure(1)
hold on
plot(error_multi, numel(Ause)./storage_multi, '*-b')
plot(error_TT, numel(Ause)./storage_TT, '*-r')
end
%%
%plot results
clf
figure(1)
semilogy(error_multi, numel(Ause)./storage_multi, '*-b')
hold on
semilogy(error_TT, numel(Ause)./storage_TT, 's-r')
set(gca,...
'FontUnits','points',...
'FontSize',24,...
'TickLabelInterpreter','latex',...
'FontName','Times')
xlabel('Relative error',...
'FontUnits','points',...
'interpreter','latex',...
'FontSize',24,...
'FontName','Times')
ylim([0.8, 100])
ylabel('Compression ratio',...
'FontUnits','points',...
'interpreter','latex',...
'FontSize',24,...
'FontName','Times')
grid()
legend({'Multiscale', 'Tensor-train','$g:$ TR-format'},...
'location', 'NorthWest',...
'FontUnits','points',...
'interpreter','latex',...
'FontSize',24,...
'FontName','Times')
pbaspect([2 1 1])
% print -dpdf bootstrap_storageM200_larger.pdf
%%
clf
figure(2)
plot(error_multi, times_multi./(maxiter), '>:', 'Color', [0.6350 0.0780 0.1840])
hold on
plot(error_TT, times_TT, '<-.', 'Color',[0 0.4470 0.7410])
set(gca,...
'FontUnits','points',...
'FontSize',24,...
'TickLabelInterpreter','latex',...
'FontName','Times')
xlabel('Relative error',...
'FontUnits','points',...
'interpreter','latex',...
'FontSize',24,...
'FontName','Times')
ylabel('Time (s)',...
'FontUnits','points',...
'interpreter','latex',...
'FontSize',24,...
'FontName','Times')
grid()
legend({'Multiscale/iteration', 'Tensor-train'},...
'location', 'NorthEast',...
'interpreter','latex',...
'FontSize',24,...
'FontName','Times')
pbaspect([2 1 1])
% print -dpdf bootstrap_timeM200_larger.pdf