From d38be18b9f7b00d8964220b100186d543adb40df Mon Sep 17 00:00:00 2001 From: jdub Date: Wed, 8 Nov 2023 18:08:04 +1300 Subject: [PATCH] some mou output tweaks --- benchmarks/basic_tests.py | 3 +- src/libs/pestpp_common/MOEA.cpp | 69 +++++++++++++++++--------- src/libs/pestpp_common/constraints.cpp | 2 +- 3 files changed, 49 insertions(+), 25 deletions(-) diff --git a/benchmarks/basic_tests.py b/benchmarks/basic_tests.py index bf5b2534..331db444 100644 --- a/benchmarks/basic_tests.py +++ b/benchmarks/basic_tests.py @@ -1441,6 +1441,7 @@ def run(): #run() #mf6_v5_ies_test() #prep_ends() + mf6_v5_sen_test() #shutil.copy2(os.path.join("..","exe","windows","x64","Debug","pestpp-glm.exe"),os.path.join("..","bin","win","pestpp-glm.exe")) #shutil.copy2(os.path.join("..", "exe", "windows", "x64", "Debug", "pestpp-ies.exe"), # os.path.join("..", "bin", "win", "pestpp-ies.exe")) @@ -1478,7 +1479,7 @@ def run(): #shutil.copy2(os.path.join("..","exe","windows","x64","Debug","pestpp-ies.exe"),os.path.join("..","bin","win","pestpp-ies.exe")) #tplins1_test() - fr_timeout_test() + #fr_timeout_test() #mf6_v5_ies_test() #mf6_v5_sen_test() diff --git a/src/libs/pestpp_common/MOEA.cpp b/src/libs/pestpp_common/MOEA.cpp index 657915b8..3d453fe6 100644 --- a/src/libs/pestpp_common/MOEA.cpp +++ b/src/libs/pestpp_common/MOEA.cpp @@ -1034,8 +1034,8 @@ map> MOEA::decvar_report(ParameterEnsemble& _dp) { max_len = max(max_len,(int)dv.size()); } - ss << left << setw(max_len) << "decision variable" << right << setw(10) << "ubnd" << setw(10) << "lbnd" << setw(10) << "mean" << setw(20); - ss << "standard devation" << setw(12) << "min" << setw(12) << "max" << endl; + ss << left << setw(max_len) << "decision variable " << right << setw(10) << "ubnd " << setw(10) << "lbnd " << setw(12) << "mean " << setw(12); + ss << "stdev " << setw(12) << "min " << setw(12) << "max " << endl; map meanmap,stdmap; _dp.fill_moment_maps(meanmap,stdmap); Eigen::VectorXd vec; @@ -1046,13 +1046,13 @@ map> MOEA::decvar_report(ParameterEnsemble& _dp) { sum.clear(); prec = pest_scenario.get_ctl_parameter_info().get_parameter_rec_ptr(dv); - ss << left << setw(max_len) << dv; - ss << right << setw(10) << prec->ubnd; - ss << right << setw(10) << prec->lbnd; - ss << right << setw(10) << meanmap[dv]; - ss << right << setw(20) << stdmap[dv]; + ss << left << setw(max_len) << dv << " "; + ss << right << setw(10) << prec->ubnd << " "; + ss << right << setw(10) << prec->lbnd << " "; + ss << right << setw(12) << meanmap[dv] << " "; + ss << right << setw(12) << stdmap[dv] << " "; vec = _dp.get_var_vector(dv); - ss << setw(12) << vec.minCoeff(); + ss << setw(12) << vec.minCoeff() << " "; ss << setw(12) << vec.maxCoeff(); ss << endl; sum["mean"] = meanmap[dv]; @@ -1079,10 +1079,10 @@ map> MOEA::decvar_change_report(map tags{ "mean","max","min" }; for (auto dv : dv_names) @@ -1092,7 +1092,7 @@ map> MOEA::decvar_change_report(map> MOEA::decvar_change_report(map 0) + throw_moea_error("too few members to continue"); + else + { + ss.str(""); + ss << "WARNING: very few population members..." << endl; + message(0,ss.str()); + } + } message(2,"aligning dv and obs populations"); @@ -2434,7 +2442,8 @@ void MOEA::initialize() { message(0, "too few population members:", op.shape().first); message(1, "need at least ", error_min_members); - throw_moea_error(string("too few active population members, cannot continue")); + if (pest_scenario.get_control_info().noptmax > 0) + throw_moea_error(string("too few active population members, cannot continue")); } if (op.shape().first < warn_min_members) { @@ -3364,16 +3373,23 @@ ParameterEnsemble MOEA::get_updated_pso_velocty(ParameterEnsemble& _dp, vector MOEA::get_pso_gbest_solutions(int num_reals, ParameterEnsemble& _dp, ObservationEnsemble& _op) { + stringstream ss; DomPair dompair = objectives.get_nsga2_pareto_dominance(-999, _op, _dp, &constraints, false); vector nondom_solutions = dompair.first; vector gbest_solutions; //if no non dom solutions, then use the dominated ones... if (nondom_solutions.size() == 0) { + ss.str(""); + ss << "WARNING: no nondom solutions for pst gbest calculation, using dominated solutions" << endl; nondom_solutions = dompair.second; } - if (nondom_solutions.size() == 1) + else if (nondom_solutions.size() == 1) { + ss.str(""); + ss << "WARNING: only one nondom solution for pst gbest calculation" << endl; + file_manager.rec_ofstream() << ss.str(); + cout << ss.str(); for (int i = 0; i < num_reals; i++) gbest_solutions.push_back(nondom_solutions[0]); return gbest_solutions; @@ -3381,12 +3397,18 @@ vector MOEA::get_pso_gbest_solutions(int num_reals, ParameterEnsemble& _ map crowd_dist = objectives.get_cuboid_crowding_distance(nondom_solutions); //normalize cd - double mx = -1.0e+30; + double mx = 0.0; for (auto& cd : crowd_dist) if ((cd.second != CROWDING_EXTREME) && (cd.second > mx)) mx = cd.second; - if ((mx < 0.0) && (iter > 0)) - throw_moea_error("pso max crowding distance is negative"); + if ((mx == 0.0) && (iter > 0)) { + ss.str(""); + ss << "WARNING: pso gbest solution max crowding distance == 0.0, " << nondom_solutions.size() + << " nondom solutions being used" << endl; + file_manager.rec_ofstream() << ss.str(); + cout << ss.str(); + + } for (auto& cd : crowd_dist) { if (cd.second == CROWDING_EXTREME) { @@ -3423,8 +3445,9 @@ vector MOEA::get_pso_gbest_solutions(int num_reals, ParameterEnsemble& _ if (found) break; count++; - if (count > 1000000) - throw_moea_error("MOEA::get_pso_gbest_solutions() seems to be stuck in a infinite loop...."); + if (count > 1000000) { + throw_moea_error("MOEA::get_pso_gbest_solutions() seems to be stuck in a infinite loop...."); + } } gbest_solutions.push_back(candidate); } diff --git a/src/libs/pestpp_common/constraints.cpp b/src/libs/pestpp_common/constraints.cpp index 21655062..b32d68d6 100644 --- a/src/libs/pestpp_common/constraints.cpp +++ b/src/libs/pestpp_common/constraints.cpp @@ -875,7 +875,7 @@ void Constraints::initial_report() f_rec << setw(15) << constraint_sense_name[name]; f_rec << setw(15) << constraints_obs.get_rec(name) << endl; } - cout << "..." << ctl_ord_obs_constraint_names.size() << " obs-based constraints, see rec file for listing" << endl; + cout << "..." << ctl_ord_obs_constraint_names.size() << " obs-based constraints/objectives, see rec file for listing" << endl; if (num_pi_constraints() > 0) {