@@ -16,6 +16,32 @@ include(joinpath(pkgdir(CM), "papers", "ice_nucleation_2024", "calibration.jl"))
16
16
include (joinpath (pkgdir (CM), " papers" , " ice_nucleation_2024" , " unpack_AIDA.jl" ))
17
17
include (joinpath (pkgdir (CM), " papers" , " ice_nucleation_2024" , " plots.jl" ))
18
18
19
+ function MSE (
20
+ n_iterations, n_ensembles,
21
+ all_params, data_file_name_list,
22
+ params_list, nuc_mode, FT, IC_list, end_sim,
23
+ y_truth, Nₜ,
24
+ )
25
+
26
+ loss_vector = [] # should have length of n_iterations with each element being the MSE from the whole batch of ensembles
27
+ for iter in 1 : n_iterations
28
+ loss_iteration = []
29
+ for ens in 1 : n_ensembles
30
+ loss_ensemble = []
31
+ for exp in 1 : length (data_file_name_list)
32
+ parcel_ensemble =
33
+ run_model ([params_list[exp]], nuc_mode, all_params[iter][:, ens], FT, [IC_list[exp]], end_sim)
34
+ loss_ensemble_exp = y_truth[exp][end ] - (parcel_ensemble[9 , end ] / Nₜ[exp])
35
+ append! (loss_ensemble, loss_ensemble_exp)
36
+ end
37
+ append! (loss_iteration, loss_ensemble)
38
+ end
39
+ append! (loss_vector, (sum (loss_iteration)^ 2 )/ (length (loss_iteration))) # MSE
40
+ end
41
+
42
+ return loss_vector
43
+ end
44
+
19
45
# Defining data names, start/end times, etc.
20
46
global edf_data_names = [
21
47
" in05_17_aida.edf" , " in05_18_aida.edf" ,
@@ -129,12 +155,24 @@ for (batch_index, batch_name) in enumerate(batch_names)
129
155
EKI_output = calibrate_J_parameters_EKI (FT, nuc_mode, params_list, IC_list, y_truth, end_sim, Γ)
130
156
UKI_output = calibrate_J_parameters_UKI (FT, nuc_mode, params_list, IC_list, y_truth, end_sim, Γ)
131
157
158
+ EKI_calibrated_parameters = EKI_output[1 ] # MEAN of parameters from ensembles in FINAL iteration
159
+ UKI_calibrated_parameters = UKI_output[1 ] # MEAN of parameters from ensembles in FINAL iteration
160
+ EKI_all_params = EKI_output[2 ] # parameters from EACH ensemble in EACH iteration
161
+ UKI_all_params = UKI_output[2 ] # parameters from EACH ensemble in EACH iteration
162
+ EKI_mean_each_iter = EKI_output[3 ] # MEAN of parameters from ensembles in EACH iteration
163
+ UKI_mean_each_iter = UKI_output[3 ] # MEAN of parameters from ensembles in EACH iteration
164
+ UKI_final_iter_spread = UKI_output[4 ] # parameters for EACH ensemble in FINAL iteration
165
+ EKI_error = EKI_output[4 ]
166
+ UKI_error = UKI_output[5 ]
167
+
132
168
EKI_n_iterations = size (EKI_output[2 ])[1 ]
133
169
EKI_n_ensembles = size (EKI_output[2 ][1 ])[2 ]
170
+ UKI_n_iterations = size (UKI_output[2 ])[1 ]
171
+ UKI_n_ensembles = size (UKI_output[2 ][1 ])[2 ]
172
+
173
+ EKI_calibrated_ensemble_means = ensemble_means (EKI_all_params, EKI_n_iterations, EKI_n_ensembles)
174
+ UKI_calibrated_ensemble_means = ensemble_means (UKI_all_params, UKI_n_iterations, UKI_n_ensembles)
134
175
135
- EKI_calibrated_parameters = EKI_output[1 ]
136
- UKI_calibrated_parameters = UKI_output[1 ]
137
- calibrated_ensemble_means = ensemble_means (EKI_output[2 ], EKI_n_iterations, EKI_n_ensembles)
138
176
merge! (EKI_calibrated_coeff_dict, Dict (batch_name => EKI_calibrated_parameters))
139
177
merge! (UKI_calibrated_coeff_dict, Dict (batch_name => UKI_calibrated_parameters))
140
178
@@ -166,14 +204,18 @@ for (batch_index, batch_name) in enumerate(batch_names)
166
204
(; AIDA_t_profile, AIDA_T_profile, AIDA_P_profile, AIDA_ICNC_profile, AIDA_e_profile) = AIDA_data
167
205
168
206
AIDA_ICNC_data_fig = plot_AIDA_ICNC_data (
169
- exp_names[exp_index],
207
+ exp_names[exp_index], start_time[exp_index],
170
208
AIDA_t_profile, AIDA_ICNC_profile,
171
209
t_profile[exp_index], ICNC_moving_avg[exp_index], frozen_frac_moving_mean[exp_index],
172
210
)
173
211
174
212
# # Calibrated coefficients.
175
213
# Did they converge?
176
- calibrated_coeffs_fig = plot_calibrated_coeffs (batch_name, EKI_n_iterations, calibrated_ensemble_means)
214
+ calibrated_coeffs_fig = plot_calibrated_coeffs (
215
+ batch_name,
216
+ EKI_n_iterations, EKI_n_ensembles, EKI_all_params,
217
+ UKI_n_iterations, UKI_n_ensembles, UKI_all_params,
218
+ )
177
219
178
220
# # Calibrated parcel simulations.
179
221
# Does the calibrated parcel give reasonable outputs?
@@ -192,21 +234,32 @@ for (batch_index, batch_name) in enumerate(batch_names)
192
234
)
193
235
194
236
# # Looking at spread in UKI calibrated parameters
195
- ϕ_UKI = UKI_output[2 ]
196
- UKI_parcel_1 = run_model ([params_list[exp_index]], nuc_mode, [ϕ_UKI[1 ,1 ], ϕ_UKI[2 ,1 ]], FT, [IC_list[exp_index]], end_sim)
197
- UKI_parcel_2 = run_model ([params_list[exp_index]], nuc_mode, [ϕ_UKI[1 ,1 ], ϕ_UKI[2 ,1 ]], FT, [IC_list[exp_index]], end_sim)
198
- UKI_parcel_3 = run_model ([params_list[exp_index]], nuc_mode, [ϕ_UKI[1 ,1 ], ϕ_UKI[2 ,1 ]], FT, [IC_list[exp_index]], end_sim)
199
- UKI_parcel_4 = run_model ([params_list[exp_index]], nuc_mode, [ϕ_UKI[1 ,1 ], ϕ_UKI[2 ,1 ]], FT, [IC_list[exp_index]], end_sim)
200
- UKI_parcel_5 = run_model ([params_list[exp_index]], nuc_mode, [ϕ_UKI[1 ,1 ], ϕ_UKI[2 ,1 ]], FT, [IC_list[exp_index]], end_sim)
237
+ UKI_parcel_1 = run_model ([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1 ,1 ], UKI_final_iter_spread[2 ,1 ]], FT, [IC_list[exp_index]], end_sim)
238
+ UKI_parcel_2 = run_model ([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1 ,2 ], UKI_final_iter_spread[2 ,2 ]], FT, [IC_list[exp_index]], end_sim)
239
+ UKI_parcel_3 = run_model ([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1 ,3 ], UKI_final_iter_spread[2 ,3 ]], FT, [IC_list[exp_index]], end_sim)
240
+ UKI_parcel_4 = run_model ([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1 ,4 ], UKI_final_iter_spread[2 ,4 ]], FT, [IC_list[exp_index]], end_sim)
241
+ UKI_parcel_5 = run_model ([params_list[exp_index]], nuc_mode, [UKI_final_iter_spread[1 ,5 ], UKI_final_iter_spread[2 ,5 ]], FT, [IC_list[exp_index]], end_sim)
201
242
202
243
UKI_spread_fig = plot_UKI_spread (
203
244
exp_names[exp_index],
204
245
t_profile[exp_index], frozen_frac_moving_mean[exp_index], Nₜ[exp_index],
205
246
UKI_parcel_1, UKI_parcel_2, UKI_parcel_3, UKI_parcel_4, UKI_parcel_5, UKI_parcel,
206
247
)
207
248
208
- end # plotting individual experiments
209
- end
249
+ end # iterating over experiments in batch
250
+
251
+ # Parcel runs using ensemble means of parameters at each iteration for each exp in batch
252
+ # EKI_loss_batch = MSE(EKI_n_iterations, EKI_n_ensembles, EKI_all_params, data_file_name_list, params_list, nuc_mode, FT, IC_list, end_sim, y_truth, Nₜ)
253
+ # UKI_loss_batch = MSE(UKI_n_iterations, UKI_n_ensembles, UKI_all_params, data_file_name_list, params_list, nuc_mode, FT, IC_list, end_sim, y_truth, Nₜ)
254
+
255
+ # # Plotting loss function over calibration iterations
256
+ loss_fig = plot_loss_func (
257
+ batch_name,
258
+ EKI_n_iterations, UKI_n_iterations,
259
+ EKI_error, UKI_error,
260
+ )
261
+
262
+ end # iterating over batches
210
263
211
264
# Plotting overview
212
265
plot_ICNC_overview (overview_data)
0 commit comments