-
Notifications
You must be signed in to change notification settings - Fork 3
/
example1.m
154 lines (101 loc) · 3.72 KB
/
example1.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
%% Example of execution of Adaptive Diffusion Networks
%
%
clc; clear; close all;
%% Location of code
addpath('functions');
%% Parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FLAG if 1 returns all the evolution of parameters vector w
FLAG_RETURN_W = 0;
Tmax = 20000; % Number of iterations
n_sim = 2; % Number of simulations to average
% We load the network and parameters of setup:
% Adjacency matrix A
% Number of nodes n_nodes
% Number of tabs M
% Vector to estimate (if has a change w0_1 and w0_2)
% snr values
% sigma2_u values
% mu_filter
load('inputs/example_complex.mat');
%load('inputs/example_basic.mat');
% Struct with the algorithms to execute
algorithms = { 'atc_nlms_nocoop', 'atc_nlms_acw','atc_nlms_metropolis',...
'datc_nlms_ls_exp'};
% Diffusion algorithm parameters
params.atc_nlms_acw.nu = 0.01; % learning parameter for the combination
% params.datc_nlms_ls_rect.L = 100; % Window size for combination estimation
% params.datc_nlms_ls_rect.regul = 1e-12;
params.datc_nlms_ls_exp.gamma = 0.99; % Window size for combination estimation
params.datc_nlms_ls_exp.regul = 1e-10;
% Error model parameters (no errors)
error_param.mode = 'none';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
display(A); % display Adjacency Matrix
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% SIMULATION
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Initialization of output structures
for a = 1:length(algorithms)
algorithm = algorithms{a};
msd_array.(algorithm) = 0;
emse_array.(algorithm) = 0;
c.(algorithm) = 0;
end
for iter = 1:n_sim
disp(['Simulation ' num2str(iter)]);
disp('-------------------------------------');
[msd, errors, c_aux, w0, u, v, d] = sim_an( algorithms, Tmax, ...
n_nodes, A, sigma2_u, snr, w0_1, w0_2, mu_filter, params, error_param,...
FLAG_RETURN_W);
% Accumulate results
for a = 1:length(algorithms)
algorithm = algorithms{a};
msd_array.(algorithm) = msd.(algorithm) + msd_array.(algorithm);
emse_array.(algorithm) = ...
(errors.(algorithm) - v).^2 + emse_array.(algorithm);
c.(algorithm) = c_aux.(algorithm) + c.(algorithm);
end
disp(' ');
end
% Divide to obtain averages
for a = 1:length(algorithms)
algorithm = algorithms{a};
msd_array.(algorithm)= msd_array.(algorithm) ./ n_sim;
emse_array.(algorithm) = emse_array.(algorithm)./n_sim;
c.(algorithm) = c.(algorithm) ./ n_sim;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% PLOT RESULTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
algorithms_plot = ...
cellfun(@get_algorithm_name_plot, algorithms, 'UniformOutput', 0);
colors = 'rgbmcky';
figure(1)
for a = 1:length(algorithms)
algorithm = algorithms{a};
network_msd = mean(msd_array.(algorithm)) ;
plot(10*log10(network_msd),colors(a)); hold on;
end
title('NETWORK MSD (dB)');
legend(algorithms_plot);
figure(2)
for a = 1:length(algorithms)
algorithm = algorithms{a};
network_emse = mean(emse_array.(algorithm)) ;
plot(10*log10(network_emse),colors(a)); hold on;
end
title('NETWORK EMSE (dB)');
legend(algorithms_plot);
%% Combiners
figure(3);
node_to_show = 1;
for a = 1:length(algorithms)
algorithm = algorithms{a};
c_to_plot = c.(algorithm);
subplot(1,length(algorithms),a);
plot(squeeze(c_to_plot(:, node_to_show,:)).'); hold on;
axis([1 Tmax 0 1]);
title(['Combiners of ' algorithms_plot{a} ' for node' num2str(node_to_show)]);
end