-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGSA_Si.m
707 lines (539 loc) · 24.4 KB
/
GSA_Si.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The function GSA_Si performs Global Sensitivity Analysis (GSA) based on
% Variance-Based Methods, computing sensitivity indices following
%
% Saltelli, A., Ratto, M., Andres, T., Campolongo, F., Cariboni, J.,
% Gatelli, D., Saisana, M., Tarantola, S., 2008. Global Sensitivity Analysis.
% The Primer. Wiley
%
% Chapter 4.6: How to Compute Sensitivity Indices (p. 164)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Input
% -----
% sglevel: data sparse grid level
% dim: dimension of parameter space
% 2D: dim = 2
% 4D: dim = 4
% N: number of samples
% Author: Pablo Seleson
% ------
% Last Modified: February 9, 2022
% -------------
function GSA_Si(sglevel,dim,N)
% Check sglevel input
if sglevel~= 7 && sglevel~= 10 && sglevel~= 13
error('sglevel should be 7, 10, or 13.')
end
% Check dim input
if dim~= 2 && dim~= 4
error('dim should be 2 or 4.')
end
% ====================================================================
% Generate random matrices
% ====================================================================
if dim == 2
% 2D case: grid limits
min_Log10_Te_Ti = -1.25;
max_Log10_Te_Ti = 1.25;
min_Psi = 0;
max_Psi = 87;
% Quasi-random numbers
Q = qrandstream('sobol',4);
P = qrand(Q,N);
% Arrays of physical parameters
P(:,[1 3]) = min_Log10_Te_Ti + (max_Log10_Te_Ti-min_Log10_Te_Ti)*P(:,[1 3]);
P(:,[2 4]) = min_Psi + (max_Psi-min_Psi)*P(:,[2 4]);
% Matrices to compute sensitivity indices
A = P(:,1:2);
B = P(:,3:4);
C1 = [A(:,1) B(:,2)];
C2 = [B(:,1) A(:,2)];
else
% 4D case: grid limits
min_Log10_Te_Ti = -1.25;
max_Log10_Te_Ti = 1.25;
min_Psi = 0;
max_Psi = 87;
min_B = 1;
max_B = 15;
min_Log10_n_values = 16;
max_Log10_n_values = 20;
% Quasi-random numbers
Q = qrandstream('sobol',8);
P = qrand(Q,N);
% Arrays of physical parameters
P(:,[1 5]) = min_Log10_Te_Ti + (max_Log10_Te_Ti-min_Log10_Te_Ti)*P(:,[1 5]);
P(:,[2 6]) = min_Psi + (max_Psi-min_Psi)*P(:,[2 6]);
P(:,[3 7]) = min_B + (max_B-min_B)*P(:,[3 7]);
P(:,[4 8]) = min_Log10_n_values + (max_Log10_n_values-min_Log10_n_values)*P(:,[4 8]);
% Matrices to compute sensitivity indices
A = P(:,1:4);
B = P(:,5:8);
C1 = [A(:,1) B(:,2) B(:,3) B(:,4)];
C2 = [B(:,1) A(:,2) B(:,3) B(:,4)];
C3 = [B(:,1) B(:,2) A(:,3) B(:,4)];
C4 = [B(:,1) B(:,2) B(:,3) A(:,4)];
end
fprintf('Random matrices generated \n')
% ====================================================================
% Evaluate IEAD* model
% ====================================================================
% Reload IEAD* fit grid
gridname = ['LS_' num2str(dim) 'D_Grid_IEADstar_level_' num2str(sglevel)];
[lGrid_IEADstar] = tsgReloadGrid(gridname);
% Evaluate IEAD* surrogate model on points
if dim == 2
% Matrix A
[IEADstar_all_A] = tsgEvaluate(lGrid_IEADstar, [A(:,1) A(:,2)]);
% Matrix B
[IEADstar_all_B] = tsgEvaluate(lGrid_IEADstar, [B(:,1) B(:,2)]);
% Matrix C_1
[IEADstar_all_C1] = tsgEvaluate(lGrid_IEADstar, [C1(:,1) C1(:,2)]);
% Matrix C_2
[IEADstar_all_C2] = tsgEvaluate(lGrid_IEADstar, [C2(:,1) C2(:,2)]);
else
% Matrix A
[IEADstar_all_A] = tsgEvaluate(lGrid_IEADstar, [A(:,1) A(:,2) A(:,3) A(:,4)]);
% Matrix B
[IEADstar_all_B] = tsgEvaluate(lGrid_IEADstar, [B(:,1) B(:,2) B(:,3) B(:,4)]);
% Matrix C_1
[IEADstar_all_C1] = tsgEvaluate(lGrid_IEADstar, [C1(:,1) C1(:,2) C1(:,3) C1(:,4)]);
% Matrix C_2
[IEADstar_all_C2] = tsgEvaluate(lGrid_IEADstar, [C2(:,1) C2(:,2) C2(:,3) C2(:,4)]);
% Matrix C_3
[IEADstar_all_C3] = tsgEvaluate(lGrid_IEADstar, [C3(:,1) C3(:,2) C3(:,3) C3(:,4)]);
% Matrix C_4
[IEADstar_all_C4] = tsgEvaluate(lGrid_IEADstar, [C4(:,1) C4(:,2) C4(:,3) C4(:,4)]);
end
fprintf('IEAD* surrogate model evaluated \n')
% ====================================================================
% Compute Moments per Case for Transformation
% ====================================================================
% Reload moments grid
gridname = ['LS_' num2str(dim) 'D_Grid_Moments_level_' num2str(sglevel)];
[lGrid_Moments] = tsgReloadGrid(gridname);
% Evaluate moments surrogate model on points
if dim == 2
% Matrix A
[Moments_A] = tsgEvaluate(lGrid_Moments, [A(:,1) A(:,2)]);
% Matrix B
[Moments_B] = tsgEvaluate(lGrid_Moments, [B(:,1) B(:,2)]);
% Matrix C_1
[Moments_C1] = tsgEvaluate(lGrid_Moments, [C1(:,1) C1(:,2)]);
% Matrix C_2
[Moments_C2] = tsgEvaluate(lGrid_Moments, [C2(:,1) C2(:,2)]);
else
% Matrix A
[Moments_A] = tsgEvaluate(lGrid_Moments, [A(:,1) A(:,2) A(:,3) A(:,4)]);
% Matrix B
[Moments_B] = tsgEvaluate(lGrid_Moments, [B(:,1) B(:,2) B(:,3) B(:,4)]);
% Matrix C_1
[Moments_C1] = tsgEvaluate(lGrid_Moments, [C1(:,1) C1(:,2) C1(:,3) C1(:,4)]);
% Matrix C_2
[Moments_C2] = tsgEvaluate(lGrid_Moments, [C2(:,1) C2(:,2) C2(:,3) C2(:,4)]);
% Matrix C_3
[Moments_C3] = tsgEvaluate(lGrid_Moments, [C3(:,1) C3(:,2) C3(:,3) C3(:,4)]);
% Matrix C_4
[Moments_C4] = tsgEvaluate(lGrid_Moments, [C4(:,1) C4(:,2) C4(:,3) C4(:,4)]);
end
% Assign moments to arrays
% Moments for Matrix A
thetabar_mean_A = Moments_A(:,1);
Ebar_mean_A = 10.^Moments_A(:,2);
Theta_mean_11_A = 10.^Moments_A(:,3);
Theta_mean_22_A = 10.^Moments_A(:,4);
Theta_mean_12_A = Moments_A(:,5);
Theta_mean_A = [Theta_mean_11_A Theta_mean_22_A Theta_mean_12_A]; % [Theta(1,1) Theta(2,2) Theta(1,2)];
% Moments for Matrix B
thetabar_mean_B = Moments_B(:,1);
Ebar_mean_B = 10.^Moments_B(:,2);
Theta_mean_11_B = 10.^Moments_B(:,3);
Theta_mean_22_B = 10.^Moments_B(:,4);
Theta_mean_12_B = Moments_B(:,5);
Theta_mean_B = [Theta_mean_11_B Theta_mean_22_B Theta_mean_12_B]; % [Theta(1,1) Theta(2,2) Theta(1,2)];
% Moments for Matrix C_1
thetabar_mean_C1 = Moments_C1(:,1);
Ebar_mean_C1 = 10.^Moments_C1(:,2);
Theta_mean_11_C1 = 10.^Moments_C1(:,3);
Theta_mean_22_C1 = 10.^Moments_C1(:,4);
Theta_mean_12_C1 = Moments_C1(:,5);
Theta_mean_C1 = [Theta_mean_11_C1 Theta_mean_22_C1 Theta_mean_12_C1]; % [Theta(1,1) Theta(2,2) Theta(1,2)];
% Moments for Matrix C_2
thetabar_mean_C2 = Moments_C2(:,1);
Ebar_mean_C2 = 10.^Moments_C2(:,2);
Theta_mean_11_C2 = 10.^Moments_C2(:,3);
Theta_mean_22_C2 = 10.^Moments_C2(:,4);
Theta_mean_12_C2 = Moments_C2(:,5);
Theta_mean_C2 = [Theta_mean_11_C2 Theta_mean_22_C2 Theta_mean_12_C2]; % [Theta(1,1) Theta(2,2) Theta(1,2)];
if dim == 4
% Moments for Matrix C_3
thetabar_mean_C3 = Moments_C3(:,1);
Ebar_mean_C3 = 10.^Moments_C3(:,2);
Theta_mean_11_C3 = 10.^Moments_C3(:,3);
Theta_mean_22_C3 = 10.^Moments_C3(:,4);
Theta_mean_12_C3 = Moments_C3(:,5);
Theta_mean_C3 = [Theta_mean_11_C3 Theta_mean_22_C3 Theta_mean_12_C3]; % [Theta(1,1) Theta(2,2) Theta(1,2)];
% Moments for Matrix C_4
thetabar_mean_C4 = Moments_C4(:,1);
Ebar_mean_C4 = 10.^Moments_C4(:,2);
Theta_mean_11_C4 = 10.^Moments_C4(:,3);
Theta_mean_22_C4 = 10.^Moments_C4(:,4);
Theta_mean_12_C4 = Moments_C4(:,5);
Theta_mean_C4 = [Theta_mean_11_C4 Theta_mean_22_C4 Theta_mean_12_C4]; % [Theta(1,1) Theta(2,2) Theta(1,2)];
end
fprintf('Moments surrogate model evaluated \n')
% ====================================================================
% Read Binning in Transformed Coordinates
% ====================================================================
[~, ~, ~, ~, xstar, ystar, ~, ~, ~] = gridpolygonsTC;
% ====================================================================
% Compute Moments
% ====================================================================
% Moments for Matrix A
Moments_Theta_E_A = zeros(N,4);
% Moments for Matrix B
Moments_Theta_E_B = zeros(N,4);
% Moments for Matrix C_1
Moments_Theta_E_C1 = zeros(N,4);
% Moments for Matrix C_2
Moments_Theta_E_C2 = zeros(N,4);
if dim == 4
% Moments for Matrix C_3
Moments_Theta_E_C3 = zeros(N,4);
% Moments for Matrix C_4
Moments_Theta_E_C4 = zeros(N,4);
end
% Ion temperature
Ti = 10;
% Create reference non-uniform grid in the transformed coordinates
[~, ~, ~, ~, xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, ~] = gridpolygonsTC;
fprintf('Converting IEAD* to IEAD and computing moments ... \n\n')
% Run over samples
for i = 1:N
fprintf('Sample %5g of %5g\n',i,N)
% --------
% Matrix A
% --------
% Read IEAD* for the ith sample
IEADstar_A = IEADstar_all_A(i,:);
% Moments to convert data
thetabar = thetabar_mean_A(i);
Ebar = Ebar_mean_A(i);
Theta = [Theta_mean_A(i,1) Theta_mean_A(i,3); Theta_mean_A(i,3) Theta_mean_A(i,2)];
% Electron temperature
Log10_Te_Ti = A(i,1);
Te = Ti*10^Log10_Te_Ti;
% Transform grid in the transformed coordinates to the original coordinates
[xNU, yNU, xNUpolyarray, yNUpolyarray] = transform_gridpolygonsTC(xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, thetabar, Ebar, Theta);
% Evaluate IEAD from IEAD*
[IEAD_A_NU] = evaluate_IEAD_from_IEADstar(xNU(:),yNU(:),thetabar,Ebar,Theta,xstar(:),ystar(:),IEADstar_A(:));
% Mean and standard devation of angle & energy
[~, ~, expected_theta, expected_E, std_theta, std_E] = MP_Expected_Theta_E(xNU,yNU,xNUpolyarray,yNUpolyarray,IEAD_A_NU,Te);
Moments_Theta_E_A(i,:) = [expected_theta expected_E std_theta std_E];
% --------
% Matrix B
% --------
% Read IEAD* for the ith sample
IEADstar_B = IEADstar_all_B(i,:);
% Moments to convert data
thetabar = thetabar_mean_B(i);
Ebar = Ebar_mean_B(i);
Theta = [Theta_mean_B(i,1) Theta_mean_B(i,3); Theta_mean_B(i,3) Theta_mean_B(i,2)];
% Electron temperature
Log10_Te_Ti = B(i,1);
Te = Ti*10^Log10_Te_Ti;
% Transform grid in the transformed coordinates to the original coordinates
[xNU, yNU, xNUpolyarray, yNUpolyarray] = transform_gridpolygonsTC(xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, thetabar, Ebar, Theta);
% Evaluate IEAD from IEAD*
[IEAD_B_NU] = evaluate_IEAD_from_IEADstar(xNU(:),yNU(:),thetabar,Ebar,Theta,xstar(:),ystar(:),IEADstar_B(:));
% Mean and standard devation of angle & energy
[~, ~, expected_theta, expected_E, std_theta, std_E] = MP_Expected_Theta_E(xNU,yNU,xNUpolyarray,yNUpolyarray,IEAD_B_NU,Te);
Moments_Theta_E_B(i,:) = [expected_theta expected_E std_theta std_E];
% ----------
% Matrix C_1
% ----------
% Read IEAD* for the ith sample
IEADstar_C1 = IEADstar_all_C1(i,:);
% Moments to convert data
thetabar = thetabar_mean_C1(i);
Ebar = Ebar_mean_C1(i);
Theta = [Theta_mean_C1(i,1) Theta_mean_C1(i,3); Theta_mean_C1(i,3) Theta_mean_C1(i,2)];
% Electron temperature
Log10_Te_Ti = C1(i,1);
Te = Ti*10^Log10_Te_Ti;
% Transform grid in the transformed coordinates to the original coordinates
[xNU, yNU, xNUpolyarray, yNUpolyarray] = transform_gridpolygonsTC(xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, thetabar, Ebar, Theta);
% Evaluate IEAD from IEAD*
[IEAD_C1_NU] = evaluate_IEAD_from_IEADstar(xNU(:),yNU(:),thetabar,Ebar,Theta,xstar(:),ystar(:),IEADstar_C1(:));
% Mean and standard devation of angle & energy
[~, ~, expected_theta, expected_E, std_theta, std_E] = MP_Expected_Theta_E(xNU,yNU,xNUpolyarray,yNUpolyarray,IEAD_C1_NU,Te);
Moments_Theta_E_C1(i,:) = [expected_theta expected_E std_theta std_E];
% ----------
% Matrix C_2
% ----------
% Read IEAD* for the ith sample
IEADstar_C2 = IEADstar_all_C2(i,:);
% Moments to convert data
thetabar = thetabar_mean_C2(i);
Ebar = Ebar_mean_C2(i);
Theta = [Theta_mean_C2(i,1) Theta_mean_C2(i,3); Theta_mean_C2(i,3) Theta_mean_C2(i,2)];
% Electron temperature
Log10_Te_Ti = C2(i,1);
Te = Ti*10^Log10_Te_Ti;
% Transform grid in the transformed coordinates to the original coordinates
[xNU, yNU, xNUpolyarray, yNUpolyarray] = transform_gridpolygonsTC(xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, thetabar, Ebar, Theta);
% Evaluate IEAD from IEAD*
[IEAD_C2_NU] = evaluate_IEAD_from_IEADstar(xNU(:),yNU(:),thetabar,Ebar,Theta,xstar(:),ystar(:),IEADstar_C2(:));
% Mean and standard devation of angle & energy
[~, ~, expected_theta, expected_E, std_theta, std_E] = MP_Expected_Theta_E(xNU,yNU,xNUpolyarray,yNUpolyarray,IEAD_C2_NU,Te);
Moments_Theta_E_C2(i,:) = [expected_theta expected_E std_theta std_E];
if dim == 4
% ----------
% Matrix C_3
% ----------
% Read IEAD* for the ith sample
IEADstar_C3 = IEADstar_all_C3(i,:);
% Moments to convert data
thetabar = thetabar_mean_C3(i);
Ebar = Ebar_mean_C3(i);
Theta = [Theta_mean_C3(i,1) Theta_mean_C3(i,3); Theta_mean_C3(i,3) Theta_mean_C3(i,2)];
% Electron temperature
Log10_Te_Ti = C3(i,1);
Te = Ti*10^Log10_Te_Ti;
% Transform grid in the transformed coordinates to the original coordinates
[xNU, yNU, xNUpolyarray, yNUpolyarray] = transform_gridpolygonsTC(xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, thetabar, Ebar, Theta);
% Evaluate IEAD from IEAD*
[IEAD_C3_NU] = evaluate_IEAD_from_IEADstar(xNU(:),yNU(:),thetabar,Ebar,Theta,xstar(:),ystar(:),IEADstar_C3(:));
% Mean and standard devation of angle & energy
[~, ~, expected_theta, expected_E, std_theta, std_E] = MP_Expected_Theta_E(xNU,yNU,xNUpolyarray,yNUpolyarray,IEAD_C3_NU,Te);
Moments_Theta_E_C3(i,:) = [expected_theta expected_E std_theta std_E];
% ----------
% Matrix C_4
% ----------
% Read IEAD* for the ith sample
IEADstar_C4 = IEADstar_all_C4(i,:);
% Moments to convert data
thetabar = thetabar_mean_C4(i);
Ebar = Ebar_mean_C4(i);
Theta = [Theta_mean_C4(i,1) Theta_mean_C4(i,3); Theta_mean_C4(i,3) Theta_mean_C4(i,2)];
% Electron temperature
Log10_Te_Ti = C4(i,1);
Te = Ti*10^Log10_Te_Ti;
% Transform grid in the transformed coordinates to the original coordinates
[xNU, yNU, xNUpolyarray, yNUpolyarray] = transform_gridpolygonsTC(xNU_ref, yNU_ref, xNUpolyarray_ref, yNUpolyarray_ref, thetabar, Ebar, Theta);
% Evaluate IEAD from IEAD*
[IEAD_C4_NU] = evaluate_IEAD_from_IEADstar(xNU(:),yNU(:),thetabar,Ebar,Theta,xstar(:),ystar(:),IEADstar_C4(:));
% Mean and standard devation of angle & energy
[~, ~, expected_theta, expected_E, std_theta, std_E] = MP_Expected_Theta_E(xNU,yNU,xNUpolyarray,yNUpolyarray,IEAD_C4_NU,Te);
Moments_Theta_E_C4(i,:) = [expected_theta expected_E std_theta std_E];
end
end
% ====================================================================
% Compute Sensitivity Indices for Angle and Energy Moments
% ====================================================================
% First-order indices
f0sq_Moments = ((1/N)*sum(Moments_Theta_E_A,1)).^2;
Si_denom_Moments = (1/N)*sum(Moments_Theta_E_A.^2,1) - f0sq_Moments;
S1_Moments = ((1/N)*sum(Moments_Theta_E_A.*Moments_Theta_E_C1,1) - f0sq_Moments)./Si_denom_Moments;
S2_Moments = ((1/N)*sum(Moments_Theta_E_A.*Moments_Theta_E_C2,1) - f0sq_Moments)./Si_denom_Moments;
if dim == 4
S3_Moments = ((1/N)*sum(Moments_Theta_E_A.*Moments_Theta_E_C3,1) - f0sq_Moments)./Si_denom_Moments;
S4_Moments = ((1/N)*sum(Moments_Theta_E_A.*Moments_Theta_E_C4,1) - f0sq_Moments)./Si_denom_Moments;
end
% Total-effect indices
if dim == 4
ST1_Moments = 1 - ((1/N)*sum(Moments_Theta_E_B.*Moments_Theta_E_C1,1) - f0sq_Moments)./Si_denom_Moments;
ST2_Moments = 1 - ((1/N)*sum(Moments_Theta_E_B.*Moments_Theta_E_C2,1) - f0sq_Moments)./Si_denom_Moments;
ST3_Moments = 1 - ((1/N)*sum(Moments_Theta_E_B.*Moments_Theta_E_C3,1) - f0sq_Moments)./Si_denom_Moments;
ST4_Moments = 1 - ((1/N)*sum(Moments_Theta_E_B.*Moments_Theta_E_C4,1) - f0sq_Moments)./Si_denom_Moments;
end
% ====================================================================
% Plot Sensitivity Indices for Moments of Angle and Energy
% ====================================================================
figure
set(gcf,'Position',[500 500 1400 500])
% -----------
% S_1
% -----------
if dim == 2
subplot(1,3,1)
else
subplot(2,4,1)
end
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[S1_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan S1_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan S1_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan S1_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_1$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
% -----------
% S_2
% -----------
if dim == 2
subplot(1,3,2)
else
subplot(2,4,2)
end
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[S2_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan S2_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan S2_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan S2_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_2$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
% -----------
% S_12 (only for dim = 2)
% -----------
if dim == 2
S12_Moments = 1 - S1_Moments - S2_Moments;
subplot(1,3,3)
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[S12_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan S12_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan S12_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan S12_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_{12}$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
else
% -----------
% S_3
% -----------
subplot(2,4,3)
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[S3_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan S3_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan S3_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan S3_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_3$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
% -----------
% S_4
% -----------
subplot(2,4,4)
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[S4_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan S4_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan S4_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan S4_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_4$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
% -----------
% S_{T_1}
% -----------
subplot(2,4,5)
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[ST1_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan ST1_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan ST1_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan ST1_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_{T_1}$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
% -----------
% S_{T_2}
% -----------
subplot(2,4,6)
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[ST2_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan ST2_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan ST2_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan ST2_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_{T_2}$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
% -----------
% S_{T_3}
% -----------
subplot(2,4,7)
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[ST3_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan ST3_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan ST3_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan ST3_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_{T_3}$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
% -----------
% S_{T_4}
% -----------
subplot(2,4,8)
hold on
% Bar width
wd = 0.5;
x = [1 2 3 4];
bar(x,[ST4_Moments(1) nan nan nan],wd,'facecolor','r');
bar(x,[nan ST4_Moments(2) nan nan],wd,'facecolor','b');
bar(x,[nan nan ST4_Moments(3) nan],wd,'facecolor','g');
bar(x,[nan nan nan ST4_Moments(4)],wd,'facecolor','m');
set(gca,'xtick',x,'xticklabel',{'$\mu_{\theta}$';'$\mu_{E}$';'$\sigma_{\theta}$';'$\sigma_{E}$'})
title('$S_{T_4}$','interpreter','latex','FontSize',30)
set(gca,'FontSize',20)
set(gca,'TickLabelInterpreter','latex')
box('on')
ylim([0 1])
pbaspect([1 1 1])
end
end