-
Notifications
You must be signed in to change notification settings - Fork 0
/
L1.m
81 lines (69 loc) · 1.73 KB
/
L1.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
close all;
clear;
%% Load data
sample_duration = 1000;
load(sprintf('Data/%ddata.mat',sample_duration));
%% Set parameters
if sample_duration == 1000
a = 0;
elseif sample_duration == 200
a = 0.01;
elseif sample_duration == 100
a = 0.01 ;
end
%% Set the correct weight vector
omega = [];
for i = 1:n-1
omega = [omega; abs(A(i,i+1:n).')];
end
%% L1
tic
cvx_begin
variable q(m)
J = -log_det(E*diag(q)*E' + e*e'/n) + 2*trace(S*E*diag(q)*E')/sigma^2;
g = a*norm(q,1);
minimize (J + g)
subject to
lambda_min(E*diag(q)*E' + e*e.'/n) > 0;
q >= 0
cvx_end
toc
%% Define the convex function
J = @(u) -log(det(E*diag(u)*E.' + e*e.'/n)) + 2*trace(S*(E*diag(u)*E.'))/sigma^2;
g = @(u) a*norm(u,1);
%% Display the result
A_vec = [];
edge = [];
count = 0;
for i = 1:n
for j=i+1:n
count = count+1;
edge = [edge, abs(A(i,j))];
if abs(A(i,j)) > 0
A_vec = [A_vec, count];
end
end
end
disp(q)
q_active = (abs(q)>=0.1);
find(q_active)'
A_vec
L2_error = norm((J(q) + g(q))-(J(omega) + g(omega)),2)
relative_error = norm(omega-q,2)/norm(omega,2)
figure;
stem(q, 'LineWidth',4);
hold on
stem(edge, 'LineWidth',4);
grid on
xlabel('edge');
xticks(1:m)
xlim([0 m+1])
ylim([-0.1 2.2])
legend('estimate', 'true', 'Location', 'northeastoutside');
title('solution q');
%% Save the result
if not(exist(sprintf("EstimateResult/L1_%d",sample_duration),'dir'))
mkdir(sprintf("EstimateResult/L1_%d",sample_duration))
end
date=datetime('now','Format','MM-dd HH-mm-ss');
save(sprintf("EstimateResult/L1_%d/L1_%d %s",sample_duration,sample_duration,date),'omega','a','edge','q',"L2_error","relative_error")