-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_IRCUR.m
67 lines (49 loc) · 1.95 KB
/
test_IRCUR.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
clear;
close all;
n = 5000; % Problem dimension m-by-n
m = n;
r = 5; % rank
alpha = 0.3; % Percentage of outliers
c = 5; % Parameter controls the size of outliers
%% Generate a RPCA problem
disp('Generating a RPCA problem.')
A_generater = randn(m,r);
B_generater = randn(r,n);
L_true = A_generater * B_generater;
norm_of_L_true = norm(L_true,'fro');
S_supp_idx = randsample(m*n, round(alpha*m*n), false);
S_range = c*mean(mean(abs(L_true)));
S_temp = 2*S_range*rand(m,n)-S_range;
S_true = zeros(m, n);
S_true(S_supp_idx) = S_temp(S_supp_idx);
norm_of_S_true = norm(S_true,'fro');
D = L_true + S_true;
%% IRCUR-R % Resample row/column version
disp('Running IRCUR-R now.')
para.beta_init = 1.5*max(abs(L_true(:)));
para.beta = para.beta_init;
para.tol = 1e-5;
para.con = 3;
para.resample = true;
[C1, pinv_U1, R1, ircur_r_timer, ircur_r_err] = IRCUR( D, r, para);
recover_err_ircur_r = norm(L_true - C1 * pinv_U1 * R1, 'fro') / norm(L_true,'fro')
%% IRCUR-F % Fix row/column version
disp('Running IRCUR-F now.')
para2.beta_init = 2*max(max(abs(L_true)));
para2.beta = para.beta_init;
para2.tol = 1e-5;
para2.con = 3;
para2.resample = false;
[C2, pinv_U2, R2, ircur_f_timer, ircur_f_err] = IRCUR( D, r, para2);
recover_err_ircur_f = norm(L_true - C2 * pinv_U2 * R2, 'fro') / norm(L_true,'fro')
%% Using All Defalut Setting % Check IRCUR.m for the defalut settings
[C3, pinv_U3, R3, ircur_d_timer, ircur_d_err] = IRCUR( D, r, '');
recover_err_ircur_d = norm(L_true - C3 * pinv_U3 * R3, 'fro') / norm(L_true,'fro')
%% Plot the converegence
figure;
plot(cumsum(ircur_r_timer),ircur_r_err,'bD-',cumsum(ircur_f_timer),ircur_f_err,'r+-',cumsum(ircur_d_timer),ircur_d_err,'g*-');
legend('ICUR-R','ICUR-F','IRCUR-Defalut');
title('Relative Error vs Runtime');
ylabel('Relative Error');
xlabel('Time(secs)');
set(gca,'YScale', 'log')