-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtensor_analyze.m
44 lines (34 loc) · 1.35 KB
/
tensor_analyze.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
function [] = tensor_analyze(A)
addpath("Tensor-tensor-product-toolbox-master/tproduct toolbox 1.0/");
% Get image dimensions
[rows,cols,channels] = size(A);
% using the defualt transformation
[U,S,V] = tsvd(A,'econ');
% cumsum algorithm, sum in 3rd dim.
cum_e = cumsum(diag(sum(S,3)))/sum(diag(sum(S,3)));
% find the 90 percent cut off
cut_90 = find(cum_e>.9, 1 );
% find the 99.99 percent cut off ( for croppping )
cut_0 = find(cum_e>0.9999,1);
% plotting the cumulative energy
figure();
subplot(1, 2, 1);
plot(cum_e(1:cut_0+10)), grid on, hold on;
title("Cumulative energy in singular values")
ylabel("Cumulative Energy");
xlabel("r");
% draw cut off lines
%xline(cut_90,'Color','red', 'DisplayName','90% cutoff');
xline(cut_90, '-.','90% Cutoff','DisplayName', 'Cumulative energy cutoff','Color','red');
%xline(cut_0,'Color','blue');
% plotting the singular value
subplot(1,2,2);
cropped_S = diag(sum(S,3));
semilogy(cropped_S(1:cut_0+4),'-ok','LineWidth',1.5), grid on, hold on;
title("Singular values per rank")
ylabel("Singular Value");
xlabel("r");
% draw cut off lines
xline(cut_90, '-.','90% Cutoff','DisplayName', 'Cumulative energy cutoff','Color','red');
%xline(cut_0,'Color','blue');
end