-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshow_TMoE_results.m
182 lines (161 loc) · 5.53 KB
/
show_TMoE_results.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
function show_TMoE_results(x, y, TMoE, klas, TrueStats)
set(0,'defaultaxesfontsize',12);
colors = {'k','r','b','g','m','c','y', 'k','r','b','g','m','c','y', 'k','r','b','g','m','c','y'};
style = {'k.','r.','b.','g.','m.','c.','y.','k.','r.','b.','g.','m.','c.','y.','k.','r.','b.','g.','m.','c.','y.'};
yaxislim = [min(y)-std(y), max(y)+std(y)];
param = TMoE.param;
stats = TMoE.stats;
K = length(param.Nuk);
if nargin>3
figure,
h1 = plot(x,y,'o','color',[0.6 0.6 .6]);
hold all
h2 = plot(x,TrueStats.Ey_k,'k--');
h3 = plot(x,stats.Ey_k,'r--');
h4 = plot(x,TrueStats.Ey,'k','linewidth',2);
h5 = plot(x,stats.Ey,'r','linewidth',2);
xlabel('x'), ylabel('y');
ylim(yaxislim)
hold off
legend([h1, h4, h3(1), h5, h2(1)], 'data',['True mean',' (TMoE)'],'True Experts', ...
['Estimated mean',' (TMoE)'],'Estimated Experts',...
'Location','SouthWest');
legend('boxoff')
figure,
for k=1:K
plot(x,stats.Piik(:,k),[colors{k},'-'],'linewidth',2);
hold on;
end
hold off
ylim([0, 1]);
xlabel('x'), ylabel('Gating network probabilities');
%% data, True and Estimated mean functions and pointwise 2*sigma confidence regions
figure,
h1 = plot(x,y,'o','color',[0.6 0.6 .6]);
hold all
% true
h2 = plot(x,TrueStats.Ey,'k','linewidth',1.5);
h3 = plot(x,[TrueStats.Ey-2*sqrt(TrueStats.Vy), TrueStats.Ey+2*sqrt(TrueStats.Vy)],'k--','linewidth',1);
% estimated
h4 = plot(x,stats.Ey,'r','linewidth',2);
h5 = plot(x,[stats.Ey-2*sqrt(stats.Vy), stats.Ey+2*sqrt(stats.Vy)],'r--','linewidth',1);
legend([h1, h2, h3(1), h4, h5(1)],'data', ['True mean',' (TMoE)'], ....
'True conf. regions',['Estimated mean',' (TMoE)'], 'Estimated conf. regions',...
'Location','SouthWest');
legend('boxoff');
xlabel('x'), ylabel('y');
ylim(yaxislim)
hold off
%% obtained partition
figure,
hold all
% true partiton
for k=1:max(klas)
plot(x,TrueStats.Ey_k(:,k),colors{k},'linewidth',1.2);
plot(x(klas==k),y(klas==k),[colors{k},'o']);
end
legend('True expert means','True clusters');
ylim(yaxislim)
box on
xlabel('x'), ylabel('y');
legend('boxoff')
hold off
figure
hold all
% estimated partition
for k=1:K
plot(x,stats.Ey_k(:,k),colors{k},'linewidth',1.2);
plot(x(stats.klas==k),y(stats.klas==k),[colors{k},'o']);
end
legend('Estimated expert means','Estimated clusters'); ylim(yaxislim)
box on
xlabel('x'), ylabel('y');
legend('boxoff')
hold off
%% observed data log-likelihood
figure, plot(stats.stored_loglik,'-');
xlabel('EM iteration number');
ylabel('Observed data log-likelihood');
legend('TMoE log-likelihood');
legend('boxoff')
box on;
else %eg. for real data with unknown classes etc
[x, indx] = sort(x);
y = y(indx);
stats.Ey_k = stats.Ey_k(indx,:);
stats.Piik = stats.Piik(indx,:);
stats.Ey = stats.Ey(indx);
stats.Vy = stats.Vy(indx);
stats.klas = stats.klas(indx);
figure,
h1 = plot(x,y,'o','color',[0.6 0.6 .6]);
hold all
h2 = plot(x,stats.Ey_k,'r--');
h3 = plot(x,stats.Ey,'r','linewidth',2);
xlabel('x'), ylabel('y');
ylim(yaxislim)
hold off
legend([h1, h2(1), h3], 'data','TMoE mean function','Estimated Experts',...
'Location','SouthWest');
legend('boxoff')
figure,
for k=1:K
plot(x,stats.Piik(:,k),[colors{k},'-'],'linewidth',2);
hold on;
end
hold off
ylim([0, 1]);
xlabel('x'), ylabel('Gating network probabilities');
%% data and Estimated mean functions and pointwise 2*sigma confidence regions
figure,
h1 = plot(x,y,'o','color',[0.6 0.6 .6]);
hold all
% estimated
h2 = plot(x,stats.Ey,'r','linewidth',2);
h3 = plot(x,[stats.Ey-2*sqrt(stats.Vy), stats.Ey+2*sqrt(stats.Vy)],'r--','linewidth',1);
legend([h1, h2(1), h3(1)],'data', 'Estimated mean (TMoE)', 'Estimated conf. regions',...
'Location','SouthWest');
legend('boxoff');
xlabel('x'), ylabel('y');
ylim(yaxislim)
hold off
%% obtained partition
figure
hold all
for k=1:K
% h1= plot(x,stats.Ey_k(:,k),color{k},'linewidth',1.2);
% h2= plot(x(stats.klas==k),y(stats.klas==k),[color{k},'o']);
% hold on
% end
%%
expertMean_k = stats.Ey_k(:,k);
%prob_model_k = solution.param.piik(:,k);
active_model_k = expertMean_k(stats.klas==k);
active_period_model_k = x(stats.klas==k);
inactive_model_k = expertMean_k(stats.klas ~= k);
inactive_period_model_k = x(stats.klas ~= k);
if (~isempty(active_model_k))
plot(active_period_model_k,y(stats.klas==k),[colors{k},'o']);%, 'markersize', 0.2);
hold on,
plot(inactive_period_model_k,inactive_model_k,style{k},'markersize',0.01);
hold on,
plot(active_period_model_k, active_model_k,'Color', colors{k},'linewidth',2.5);
hold on
end
end
%%
legend('Estimated clusters','TMoE expert means (non-active)','TMoE expert means (active)');
ylim(yaxislim)
box on
xlabel('x'), ylabel('y');
legend('boxoff')
hold off
%% observed data log-likelihood
figure, plot(stats.stored_loglik,'-');
xlabel('EM iteration number');
ylabel('Observed data log-likelihood');
legend('TMoE log-likelihood');
legend('boxoff')
box on;
end
end