-
Notifications
You must be signed in to change notification settings - Fork 39
/
Test_MLE_SHP.m
144 lines (115 loc) · 4.17 KB
/
Test_MLE_SHP.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Superposed Hawkes Processes: various source_num, D = 10
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear
%run setup
D = 10;
K = D;
N = 5;
nTest = 10;
rate = 0;
Err = zeros(2, 2, N, nTest);
ErrS = Err;
para = cell(K, 2, nTest);
Seqs = cell(K, 2, nTest);
models = cell(2, 2, N, nTest);
alg.LowRank = 0;
alg.Sparse = 0;
alg.GroupSparse = 0;
alg.outer = 10;
alg.rho = 0.1;
alg.inner = 10;
alg.thres = 2e-2;
alg.Tmax = [];
algmu = alg;
algmu.Sparse = 1;
algmu.alphaS = 0.1;
options.N = 300; % the number of sequences
options.Nmax = 100; % the maximum number of events per sequence
options.Tmax = 20; % the maximum size of time window
options.tstep = 0.1;
options.dt = 0.1;
options.M = 250;
options.GenerationNum = 200;
for n = 1:nTest
A = rand(D, D);
A(A<0.4) = 0;
A = A + eye(D);
A = 0.5*A./max(abs(eig(A)));
AA = reshape(A, [D, 1, D]);
L = zeros(K,2);
for k = 1:K
para{k, 1, n}.kernel = 'exp';
para{k, 1, n}.landmark = 0;
para{k, 1, n}.w = 1;
para{k, 1, n}.mu = zeros(D,1);
para{k, 1, n}.mu(k) = 0.5;
para{k, 1, n}.A = reshape(A, [D, 1, D]);
Seqs{k, 1, n} = SimulationFast_Thinning_ExpHP(para{k, 1, n}, options);
L(k,1) = length(Seqs{k, 1, n});
para{k, 2, n}.kernel = 'exp';
para{k, 2, n}.landmark = 0;
para{k, 2, n}.w = 1;
para{k, 2, n}.mu = ones(D,1)./(2*D);
para{k, 2, n}.A = reshape(A, [D, 1, D]);
Seqs{k, 2, n} = SimulationFast_Thinning_ExpHP(para{k, 2, n}, options);
L(k,2) = length(Seqs{k, 2, n});
end
model.A = rand(D,1,D)./(D^2);
model.mu = rand(D,1)./D;
model.kernel = 'exp';
model.w = 1;
model.landmark = 0;
for nn = 1:N
num = min([nn*(options.N/N); L(:)]);
seq_sum1 = Seqs{1, 1, n}(1:num);
seq_super1 = Seqs{1, 1, n}(1:num);
seq_sum2 = Seqs{1, 2, n}(1:num);
seq_super2 = Seqs{1, 2, n}(1:num);
for kk = 2:K
seq_sum1 = [seq_sum1, Seqs{kk, 1, n}(1:num)];
seq_super1 = SuperPosition(seq_super1, ...
Seqs{kk, 1, n}(1:num), rate);
seq_sum2 = [seq_sum2, Seqs{kk, 2, n}(1:num)];
seq_super2 = SuperPosition(seq_super2, ...
Seqs{kk, 2, n}(1:num), rate);
end
% multi-task Hawkes
model1 = model;
% model1.mu = 0.5*ones(1, num);
% for k = 2:K
% model1.mu = blkdiag(model1.mu, 0.5*ones(1, num));
% end
model1.mu = rand(D, num*K)./D;
models{1, 1, nn, n} = model1;
models{1, 1, nn, n} = Learning_MLE_Basis_MTmu( ...
seq_sum1, models{1, 1, nn, n}, algmu, 1 );
model2 = model;
%model2.mu = ones(D,num*K)./(2*D);%
model2.mu = rand(D, num*K)./D;
models{1, 2, nn, n} = model2;
models{1, 2, nn, n} = Learning_MLE_Basis_MTmu( ...
seq_sum2, models{1, 2, nn, n}, algmu, 1 );
% superposed Hawkes
models{2, 1, nn, n} = model;
%models{2, 1, nn, n}.mu = sum(model1.mu, 2)./num;
models{2, 1, nn, n} = Learning_MLE_Basis2( ...
seq_super1, models{2, 1, nn, n}, alg, 1 );
models{2, 2, nn, n} = model;
%models{2, 2, nn, n}.mu = sum(model2.mu, 2)./num;
models{2, 2, nn, n} = Learning_MLE_Basis2( ...
seq_super2, models{2, 2, nn, n}, alg, 1 );
Err(1, 1, nn, n) = norm(models{1, 1, nn, n}.A(:) - ...
AA(:))/norm(AA(:));
Err(1, 2, nn, n) = norm(models{1, 2, nn, n}.A(:) - ...
AA(:))/norm(AA(:));
Err(2, 1, nn, n) = norm(models{2, 1, nn, n}.A(:) - ...
AA(:))/norm(AA(:));
Err(2, 2, nn, n) = norm(models{2, 2, nn, n}.A(:) - ...
AA(:))/norm(AA(:));
end
end
save('Result_superpose_error_syn_D10.mat', 'Err', 'models', ...
'para', 'options', 'K');