Skip to content

Commit

Permalink
new branch naming scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
jtwhite79 committed Dec 16, 2024
1 parent a42d9a2 commit 471a3a9
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 52 deletions.
67 changes: 33 additions & 34 deletions src/libs/pestpp_common/EnsembleMethodUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2492,16 +2492,16 @@ double L2PhiHandler::calc_std(map<string, double> *phi_map)

double L2PhiHandler::get_representative_phi(phiType pt)
{
//if (pest_scenario->get_pestpp_options().get_ies_n_iter_mean() < 0)
//if (pest_scenario->get_pestpp_options().get_ies_n_iter_reinflate() < 0)
bool use_min = false;
for (auto& fac : pest_scenario->get_pestpp_options().get_ies_n_iter_mean())
{
if (fac < 0)
{
use_min = true;
break;
}
}
// for (auto& fac : pest_scenario->get_pestpp_options().get_ies_n_iter_reinflate())
// {
// if (fac < 0)
// {
// use_min = true;
// break;
// }
// }
if (use_min)
{
return get_min(pt);
Expand Down Expand Up @@ -4317,7 +4317,7 @@ bool EnsembleMethod::should_terminate(int current_n_iter_mean)
message(1, "phiredstp: ", phiredstp);
message(1, "nphistp: ", nphistp);
message(1, "nphinored (also used for consecutive bad lambda cycles): ", nphinored);
//int n_mean_iter = pest_scenario.get_pestpp_options().get_ies_n_iter_mean();
//int n_mean_iter = pest_scenario.get_pestpp_options().get_ies_n_iter_reinflate();
vector<double>::iterator begin_idx = best_mean_phis.begin();
//if ((current_n_iter_mean > 0) && (best_mean_phis.size() > current_n_iter_mean))
// begin_idx = best_mean_phis.end() - (current_n_iter_mean+1); //bc of prior phi and then adding the mean shift to the list
Expand Down Expand Up @@ -4910,7 +4910,7 @@ void EnsembleMethod::initialize(int cycle, bool run, bool use_existing)
consec_bad_lambda_cycles = 0;
reinflate_to_minphi_real = false;
bool use_min = false;
for (auto& fac : pest_scenario.get_pestpp_options().get_ies_n_iter_mean())
for (auto& fac : pest_scenario.get_pestpp_options().get_ies_n_iter_reinflate())
{
if (fac < 0)
{
Expand All @@ -4923,7 +4923,7 @@ void EnsembleMethod::initialize(int cycle, bool run, bool use_existing)
{
message(2,"n_iter_reinflate < 0, using min-phi real for re-inflation, resetting n_iter_reinflate to positive");
reinflate_to_minphi_real = true;
//pest_scenario.get_pestpp_options_ptr()->set_ies_n_iter_mean(-1 * pest_scenario.get_pestpp_options().get_ies_n_iter_mean());
//pest_scenario.get_pestpp_options_ptr()->set_ies_n_iter_reinflate(-1 * pest_scenario.get_pestpp_options().get_ies_n_iter_reinflate());
}
lam_mults = pest_scenario.get_pestpp_options().get_ies_lam_mults();
if (lam_mults.size() == 0)
Expand Down Expand Up @@ -7438,35 +7438,35 @@ bool EnsembleMethod::solve(bool use_mda, vector<double> inflation_factors, vecto
return true;
}

void EnsembleMethod::reset_par_ensemble_to_prior_mean(){
void EnsembleMethod::reset_par_ensemble_to_prior_mean(double reinflate_factor){

string min_phi_name = "";
if (true)
{
map<string,double> pmap = ph.get_phi_map(L2PhiHandler::phiType::ACTUAL);
double min_phi = numeric_limits<double>::max();
//find the min phi real...
map<string,double> pmap = ph.get_phi_map(L2PhiHandler::phiType::ACTUAL);
double min_phi = numeric_limits<double>::max();

for (auto& item : pmap)
{
if (item.second < min_phi)
{
min_phi = item.second;
min_phi_name = item.first;
}
}
vector<string> real_names = oe.get_real_names();
int idx = distance(real_names.begin(),find(real_names.begin(),real_names.end(),min_phi_name));
if (idx == real_names.size())
for (auto& item : pmap)
{
if (item.second < min_phi)
{
throw_em_error("min phi realization name not found in obs ensemble");
min_phi = item.second;
min_phi_name = item.first;
}
real_names = pe.get_real_names();
min_phi_name = real_names[idx];

}
vector<string> real_names = oe.get_real_names();
int idx = distance(real_names.begin(),find(real_names.begin(),real_names.end(),min_phi_name));
if (idx == real_names.size())
{
throw_em_error("min phi realization name not found in obs ensemble");
}
real_names = pe.get_real_names();
min_phi_name = real_names[idx];

message(0,"resetting current parameter ensemble to prior ensemble with current ensemble mean");
message(1,"reinflation factor:",reinflate_factor);
performance_log->log_event("getting prior parameter ensemble mean-centered anomalies");
Eigen::MatrixXd anoms = pe_base.get_eigen_anomalies(pe_base.get_real_names(), pe.get_var_names(), pest_scenario.get_pestpp_options().get_ies_center_on());

anoms = anoms * reinflate_factor;
performance_log->log_event("getting current parameter ensemble mean vector");
vector<double> mean_vec = pe.get_mean_stl_var_vector();
Eigen::VectorXd offset(mean_vec.size());
Expand All @@ -7478,7 +7478,6 @@ void EnsembleMethod::reset_par_ensemble_to_prior_mean(){
message(2,"using min-phi realization for offset");
}


performance_log->log_event("adding offset to anomalies");
for (int i = 0; i < mean_vec.size(); i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libs/pestpp_common/EnsembleMethodUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ class EnsembleMethod

double get_lambda();

void reset_par_ensemble_to_prior_mean();
void reset_par_ensemble_to_prior_mean(double reinflate_factor);

};
#endif
26 changes: 17 additions & 9 deletions src/libs/pestpp_common/EnsembleSmoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ void IterEnsembleSmoother::iterate_2_solution()
ofstream &frec = file_manager.rec_ofstream();

bool accept;
vector<int> n_iter_mean = pest_scenario.get_pestpp_options().get_ies_n_iter_mean();
vector<int> n_iter_reinflate = pest_scenario.get_pestpp_options().get_ies_n_iter_reinflate();
vector<double> reinflate_factor = pest_scenario.get_pestpp_options().get_ies_reinflate_factor();

int iters_since_reinflate = 0;
int n_iter_mean_idx = 0;
int current_n_iter_mean = n_iter_mean[n_iter_mean_idx];
int n_iter_reinflate_idx = 0;
int current_n_iter_mean = n_iter_reinflate[n_iter_reinflate_idx];
double current_reinflate_factor = reinflate_factor[n_iter_reinflate_idx];
int solution_iter = 0;
for (int i = 0; i < pest_scenario.get_control_info().noptmax; i++)
{
Expand Down Expand Up @@ -76,23 +78,29 @@ void IterEnsembleSmoother::iterate_2_solution()
else
consec_bad_lambda_cycles++;

//if ((n_iter_mean > 0) && (solution_iter % n_iter_mean == 0))
//if ((n_iter_reinflate > 0) && (solution_iter % n_iter_reinflate == 0))
iters_since_reinflate++;
if ((current_n_iter_mean != 0) && (iters_since_reinflate >= current_n_iter_mean))
{
message(2,"incrementing iteration count for reinflation cycle");
iter++;
reset_par_ensemble_to_prior_mean();

reset_par_ensemble_to_prior_mean(current_reinflate_factor);
iters_since_reinflate = 0;
n_iter_mean_idx++;
if (n_iter_mean.size() > n_iter_mean_idx)
n_iter_reinflate_idx++;
if (reinflate_factor.size() > n_iter_reinflate_idx)
{
current_reinflate_factor = reinflate_factor[n_iter_reinflate_idx];
}
if (n_iter_reinflate.size() > n_iter_reinflate_idx)
{
current_n_iter_mean = n_iter_mean[n_iter_mean_idx];
current_n_iter_mean = n_iter_reinflate[n_iter_reinflate_idx];
}
}

if (should_terminate(current_n_iter_mean))
{
//if (iter > pest_scenario.get_pestpp_options().get_ies_n_iter_mean()) {
//if (iter > pest_scenario.get_pestpp_options().get_ies_n_iter_reinflate()) {
if (current_n_iter_mean == 0) {
break;
}
Expand Down
26 changes: 21 additions & 5 deletions src/libs/pestpp_common/pest_data_structs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1185,12 +1185,23 @@ bool PestppOptions::assign_ies_value_by_key(const string& key, const string& val
{
passed_args.insert("IES_N_ITER_MEAN");
passed_args.insert("IES_N_ITER_REINFLATE");
ies_n_iter_mean.clear();
ies_n_iter_reinflate.clear();
vector<string> tok;
tokenize(value, tok, ",");
for (const auto& fac : tok)
{
ies_n_iter_mean.push_back(convert_cp<int>(fac));
ies_n_iter_reinflate.push_back(convert_cp<int>(fac));
}
return true;
}
else if (key == "IES_REINFLATE_FACTOR")
{
vector<string> tok;
tokenize(value, tok, ",");
ies_reinflate_factor.clear();
for (const auto& fac : tok)
{
ies_reinflate_factor.push_back(convert_cp<double>(fac));
}
return true;
}
Expand Down Expand Up @@ -1844,7 +1855,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_reinflate: " << endl;
for (auto v : ies_n_iter_mean)
for (auto v : ies_n_iter_reinflate)
os << v << ",";
os << endl;
os << "ies_reinflate_factor: " << endl;
for (auto v : ies_reinflate_factor)
os << v << ",";
os << endl;
os << "ies_updatebyreals: " << ies_updatebyreals << endl;
Expand Down Expand Up @@ -2033,11 +2048,12 @@ void PestppOptions::set_defaults()
set_ies_localizer_forgive_missing(false);
set_ies_phi_fractions_files("");
set_ies_phi_factors_by_real(false);
set_ies_n_iter_mean(vector<int>{0});
set_ies_n_iter_reinflate(vector < int > {0});
set_ies_reinflate_factor(vector < double > {1.0});

set_ies_updatebyreals(false);
set_save_dense(false);


// DA parameters
//set_da_use_ies(false);
set_da_par_cycle_table("");
Expand Down
10 changes: 7 additions & 3 deletions src/libs/pestpp_common/pest_data_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,11 @@ class PestppOptions {
void set_ies_multimodal_alpha(double _flag) { ies_multimodal_alpha = _flag; }
void set_ensemble_output_precision(int prec) { ensemble_output_precision = prec;}
int get_ensemble_output_precision() const {return ensemble_output_precision;}
void set_ies_n_iter_mean(vector<int> _n_iter_mean) {ies_n_iter_mean = _n_iter_mean;}
vector<int> get_ies_n_iter_mean() const {return ies_n_iter_mean;}
void set_ies_n_iter_reinflate(vector<int> _n_iter_reinflate) { ies_n_iter_reinflate = _n_iter_reinflate;}
vector<int> get_ies_n_iter_reinflate() const {return ies_n_iter_reinflate;}
void set_ies_reinflate_factor(vector<double> reinflate_factor) { ies_reinflate_factor = reinflate_factor;}
vector<double> get_ies_reinflate_factor() const {return ies_reinflate_factor;}



string get_gsa_method() const { return gsa_method; }
Expand Down Expand Up @@ -828,7 +831,8 @@ class PestppOptions {
bool ies_localizer_forgive_missing;
string ies_phi_fractions_file;
bool ies_phi_factors_by_real;
vector<int> ies_n_iter_mean;
vector<int> ies_n_iter_reinflate;
vector<double> ies_reinflate_factor;
bool ies_updatebyreals;


Expand Down

0 comments on commit 471a3a9

Please sign in to comment.