-
Notifications
You must be signed in to change notification settings - Fork 0
/
Demo_synthe_02.m
173 lines (136 loc) · 5.59 KB
/
Demo_synthe_02.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
% Demostration of GreedyNAR, NAR, stochastic collocation on synthetic
% three-fidelity data
%% prepare data
clear
rng(202)
func_lf = @ (x) exp(-x) .* sin(x)
func_mf = @ (x) exp(-x) .* sin(x) .* cos(x)
func_hf = @ (x) exp(-x) .* sin(x) .* cos(x) + tanh(x) * 0.05
% xte = 100:100:50000;
xte = [0:0.01:pi*2]';
Ntr = 32;
% xtr = rand(Ntr,1) * pi * 2
xtr = linspace(0, pi * 2, Ntr)';
for i = 1:length(xte)
yhf_te(i,1) = func_hf(xte(i));
ymf_te(i,1) = func_mf(xte(i));
ylf_te(i,1) = func_lf(xte(i));
end
for i = 1:length(xtr)
yhf_tr(i,1) = func_hf(xtr(i));
ymf_tr(i,1) = func_mf(xtr(i));
ylf_tr(i,1) = func_lf(xtr(i));
end
figure(1)
plot(xte,yhf_te,'k-')
hold on
plot(xte,ymf_te,'m-')
plot(xte,ylf_te,'g-')
plot(xtr,yhf_tr,'ko')
plot(xtr,ymf_tr,'mo')
plot(xtr,ylf_tr,'go')
hold off
%% normal GP with high-fidelity data only
option.step = 1; %the step of increasing the training data
option.initial_size = 2; %the initial size of training data
% model_hf = cigp(xtr, yhf_tr, xte, 'ard');
% model_hf = cigp(xtr, yhf_tr, xte, 'linear');
model_hf = cigp_sequen(xtr, yhf_tr, xte, 'ard', Ntr/4,option);
% model_hf = cigp(xtr(1:Ntr/4), yhf_tr(1:Ntr/4), xte, 'ard');
figure(2)
clf
hold on
plot(xte,ylf_te,'g-','LineWidth',2, 'MarkerSize',10)
plot(xte,ymf_te,'m-','LineWidth',2, 'MarkerSize',10)
plot(xte,yhf_te,'b-','LineWidth',2, 'MarkerSize',10)
plot(xte,model_hf.yTe_pred,'r--','LineWidth',2, 'MarkerSize',10)
id_use = model_hf.id_use;
plot(xtr(id_use),yhf_tr(id_use),'b+','LineWidth',2, 'MarkerSize',10)
hold off
legend('Low-fidelity groundtruth','Mid-fidelity groundtruth','High-fidelity groundtruth','High-fidelity prediction',...
'High-fidelity used observations')
box on
grid on
set(gca,'FontSize',18);
print('IMG/gp_f3','-dpng')
%% stochastic collocation
[yPred, model,absId_use] = sc_v01(xtr,{ylf_tr,ymf_tr,yhf_tr},xte,[Ntr,Ntr/2,Ntr/4]);
figure(3)
clf
hold on
plot(xte,ylf_te,'g-','LineWidth',2, 'MarkerSize',10)
plot(xte,ymf_te,'m-','LineWidth',2, 'MarkerSize',10)
plot(xte,yhf_te,'b-','LineWidth',2, 'MarkerSize',10)
plot(xte,yPred,'r--','LineWidth',2, 'MarkerSize',10)
% id_use = absId_use{3};
plot(xtr(absId_use{1}),ylf_tr(absId_use{1}),'g+','LineWidth',2, 'MarkerSize',10)
plot(xtr(absId_use{2}),ymf_tr(absId_use{2}),'m+','LineWidth',2, 'MarkerSize',10)
plot(xtr(absId_use{3}),yhf_tr(absId_use{3}),'b+','LineWidth',2, 'MarkerSize',10)
hold off
legend('Low-fidelity groundtruth','Mid-fidelity groundtruth','High-fidelity groundtruth','High-fidelity prediction',...
'Low-fidelity used observations','Mid-fidelity used observations','High-fidelity used observations')
box on
grid on
set(gca,'FontSize',18);
print('IMG/sc1_fx3','-dpng')
%% stochastic collocation with low-fidelity observations
[yPred, model,absId_use] = sc_v02(xtr,{ylf_tr,ymf_tr,yhf_tr},xte,{ylf_te,[],[]},[Ntr,Ntr/2,Ntr/4]);
figure(4)
clf
hold on
plot(xte,ylf_te,'g-','LineWidth',2, 'MarkerSize',10)
plot(xte,ymf_te,'m-','LineWidth',2, 'MarkerSize',10)
plot(xte,yhf_te,'b-','LineWidth',2, 'MarkerSize',10)
plot(xte,yPred,'r--','LineWidth',2, 'MarkerSize',10)
% id_use = absId_use{3};
plot(xtr(absId_use{1}),ylf_tr(absId_use{1}),'g+','LineWidth',2, 'MarkerSize',10)
plot(xtr(absId_use{2}),ymf_tr(absId_use{2}),'m+','LineWidth',2, 'MarkerSize',10)
plot(xtr(absId_use{3}),yhf_tr(absId_use{3}),'b+','LineWidth',2, 'MarkerSize',10)
hold off
legend('Low-fidelity groundtruth','Mid-fidelity groundtruth','High-fidelity groundtruth','High-fidelity prediction',...
'Low-fidelity used observations','Mid-fidelity used observations','High-fidelity used observations')
box on
grid on
set(gca,'FontSize',18);
print('IMG/sc2_fx3','-dpng')
%% GreedyNAR without low-fidelity observations
[yPred, model, absId_use] = GreedyNAR(xtr,{ylf_tr,ymf_tr,yhf_tr},xte,'ard',[Ntr,Ntr/2,Ntr/4]);
figure(5)
clf
hold on
plot(xte,ylf_te,'g-','LineWidth',2, 'MarkerSize',10)
plot(xte,ymf_te,'m-','LineWidth',2, 'MarkerSize',10)
plot(xte,yhf_te,'b-','LineWidth',2, 'MarkerSize',10)
plot(xte,yPred,'r--','LineWidth',2, 'MarkerSize',10)
% id_use = absId_use{3};
plot(xtr(absId_use{1}),ylf_tr(absId_use{1}),'g+','LineWidth',2, 'MarkerSize',10)
plot(xtr(absId_use{2}),ymf_tr(absId_use{2}),'m+','LineWidth',2, 'MarkerSize',10)
plot(xtr(absId_use{3}),yhf_tr(absId_use{3}),'b+','LineWidth',2, 'MarkerSize',10)
hold off
legend('Low-fidelity groundtruth','Mid-fidelity groundtruth','High-fidelity groundtruth','High-fidelity prediction',...
'Low-fidelity used observations','Mid-fidelity used observations','High-fidelity used observations')
box on
grid on
set(gca,'FontSize',18);
print('IMG/greedyNAR1_fx3','-dpng')
%% GreedyNAR with low-fidelity observations
[yPred, model, absId_use] = GreedyNAR_v02(xtr,{ylf_tr,ymf_tr,yhf_tr},xte,{ylf_te,[],[]},'ard',[Ntr,Ntr/2,Ntr/4]);
% [yPred, model, absId_use] = GreedyNAR_v02(xtr,{ylf_tr,ymf_tr,yhf_tr},xte,{ylf_te,ymf_te,[]},'ard',[Ntr,Ntr/2,Ntr/4]);
figure(6)
clf
hold on
plot(xte,ylf_te,'g-','LineWidth',2, 'MarkerSize',10)
plot(xte,ymf_te,'m-','LineWidth',2, 'MarkerSize',10)
plot(xte,yhf_te,'b-','LineWidth',2, 'MarkerSize',10)
plot(xte,yPred,'r--','LineWidth',2, 'MarkerSize',10)
% id_use = absId_use{3};
plot(xtr(absId_use{1}),ylf_tr(absId_use{1}),'g+','LineWidth',2, 'MarkerSize',10)
plot(xtr(absId_use{2}),ymf_tr(absId_use{2}),'m+','LineWidth',2, 'MarkerSize',10)
plot(xtr(absId_use{3}),yhf_tr(absId_use{3}),'b+','LineWidth',2, 'MarkerSize',10)
hold off
legend('Low-fidelity groundtruth','Mid-fidelity groundtruth','High-fidelity groundtruth','High-fidelity prediction',...
'Low-fidelity used observations','Mid-fidelity used observations','High-fidelity used observations')
box on
grid on
set(gca,'FontSize',18);
print('IMG/greedyNAR2_fx3','-dpng')