ivan@155
|
1 clear
|
ivan@155
|
2 M = 20; % Signal length
|
ivan@155
|
3 N = 40; % Coefficient Space Dimension
|
ivan@155
|
4 L = 32*N; % Number of Training Samples
|
ivan@155
|
5 R = 3; % Sparsity
|
ivan@155
|
6 IT = 1000; % Number of alternating sparse approximation and dictionary update
|
ivan@155
|
7 map = 1; % Debiasing. 0 = No, 1 = Yes
|
ivan@155
|
8 maxIT = 1000; % Inner-loop maximum iteration number.
|
ivan@155
|
9 lambda = 2*.2; % Lagrangian multiplier.
|
ivan@155
|
10 epsx = 10^-7; % Stopping criterion for iterative softthresholding
|
ivan@155
|
11 epsd = 10^-7; % Stopping criterion for MM dictionary update
|
ivan@155
|
12 cvset = 0; % Dictionary constraint. 0 = Non convex ||d|| = 1, 1 = Convex ||d||<=1
|
ivan@155
|
13 Tre = .99; % Threshold for accepting too atoms identical
|
ivan@155
|
14 %%%% Generative Dictionaries
|
ivan@155
|
15 Do = randn(M,N); % Generative Dictionary
|
ivan@155
|
16 Do = Do*(diag(sum((Do'*Do).*eye(length(Do))).^-.5)); % Normalization
|
ivan@155
|
17 %%%% Sparse signal generation %%%%%
|
ivan@155
|
18 Xo = zeros(N,L); % Original Sparse Coefficients
|
ivan@155
|
19 for l = 1:L
|
ivan@155
|
20 r = 1;
|
ivan@155
|
21 while r<=R
|
ivan@155
|
22 ind = fix(rand(1)*N)+ones(1);
|
ivan@155
|
23 a = rand(1);
|
ivan@155
|
24 if Xo(ind)==0
|
ivan@155
|
25 Xo(ind,l) = (.8*rand(1)+.2)*((a>=.5)-(a<.5));
|
ivan@155
|
26 r = r+1;
|
ivan@155
|
27 end
|
ivan@155
|
28 end
|
ivan@155
|
29 end
|
ivan@155
|
30 Y = Do*Xo; % Sparse Signals
|
ivan@155
|
31 %%%% Algorithm initialization
|
ivan@155
|
32 D = randn(M,N); % Initial Dictionary
|
ivan@155
|
33 D = D*(diag(sum((D'*D).*eye(length(D))).^-.5)); % Normalization
|
ivan@155
|
34 X = ones(size(Xo)); % Initial coefficients
|
ivan@155
|
35 for it = 1:IT,
|
ivan@155
|
36 it
|
ivan@155
|
37 to = .1+svds(D,1);
|
ivan@155
|
38 [X,cost(it)] = mm1(D,Y,X,to,lambda,maxIT,epsx,map);
|
ivan@155
|
39 plot(cost);
|
ivan@155
|
40 [D,X] = dict_update_REG_cn(D,Y,X,maxIT,epsd,cvset);
|
ivan@155
|
41 end
|
ivan@155
|
42 %%%
|
ivan@155
|
43 success = sum(max(abs((Do'*D)))>=Tre);
|
ivan@155
|
44 display([' ------------------'])
|
ivan@155
|
45 display([' ',num2str(success),'% of the atoms successfully recovered after ',num2str(IT),' iterations.']); |