-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsensors_asymm.m
More file actions
109 lines (101 loc) · 4.22 KB
/
sensors_asymm.m
File metadata and controls
109 lines (101 loc) · 4.22 KB
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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% script: sensors_asymm %
% author: Federico Chiariotti (chiariot@dei.unipd.it) %
% license: GPLv3 %
% %
% %
% %
% Runs a Monte Carlo simulation with random asymmetric sensor networks %
% using chi-squared value distributions as a function of the asymmetry %
% %
% Parameters: %
% -N: the number of nodes [scalar, int] %
% -T: the number of network realizations [scalar, int] %
% -M: the number of steps to simulate [scalar, int] %
% -epsilon: the NE approximation error [scalar, R+] %
% -delta: the VoI quantization step [scalar, R+] %
% -Vmax: the maximum possible VoI [scalar, R+] %
% -psi: the transmission attempt cost [scalar, R+] %
% -sigmas: possible values for the mean VoI variation [1 x L, R+] %
% -max_iter: the maximum number of IBR iterations [scalar, int] %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all
clearvars
% Simulation parameters
N = 10;
T = 100;
M = 1e6;
epsilon = 1e-3;
delta = 1e-4;
Vmax = 50;
psi = 0.25;
sigmas = 0 : 0.05 : 0.8;
max_iter = 1000;
% Success probability
success = zeros(1, N);
success(1) = 1;
L = length(sigmas);
% Auxiliary variables
pull_rewards = zeros(L, T);
pull_vois = zeros(L, T);
pull_energies = zeros(L, T);
pull_fairness = zeros(L, T);
th_rewards = zeros(L, T);
th_energies = zeros(L, T);
th_fairness = zeros(L, T);
mc_rewards = zeros(L, T);
mc_vois = zeros(L, T);
mc_energies = zeros(L, T);
values = 0 : delta : 50;
% Run LIBRA
for ell = 1 : L
sigma = sigmas(ell);
for t = 1 : T
sigma, t
% Generate random realization
mus = ones(1, N) + (rand(1, N) - 0.5) * 2 * sigma;
% Compute expected rewards and VoI CDFs for all nodes
cdf = zeros(N, length(values) + 1);
for n = 1 : N
cdf(n, :) = [0, 1 - exp(-(values + delta / 2) / mus(n))];
end
% Compute pull-based solution
[~, nb] = max(mus);
exp_values = diff(cdf(nb(1), :)) * values';
pull_rew = 0;
pull_val = 0;
pull_tx = 0;
for v = 1 : length(values)
if (v > 1)
exp_values = exp_values - values(v) * (cdf(nb(1), v) - cdf(nb(1), v - 1));
end
v_thr = values(v) - delta / 2;
v_rew = exp_values - psi * (1 - cdf(nb(1), v));
if (v_rew > pull_rew)
pull_tx = 1 - cdf(nb(1), v);
pull_rew = v_rew;
pull_val = exp_values;
end
end
% Compute pull-based performance
pull_rewards(ell, t) = pull_rew;
pull_vois(ell, t) = pull_val;
pull_energies(ell, t) = pull_tx;
pull_fairness(ell, t) = 1 / N;
% Determine LIBRA solution
[v_eq, voi_0, initial_thresholds] = equal_value_initialization(cdf, values, psi, success);
[thresholds, reward_iter] = iterated_best_response(cdf, psi, epsilon,success, values, initial_thresholds, max_iter);
reward = max(reward_iter);
th_rewards(ell, t) = reward;
th_energies(ell, t) = sum(1 - thresholds);
% Compute fairness
th_fairness(ell, t) = (sum(1 - thresholds)) ^ 2 / N / sum((1 - thresholds) .^ 2);
% Monte Carlo check
[mc_voi, mc_reward, energy, goodput, channel_use, ~] = montecarlo(cdf, values, psi, success, thresholds, M);
mc_rewards(ell, t) = mc_reward;
mc_vois(ell, t) = mc_voi;
mc_energies(ell, t) = sum(energy);
end
end