-
Notifications
You must be signed in to change notification settings - Fork 5
/
stmiss_fed_rhovar.m
164 lines (126 loc) · 4.57 KB
/
stmiss_fed_rhovar.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
154
155
156
157
158
159
160
161
162
163
164
clear;
clc;
addpath('NORST-rmc-master/');
addpath('NORST-rmc-master/PROPACK');
%% Algorithms to run
NORST = 1;
NORST_OFFLINE = 0;
%% Parameter Initialization
n = 1000;
t_max = 3000;
alpha = 60;
f = 100;
MC = 50;
t_calc_pca = [1:alpha: t_max];
t_calc = t_calc_pca;
%sigrange = [1, 1e-2, 1e-4, 1e-6];
sigrange = [0.1, 0.2, 0.4, 0.6];
%NORST
temp_SE_NORST = zeros(length(t_calc_pca), MC);
temp_err_L_NORST = zeros(t_max, MC);
temp_SE_NORST_fed = zeros(length(t_calc_pca), length(sigrange), MC);
temp_err_L_NORST_fed = zeros(t_max, length(sigrange), MC);
t_NORST = 0;
err_L_fro_NORST = zeros(MC,1);
for mc = 1 : MC
sigcount = 1;
for rho = sigrange
fprintf('Monte-Carlo iteration %d, rho %.2f in progress \n', mc, rho);
%rho = 0.1; % fraction of missing entries
BernMat = rand(n, t_max);
T = 1 .* (BernMat <= 1 - rho); % observed entries' support
%% Generating low-rank matrix
r_0 = 30;
L = zeros(n, t_max);
lambda_min = sqrt(f)/2;
lambda_max = sqrt(f);
offset = 0; %if offset is not zero, eigenvalues (Lambda) are varying in time;
diag_entries1 = offset + [linspace(lambda_max, lambda_min, r_0)];
diag_entries2 = -offset + [linspace(lambda_max, lambda_min, r_0)];
coeff_train = zeros(r_0, t_max);
for cc = 1 : r_0
coeff_train(cc, 1:2:end-1) = -diag_entries1(cc) + ...
2 * diag_entries1(cc) * rand(1, t_max/2);
coeff_train(cc, 2:2:end) = -diag_entries2(cc) + ...
2 * diag_entries2(cc) * rand(1, t_max/2);
end
P = orth(randn(n, r_0));
delta_t = 100;
U0 = P;
subspace_size = 1500;
U_track = cell(ceil(t_max/subspace_size),1);
for i=1:length(U_track)
Btemp1 = randn(n);
B1 = (Btemp1 - Btemp1')/2;
t_1 = (i-1)*subspace_size + 1;
t_2 = min(i*subspace_size,t_max);
U_track{i} = U0;
L(:, t_1:t_2) = U0 * coeff_train(:,t_1:t_2);
U = expm(delta_t*B1)*U0;
U0 = U;
end
eps_noise = 0; % noise
L = L + eps_noise * (rand(n,t_max) - 0.5);
M = L .* T ;
%% Algorithm parameters for NORST
if(NORST == 1)
%fprintf('\tNORST\t');
K = 25;
ev_thresh = 7.5961e-04;
tol = 1e-16;
overlap_step = alpha; % if it is set to alpha then windows don't overlap
R = 0; % number of reuse
P_init = zeros(n,r_0);
t_norst_fed = tic;
[L_hat_fed, P_hat_fed, S_hat_fed, t_hat_fed, P_track_full_fed, t_calc_fed] = ...
NORST_fed_new(M, T, r_0, ev_thresh, alpha, K,R,overlap_step, 1e-6);
t_norst_fed = toc(t_norst_fed);
% t_norst = tic;
% [L_hat, P_hat, S_hat, t_hat, P_track_full, t_calc] = ...
% NORST_random(M, T, r_0, ev_thresh, alpha, K,R,overlap_step);
% t_NORST = toc(t_norst)
% err_L_fro_NORST(mc) = norm(L-L_hat,'fro')/norm(L,'fro');
end
%% Compute Performance Metrics
%frobenius norm errors
if(NORST == 1)
% temp_err_L_NORST(:, mc) = sqrt(mean((L - L_hat).^2, 1)) ...
% ./ sqrt(mean(L.^2, 1));
temp_err_L_NORST_fed(:, sigcount, mc) = (sqrt(mean((L - L_hat_fed).^2, 1)) ...
./ sqrt(mean(L.^2, 1)))';
end
%subspace errors
for jj = 1 : length(t_calc_pca)
tt = ceil(t_calc_pca(jj)/subspace_size);
if(NORST == 1)
% temp_SE_NORST(jj, mc) = ...
% Calc_SubspaceError(P_track_full{jj}, U_track{tt});
temp_SE_NORST_fed(jj, sigcount, mc) = ...
Calc_SubspaceError(P_track_full_fed{jj}, U_track{tt});
end
if(NORST_OFFLINE == 1)
temp_SE_NORST_off(jj, mc) = ...
Calc_SubspaceError(P_track_full{jj}, U_track{tt});
end
end
sigcount = sigcount + 1;
end
fprintf('\n')
end
% err_SE_NORST = mean(temp_SE_NORST, 2);
% err_L_NORST = mean(temp_err_L_NORST, 2);
err_SE_NORST_fed = mean(temp_SE_NORST_fed, 3);
err_L_NORST_fed = mean(temp_err_L_NORST_fed, 3);
figure
strx = 't';
stry = '$$\log_{10} dist(\hat{P}_{(t)}, P_{(t)})$$';
semilogy(t_calc_pca(1:2:end),err_SE_NORST_fed(1:2:end, 1),'-*r','LineWidth',2,'MarkerSize',10);
hold
semilogy(t_calc_pca(1:2:end),err_SE_NORST_fed(1:2:end, 2),'-*k','LineWidth',2,'MarkerSize',10);
semilogy(t_calc_pca(1:2:end),err_SE_NORST_fed(1:2:end, 3),'-*b','LineWidth',2,'MarkerSize',10);
semilogy(t_calc_pca(1:2:end),err_SE_NORST_fed(1:2:end, 4),'-*g','LineWidth',2,'MarkerSize',10);
grid on
axis tight
xlabel(strx, 'Interpreter', 'LaTeX', 'FontSize', 20);
ylabel(stry, 'Interpreter', 'LaTeX', 'FontSize', 20);
legend('sig1', 'sig2', 'sig3', 'sig4')