-
Notifications
You must be signed in to change notification settings - Fork 3
/
ncim.m
85 lines (71 loc) · 2.26 KB
/
ncim.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
function TM = ncim(row,col,total,sigmasq)
%NCIM Generate a series of traffic matrices via the Non-stationary
% Conditionally Independent Model (NCIM).
%
% TM = ncim(row,column,total,sigmasq) returns the series of traffic
% matrices TM based on
%
% 1. row: average total outgoing traffic from PoPs in each time interval
% 2. col: average total incoming traffic into PoPs in each time interval
% 3. total: total_traffic in each time interval
% 4. sigmasq: noise variance \sigma^2 for input into the truncated normal
% distribution
%
% The script generates M traffic matrices, where M is the length of
% total, with the spatial size determined by the number of rows
% row and number of columns of col. Note that row and col must have their
% lengths equal to that of total, i.e. they must be defined on M time
% intervals.
%
% Requires the HMC_exact script by Ari Pakman. Download from
% https://github.com/aripakman/hmc-tmg
%
% file: ncim.m, (c) Paul Tune, Thu May 28 2015
% created: Thu May 28 2015
% author: Paul Tune
% email: paul.tune@adelaide.edu.au
% sanity checks
if isempty(total)
error('No total traffic provided');
end
[s,t] = size(total);
if s > 1 && t > 1
error('Total traffic should not be a matrix');
end
if s > 1
total = total';
end
if min(min(row)) < 0
error('Row entries must be non-negative');
end
if min(min(col)) < 0
error('Column entries must be non-negative');
end
[Nrow,n_TMs] = size(row);
[Ncol,m_TMs] = size(col);
if Nrow ~= Ncol
error('Column length mismatch to row length');
end
if n_TMs ~= m_TMs
error('Column temporal length mismatch to row temporal length');
end
if length(total) ~= n_TMs
error('Total traffic length mismatch to row/column temporal length');
end
if sigmasq < 0
error('Noise variance must be non-negative');
end
if min(modulated_total) < 0
error('Total traffic must be non-negative');
end
%% construct NCIM
TM = zeros(Nrow,Ncol,n_TMs);
for i=1:n_TMs
% fanouts
pU = row(:,i)/total(i);
pV = col(:,i)/total(i);
% construct gravity-like model in each time slice
U = HMC_exact(eye(Nrow), zeros(Nrow,1), eye(Nrow)*sigmasq, pU, true, 2, pU);
V = HMC_exact(eye(Ncol), zeros(Ncol,1), eye(Ncol)*sigmasq, pV, true, 2, pV);
TM(:,:,i) = total(i)*U(:,2)*V(:,2)';
end