-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_IEAD_model_vs_data.m
202 lines (152 loc) · 6.46 KB
/
plot_IEAD_model_vs_data.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function plot_IEAD_model_vs_data plots a comparison between the IEAD
% from the model and the data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input
% -----
% sglevel: data sparse grid level
% dim: dimension of parameter space
% 2D: dim = 2
% 4D: dim = 4
% data_type: 'train' for training data and 'test' for testing data
% Author: Pablo Seleson
% ------
% Last Modified: February 1, 2022
% -------------
function plot_IEAD_model_vs_data(sglevel,dim,data_type)
% ===================================================================
% Load IEAD Data
% ===================================================================
IEAD_data_filename = ['IEAD_data_' num2str(dim) 'D/Level_' num2str(sglevel) '_' data_type '.mat'];
load(IEAD_data_filename)
% Number of bins
dimX = length(XNODES);
dimY = length(YNODES);
% Number of cases
ncases = length(points);
% ===================================================================
% Evaluate IEAD* surrogate model at the grid points
% ===================================================================
% Reload IEAD* fit grid
gridname = ['LS_' num2str(dim) 'D_Grid_IEADstar_level_' num2str(sglevel)];
[lGrid_IEADstar] = tsgReloadGrid(gridname);
% Reload moments fit grid
gridname = ['LS_' num2str(dim) 'D_Grid_Moments_level_' num2str(sglevel)];
[lGrid_Moments] = tsgReloadGrid(gridname);
if dim == 2
% Evaluate 2D IEAD* surrogate model at the 2D grid points
[IEADstar_all] = tsgEvaluate(lGrid_IEADstar, [points(:,1) points(:,2)]);
% Evaluate 2D moments surrogate model at the 2D grid points
[Moments_all] = tsgEvaluate(lGrid_Moments,[points(:,1) points(:,2)]);
else
% Evaluate 4D IEAD* surrogate model at the 4D grid points
[IEADstar_all] = tsgEvaluate(lGrid_IEADstar, [points(:,1) points(:,2) points(:,3) points(:,4)]);
% Evaluate 4D moments surrogate model at the 4D grid points
[Moments_all] = tsgEvaluate(lGrid_Moments,[points(:,1) points(:,2) points(:,3) points(:,4)]);
end
% ------------------------------------------------------
% Create grids
% ------------------------------------------------------
% Create grid in the original coordinates
[~, ~, dimX, dimY, x, y, xpolyarray, ypolyarray, ~] = gridpolygonsOC;
% Create grid in the transformed coordinates
[~, ~, ~, ~, xstar, ystar, ~, ~, ~] = gridpolygonsTC;
% ------------------------------------------------------
% Open figure
% ------------------------------------------------------
figure
set(gcf,'Position',[300 400 1800 700])
% Run over cases
for ncase = 1:ncases
% ----------------------------------
% Find values of physical parameters
% ----------------------------------
if dim == 2
Log10_Te_Ti_value = points(ncase,1);
Psi_value = points(ncase,2);
else
Log10_Te_Ti_value = points(ncase,1);
Psi_value = points(ncase,2);
B_value = points(ncase,3);
Log10_n_value = points(ncase,4);
end
% ----------------------------------
% Find moments for transformation
% ----------------------------------
thetabar = Moments_all(ncase,1);
Ebar = 10.^Moments_all(ncase,2);
Theta11 = 10.^Moments_all(ncase,3);
Theta22 = 10.^Moments_all(ncase,4);
Theta12 = Moments_all(ncase,5);
Theta = [Theta11 Theta12; Theta12 Theta22];
% ----------------------------------
% Title
% ----------------------------------
string_fig = ['IEAD -- Case = ' num2str(ncase) ' of ' num2str(ncases)];
if dim == 2
string_case = ['$\log_{10}(T_e/T_i)$: ' num2str(Log10_Te_Ti_value,'%.2f') ' $\Psi$: ' num2str(Psi_value,'%.1f')];
else
string_case = ['$\log_{10}(T_e/T_i)$: ' num2str(Log10_Te_Ti_value,'%.2f') ' $\Psi$: ' num2str(Psi_value,'%.1f') ' $B$: ' num2str(B_value,'%.1f') ' $\log_{10}(n)$: ' num2str(Log10_n_value,'%.1f')];
end
sgtitle({string_fig,string_case},'interpreter','latex','FontSize',24)
% ----------------------------------
% Plot fit
% ----------------------------------
sp1 = subplot(1,2,1);
% Fit
IEADstar_fit = IEADstar_all(ncase,:);
% Read IEAD from IEAD*
[IEAD_fit] = evaluate_IEAD_from_IEADstar(x(:),y(:),thetabar,Ebar,Theta,xstar(:),ystar(:),IEADstar_fit');
% Find IEAD limits
max_value = max(IEAD_fit);
min_value = min(IEAD_fit);
caxis([min_value max_value]);
if ncase > 1
delete(p1);
end
% Plot IEAD fit
p1 = patch(xpolyarray, ypolyarray,IEAD_fit,'LineStyle','none');
axis([min(xpolyarray(:)) max(xpolyarray(:)) min(ypolyarray(:)) max(ypolyarray(:))])
% Colorbar
colorbar
% Other settings
set(sp1,'FontSize',20)
title('Model','interpreter','latex','FontSize',24)
xlabel('$\theta$','Interpreter','latex','Fontsize',24)
ylabel('$E/T_e$','Interpreter','latex','Fontsize',24)
pbaspect([1 1 1])
box('on')
% Colorbar title
hcb=colorbar;
hcb.Title.String = "$f$";
set(hcb.Title,'FontSize',30,'Interpreter','latex')
% ----------------------------------
% Plot data
% ----------------------------------
sp2 = subplot(1,2,2);
% Data
IEAD = reshape(IEAD_array(ncase,:),dimX,dimY);
% IEAD limits
caxis([min_value max_value]);
if ncase > 1
delete(p2);
end
% Plot IEAD data
p2 = patch(xpolyarray, ypolyarray,IEAD(:)','LineStyle','none');
axis([min(xpolyarray(:)) max(xpolyarray(:)) min(ypolyarray(:)) max(ypolyarray(:))])
% Colorbar
colorbar
% Other settings
set(sp2,'FontSize',20)
title('Data','interpreter','latex','FontSize',24)
xlabel('$\theta$','Interpreter','latex','Fontsize',24)
ylabel('$E/T_e$','Interpreter','latex','Fontsize',24)
pbaspect([1 1 1])
box('on')
% Colorbar title
hcb=colorbar;
hcb.Title.String = "$f$";
set(hcb.Title,'FontSize',30,'Interpreter','latex')
drawnow
end
end