From bcdf40a8a06427b6d72c2c93734c096fefae6093 Mon Sep 17 00:00:00 2001 From: jwhite Date: Fri, 16 Aug 2024 13:36:08 -0600 Subject: [PATCH] initial attempt at updatebyreals --- .../pestpp_common/EnsembleMethodUtils.cpp | 20 +++++++++++-------- src/libs/pestpp_common/pest_data_structs.cpp | 10 +++++++++- src/libs/pestpp_common/pest_data_structs.h | 3 +++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/libs/pestpp_common/EnsembleMethodUtils.cpp b/src/libs/pestpp_common/EnsembleMethodUtils.cpp index 58d5b1c7..bb4d8af0 100644 --- a/src/libs/pestpp_common/EnsembleMethodUtils.cpp +++ b/src/libs/pestpp_common/EnsembleMethodUtils.cpp @@ -7110,8 +7110,8 @@ bool EnsembleMethod::solve(bool use_mda, vector inflation_factors, vecto } if (best_idx == -1) { - message(0, "WARNING: unsuccessful upgrade testing, resetting lambda to 10000.0 and returning to upgrade calculations"); - last_best_lam = 10000.0; + message(0, "WARNING: unsuccessful upgrade testing, multiplying lambda by 10000.0 and returning to upgrade calculations"); + last_best_lam *= 10000.0; return false; } @@ -7121,7 +7121,6 @@ bool EnsembleMethod::solve(bool use_mda, vector inflation_factors, vecto if ((best_idx != -1) && (use_subset) && (local_subset_size < pe.shape().first)) { - double acc_phi = last_best_mean * acc_fac; if (pest_scenario.get_pestpp_options().get_ies_debug_high_subset_phi()) @@ -7348,9 +7347,15 @@ bool EnsembleMethod::solve(bool use_mda, vector inflation_factors, vecto message(0, "updating parameter ensemble"); performance_log->log_event("updating parameter ensemble"); last_best_mean = best_mean; - - pe = pe_lams[best_idx]; - oe = oe_lam_best; + if (pest_scenario.get_pestpp_options().get_ies_updatebyreals()) + { + message(0, "only updating realizations with reduced phi"); + update_reals_by_phi(pe_lams[best_idx], oe_lam_best); + } + else { + pe = pe_lams[best_idx]; + oe = oe_lam_best; + } if (best_std < last_best_std * acc_fac) { double new_lam = lam_vals[best_idx] * lam_dec; @@ -7368,11 +7373,10 @@ bool EnsembleMethod::solve(bool use_mda, vector inflation_factors, vecto else { //message(0, "not updating parameter ensemble"); - if (!use_mda) + if ((!use_mda) && (!pest_scenario.get_pestpp_options().get_ies_updatebyreals())) { message(0, "only updating realizations with reduced phi"); update_reals_by_phi(pe_lams[best_idx], oe_lam_best); - } ph.update(oe, pe, weights); //re-check phi diff --git a/src/libs/pestpp_common/pest_data_structs.cpp b/src/libs/pestpp_common/pest_data_structs.cpp index 3bea7f89..cfad3779 100644 --- a/src/libs/pestpp_common/pest_data_structs.cpp +++ b/src/libs/pestpp_common/pest_data_structs.cpp @@ -1186,6 +1186,11 @@ bool PestppOptions::assign_ies_value_by_key(const string& key, const string& val convert_ip(value,ies_n_iter_mean); return true; } + else if (key == "IES_UPDATE_BY_REALS") + { + ies_updatebyreals = pest_utils::parse_string_arg_to_bool(value); + return true; + } return false; @@ -1824,9 +1829,11 @@ void PestppOptions::summary(ostream& os) const os << "ies_phi_factors_file: " << ies_phi_fractions_file << endl; os << "ies_phi_factors_by_real: " << ies_phi_factors_by_real << endl; os << "ies_n_iter_mean: " << ies_n_iter_mean << endl; + os << "ies_updatebyreals: " << ies_updatebyreals << endl; + - os << endl << "pestpp-sen options: " << endl; + os << endl << "pestpp-sen options: " << endl; os << "gsa_method: " << gsa_method << endl; os << "gsa_morris_pooled_obs: " << gsa_morris_pooled_obs << endl; os << "gsa_morris_obs_sen: " << gsa_morris_obs_sen << endl; @@ -2010,6 +2017,7 @@ void PestppOptions::set_defaults() set_ies_phi_fractions_files(""); set_ies_phi_factors_by_real(false); set_ies_n_iter_mean(0); + set_ies_updatebyreals(true); // DA parameters diff --git a/src/libs/pestpp_common/pest_data_structs.h b/src/libs/pestpp_common/pest_data_structs.h index 0201bf37..b51331d0 100644 --- a/src/libs/pestpp_common/pest_data_structs.h +++ b/src/libs/pestpp_common/pest_data_structs.h @@ -492,6 +492,8 @@ class PestppOptions { void set_ies_phi_fractions_files(string _file) {ies_phi_fractions_file = _file;} bool get_ies_phi_factors_by_real() const {return ies_phi_factors_by_real;} void set_ies_phi_factors_by_real(bool _flag) {ies_phi_factors_by_real = _flag;} + bool get_ies_updatebyreals() const {return ies_updatebyreals;} + void set_ies_updatebyreals(bool _flag) {ies_updatebyreals = _flag;} @@ -823,6 +825,7 @@ class PestppOptions { string ies_phi_fractions_file; bool ies_phi_factors_by_real; int ies_n_iter_mean; + bool ies_updatebyreals; // Data Assimilation parameters