-
Notifications
You must be signed in to change notification settings - Fork 0
/
ay_plot_sample_ver01_4_Yb_test.m
251 lines (189 loc) · 5.96 KB
/
ay_plot_sample_ver01_4_Yb_test.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
close all
% generate data
T= 0.9;
[Xk,Yn,Yb,In,Param] =ay_data_generator_4_Yb_test(100,1,0.25,0.95,0.02,log(T));
% sample range
Xs = -1:0.01:3;
figure(1)
plot(Xk,'b','LineWidth',3)
xlabel('Time')
ylabel('\it{X_k}');
%set(gca,'Color',[0.2 0.2 0.5]);
figure(2)
ind = find(In==0);
Yt = exp(Yn);
Yt(ind)=inf;
plot(Yt,'Color',[0 0 1],'LineWidth',3);
hold on;
plot(T*ones(100,1),'k--','LineWidth',0.3);
%Nums ={'','False', num2str(0.2),num2str(0.4),num2str(0.6),num2str(0.8),'True',''};
%set(gca,'YTick',linspace(-0.1,1.1,8),'YTickLabel',Nums);
%plot(ind,1,'kx','LineWidth',2)
ind = find(In==0);
Yb(ind)=inf;
plot(Yb,'o','Color',[0 0 1],'MarkerSize',6,'LineWidth',2);
ind = find(In==0);
plot(ind,T,'x','Color',[0 0.0 0],'LineWidth',2,'MarkerSize',8)
hold off;
xlabel('Time');
ylabel('Observation=\{{\it{Y_k} , \it{Z_k}}\}')
legend('Yk','T(sec)','Zk','Missed','Orientation','horizontal')
%set(gca,'Color',[0.2 0.2 0.5]);
ylim([-0.1 1.1])
% match to Xs
% ImagXk = zeros(100,1);
% for s=1:100
% [temp,ind]= min(abs(Xk(s)-Xs));
% ImagXk(s) = length(Xs)-ind;
% end
% Run the exact
figure(10)
tic
Pxz = ay_smoothing(1,1,Yn,Yb,In(:,1),Xs,Param,log(T));
toc
mse1 = ay_mse(Xk,Xs,Pxz);
[cnt1,lbnd,ubnd] = ay_count(Xk,Xs,Pxz);
MeanP = zeros(100,1);
for s=1:100
mx = Xs * Pxz(s,:)';
%[temp,ind]= min(abs(mx-Xs));
MeanP(s) = mx; %length(Xs)-ind;
end
%MeanP = MeanP(end:-1:1);
%Pxz = Pxz(:,end:-1:1);
%h=imagesc(sqrt(Pxz'));
%colormap(flipud(bone))
%hold on
ay_plot_bound(1,1:100,MeanP,lbnd' ,ubnd' );hold on;
plot(Xk,'b','LineWidth',2);hold on;
num1 = min(lbnd-0.2);
num2 = max(ubnd+0.2);
ylim([num1 num2])
ind=find(In(:,1)==0);
plot(ind,num1+0.1,'x','MarkerSize',8,'LineWidth',2,'Color',[0 0.0 0]);
hold off;
% index = (linspace(Xs(num1),Xs(num2),6));
% Nums ={ num2str(index(1)), num2str(index(2)),num2str(index(3)),num2str(index(4)),num2str(index(5)),num2str(index(6))};
% set(gca,'YTick',linspace(num1,num2,6),'YTickLabel',Nums(end:-1:1));
xlabel('Time')
ylabel('\it{X_k}');
title('Exact Method','FontWeight','normal');
legend('95% HPD Rgn','\it{X_k_|_k}','\it{X_k}','Orientation','horizontal')
figure(11)
Pxz = ay_smoothing(1,2,Yn,Yb,In(:,1),Xs,Param,log(T));
mse2 = ay_mse(Xk,Xs,Pxz);
[cnt2,lbnd,ubnd] = ay_count(Xk,Xs,Pxz);
MeanP = zeros(100,1);
for s=1:100
mx = Xs * Pxz(s,:)';
%[temp,ind]= min(abs(mx-Xs));
MeanP(s) = mx; %length(Xs)-ind;
end
%MeanP = MeanP(end:-1:1);
%Pxz = Pxz(:,end:-1:1);
%h=imagesc(sqrt(Pxz'));
%colormap(flipud(bone))
%hold on
ay_plot_bound(1,1:100,MeanP,lbnd' ,ubnd' );hold on;
plot(Xk,'b','LineWidth',2);hold on;
num1 = min(num1,min(lbnd-0.2));
num2 = max(num2,max(ubnd+0.2));
ind=find(In(:,1)==0);
plot(ind,num1+0.1,'x','MarkerSize',8,'LineWidth',2,'Color',[0 0.0 0]);
hold off;
% index = (linspace(Xs(num1),Xs(num2),6));
% Nums ={ num2str(index(1)), num2str(index(2)),num2str(index(3)),num2str(index(4)),num2str(index(5)),num2str(index(6))};
% set(gca,'YTick',linspace(num1,num2,6),'YTickLabel',Nums(end:-1:1));
xlabel('Time')
ylabel('\it{X_k}');
title('Impute Method','FontWeight','normal');
legend('95% HPD Rgn','\it{X_k_|_k}','\it{X_k}','Orientation','horizontal')
figure(12)
Pxz = ay_smoothing(1,3,Yn,Yb,In(:,1),Xs,Param,log(T));
mse3 = ay_mse(Xk,Xs,Pxz);
[cnt3,lbnd,ubnd] = ay_count(Xk,Xs,Pxz);
MeanP = zeros(100,1);
for s=1:100
mx = Xs * Pxz(s,:)';
%[temp,ind]= min(abs(mx-Xs));
MeanP(s) = mx; %length(Xs)-ind;
end
%MeanP = MeanP(end:-1:1);
%Pxz = Pxz(:,end:-1:1);
%h=imagesc(sqrt(Pxz'));
%colormap(flipud(bone))
%hold on
ay_plot_bound(1,1:100,MeanP,lbnd' ,ubnd' );hold on;
plot(Xk,'b','LineWidth',2);hold on;
num1 = min(num1,min(lbnd-0.2));
num2 = max(num2,max(ubnd+0.2));
ind=find(In(:,1)==0);
plot(ind,num1+0.1,'x','MarkerSize',8,'LineWidth',2,'Color',[0 0.0 0]);
hold off;
% index = (linspace(Xs(num1),Xs(num2),6));
% Nums ={ num2str(index(1)), num2str(index(2)),num2str(index(3)),num2str(index(4)),num2str(index(5)),num2str(index(6))};
% set(gca,'YTick',linspace(num1,num2,6),'YTickLabel',Nums(end:-1:1));
xlabel('Time')
ylabel('\it{X_k}');
title('Ignore Method','FontWeight','normal');
legend('95% HPD Rgn','\it{X_k_|_k}','\it{X_k}','Orientation','horizontal')
figure(13)
tic
[temp,Mx,Sx] =ay_smoothing(1,4,Yn,Yb,In(:,1),Xs,Param,log(T));
toc
for s=1:100
Pxz(s,:)=exp(-(Xs-Mx(s)).^2/(2*Sx(s)));
Pxz(s,:)=Pxz(s,:)/sum(Pxz(s,:));
end
mse4 = ay_mse(Xk,Xs,Pxz);
[cnt4,lbnd,ubnd] = ay_count(Xk,Xs,Pxz);
MeanP = zeros(100,1);
for s=1:100
mx = Xs * Pxz(s,:)';
%[temp,ind]= min(abs(mx-Xs));
MeanP(s) = mx; %length(Xs)-ind;
end
%MeanP = MeanP(end:-1:1);
%Pxz = Pxz(:,end:-1:1);
%h=imagesc(sqrt(Pxz'));
%colormap(flipud(bone))
%hold on
ay_plot_bound(1,1:100,MeanP,lbnd' ,ubnd' );hold on;
plot(Xk,'b','LineWidth',2);hold on;
num1 = min(num1,min(lbnd-0.2));
num2 = max(num2,max(ubnd+0.2));
ind=find(In(:,1)==0);
plot(ind,num1+0.1,'x','MarkerSize',8,'LineWidth',2,'Color',[0 0.0 0]);
hold off;
% index = (linspace(Xs(num1),Xs(num2),6));
% Nums ={ num2str(index(1)), num2str(index(2)),num2str(index(3)),num2str(index(4)),num2str(index(5)),num2str(index(6))};
% set(gca,'YTick',linspace(num1,num2,6),'YTickLabel',Nums(end:-1:1));
xlabel('Time')
ylabel('\it{X_k}');
title('Gaussian Approximation Method','FontWeight','normal');
legend('95% HPD Rgn','\it{X_k_|_k}','\it{X_k}','Orientation','horizontal')
figure(1)
ylim([num1 num2])
figure(10)
ylim([num1 num2])
figure(11)
ylim([num1 num2])
figure(12)
ylim([num1 num2])
figure(13)
ylim([num1 num2])
stop=1;
% figure(2)
% ind = find(In==0);
% Yt = exp(Yn);
% Yt(ind)=inf;
% Yb(ind)=inf;
% h=plotyy(1:100,Yt,1:100,Yb);
% set(h(1),'LineWidth',2);
% set(h(2),'LineStyleOrder','.');
% hold on;
% plot(ones(100,1),'r-','LineWidth',1)
% plot(ind,1,'kx','LineWidth',2)
% hold off;
% ind = find(In==1);
% plot(ind,1,'kx','LineWidth',2)