-
Notifications
You must be signed in to change notification settings - Fork 5
/
TrainDynamicTexture.m
123 lines (96 loc) · 3.29 KB
/
TrainDynamicTexture.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
clear;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set configuration options %
numberSequences = 200; % number of frame sequences to be used
folder_name = 'results'; % directory to save results (will be created)
data_path = '/path/to/data'; % path to directory containing .mat frame sequences
path_to_algorithms = 'algorithms/'; % path to stable LDS algorithms
DIMS = 3:30; % subspace dimensions for which you want to run algorithms
% set standard config options
options.graphic = 0;
options.posdef = 10e-12;
options.init = 0;
options.maxiter = 500000;
options.display = 0;
machine_tolerance = 10e-11;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% add data_path to working directory
addpath(data_path);
addpath(path_to_algorithms);
mkdir(folder_name);
% loop over subspace dimensions
for dim_i = 1:length(DIMS)
n = DIMS(dim_i);
% initialize error and time matrices to record scores
CG.error = nan(numberSequences, 1);
SUB.error = nan(numberSequences, 1);
LS.error = nan(numberSequences, 1);
WLS.error = nan(numberSequences, 1);
LS.stability = nan(numberSequences, 1);
CG.time = nan(numberSequences, 1);
SUB.time = nan(numberSequences, 1);
WLS.time = nan(numberSequences, 1);
% loop over frame sequences
for i = 0 : numberSequences-1
name = ['seq_', num2str(i)];
name
% load frame sequence i
load(name)
P = im2double(data);
Pnew = P';
% get SVD decomposition
if size(Pnew,2) < size(Pnew,1)
[V,S,U] = svd(Pnew,0);
else
[U,S,V] = svd(Pnew',0);
end
% slice SVD matrices
V = V(:,1:n);
S = S(1:n,1:n);
U = U(:,1:n);
M = S*V';
% create algorithm input matrices
Y = M(:,2:end);
X = M(:,1:end-1);
% run LS model
fprintf('LS error: \n');
LS.error(i+1) = norm(Y - Y*pinv(X) * X, 'fro')^2/2;
if max(abs(eig(Y*pinv(X)))) <= 1
LS.stability(i+1) = 1;
else
LS.stability(i+1) = 0;
end
% run SUB model
fprintf('Run SUB model \n');
timeSUB = clock;
A_SUB = learnSOCmodel(X, Y,options);
% record SUB time
SUB.time(i+1) = etime(clock, timeSUB);
% compute and record SUB error
if max(abs(eig(A_SUB))) <= 1 + machine_tolerance
SUB.error(i+1) = norm(Y - A_SUB * X, 'fro')^2/2;
end
% run WLS model
fprintf('Run WLS model \n');
timeWLS = clock;
[A_WLS, ~, ~] = learnWLSmodel(V,S,1,0);
% record WLS time
WLS.time(i+1) = etime(clock, timeWLS);
% compute and record WLS error
if max(abs(eig(A_WLS))) <= 1 + machine_tolerance
WLS.error(i+1) = norm(Y - A_WLS * X, 'fro')^2/2;
end
% run CG model
fprintf('Run CG model \n');
timeCG = clock;
[A_CG, scores, ~] = learnCGModel(X, Y,1, 0);
% record CG time
CG.time(i+1) = etime(clock, timeCG);
% compute and record CG error
if max(abs(eig(A_CG))) <= 1 + machine_tolerance
CG.error(i+1) = norm(Y - A_CG * X, 'fro')^2/2;
end
% store results to dik
save([folder_name, '/Errors_and_Times_dim_', num2str(n),'.mat'], 'CG', 'WLS', 'SUB', 'LS');
end
end