forked from andrewssobral/lrslibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_algorithm_ntf.m
100 lines (93 loc) · 3.49 KB
/
run_algorithm_ntf.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
%%% NTF algorithms
% struct = run_algorithm_ntf(string, tensor)
%
function results = run_algorithm_ntf(algorithm_id, T)
lrs_load_conf;
alg_path = fullfile(lrs_conf.ntf_path,algorithm_id);
addpath(genpath(alg_path));
L = zeros(size(T)); % low-rank tensor
S = zeros(size(T)); % sparse tensor
results.cputime = 0;
timerVal = tic;
% warning('off','all');
try
%
% NTF | betaNTF | Simple beta-NTF implementation (Antoine Liutkus, 2012)
% process_video('NTF', 'betaNTF', 'dataset/demo.avi', 'output/demo_beta-NTF.avi');
%
if(strcmp(algorithm_id,'betaNTF'))
% Compute a simple NTF model of 10 components
A = double(T);
r = 10;
[~,~,~,L] = betaNTF(A,r);
S = (A - L);
% For reconstruction
% for i = 1:r, B_hat(:,:,i) = W * diag(Q(i,:)) * H'; end
end
%
% NTF | NTD-MU | Non-negative Tucker Decomposition solved by Multiplicative Updates (Zhou et al. 2012)
% NTF | NTD-APG | Non-negative Tucker Decomposition solved by Accelerated Proximal Gradient (Zhou et al. 2012)
% NTF | NTD-HALS | Non-negative Tucker Decomposition solved by Hierarchical ALS (Zhou et al. 2012)
%
% process_video('NTF', 'NTD-MU', 'dataset/demo.avi', 'output/demo_NTD-MU.avi');
% process_video('NTF', 'NTD-APG', 'dataset/demo.avi', 'output/demo_NTD-APG.avi');
% process_video('NTF', 'NTD-HALS', 'dataset/demo.avi', 'output/demo_NTD-HALS.avi');
%
if(strcmp(algorithm_id,'NTD-MU') ...
|| strcmp(algorithm_id,'NTD-APG') ...
|| strcmp(algorithm_id,'NTD-HALS'))
alg_path = fullfile(lrs_conf.ntf_path,'lraNTD');
addpath(genpath(alg_path));
R = [size(T,1) size(T,2) 2];
if(strcmp(algorithm_id,'NTD-MU'))
opts = struct('NumOfComp',R,'nlssolver','mu','maxiter',100,'maxiniter',20,'tdalgFile','call_tucker_als_opts.mat');
end
if(strcmp(algorithm_id,'NTD-APG'))
opts = struct('NumOfComp',R,'nlssolver','apg','maxiter',100,'maxiniter',20,'tdalgFile','call_tucker_als_opts.mat');
end
if(strcmp(algorithm_id,'NTD-HALS'))
opts = struct('NumOfComp',R,'nlssolver','hals','maxiter',100,'maxiniter',20,'tdalgFile','call_tucker_als_opts.mat');
end
T_hat = lraNTD_ANLS(T, opts);
L = double(tensor(T_hat));
S = double(T) - L;
end
%
% NTF | bcuNTD | Non-negative Tucker Decomposition by block-coordinate update (Xu and Yin, 2012)
% process_video('NTF', 'bcuNTD', 'dataset/demo.avi', 'output/demo_bcuNTD.avi');
%
if(strcmp(algorithm_id,'bcuNTD'))
% Compute a simple NTF model of 10 components
A = double(T);
R = [size(T,1) size(T,2) 2]; % tensor rank
opts.maxit = 1000; % max number of iterations
opts.tol = 1e-4; % stopping tolerance
[M,C] = ntd(T,R,opts);
L = (double(full(ttensor(C,M))));
S = (A - L);
end
%
% NTF | bcuNCP | Non-negative CP Decomposition by block-coordinate update (Xu and Yin, 2012)
% process_video('NTF', 'bcuNCP', 'dataset/demo.avi', 'output/bcuNCP.avi');
%
if(strcmp(algorithm_id,'bcuNCP'))
% Compute a simple NTF model of 10 components
A = double(T);
R = 10; % tensor rank
opts.maxit = 1000; % max number of iterations
opts.tol = 1e-4; % stopping tolerance
M = ncp(T,R,opts);
L = double(full(M));
S = (A - L);
end
catch ex
warning(ex.message);
end
%
cputime = toc(timerVal);
rmpath(genpath(alg_path));
%
results.L = L; % low-rank tensor
results.S = S; % sparse tensor
results.cputime = cputime;
end