Skip to content

Commit

Permalink
start
Browse files Browse the repository at this point in the history
  • Loading branch information
jtwhite79 committed Nov 6, 2024
1 parent 12994e4 commit 29d7ef3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
59 changes: 59 additions & 0 deletions src/libs/pestpp_common/MOEA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "EnsembleMethodUtils.h"
#include "constraints.h"
#include "eigen_tools.h"
#include "RedSVD-h.h"

using namespace std;

Expand Down Expand Up @@ -3550,6 +3551,64 @@ ParameterEnsemble MOEA::generate_pso_population(int num_members, ParameterEnsemb
return new_dp;
}

ParameterEnsemble MOEA::generate_empcov_population(int num_members, ParameterEnsemble& _dp, ObservationEnsemble& _op)
{

message(1, "generating empirical-covariance population of size", num_members);
vector<string> gbest_solutions = get_pso_gbest_solutions(_dp.shape().first, dp_archive, op_archive);
ParameterEnsemble cur_velocity = get_updated_pso_velocty(_dp, gbest_solutions);
Eigen::MatrixXd draws(num_members,_dp.shape().second);
for (int i = 0; i < num_members; i++)
{
for (int j = 0; j < _dp.shape().second; j++)
{
draws(i, j) = draw_standard_normal(rand_gen);
}
}
ParameterEnsemble new_dp(&pest_scenario, &rand_gen, draws, _dp.get_real_names(), _dp.get_var_names());
new_dp.set_fixed_info(_dp.get_fixed_info());
vector<string> new_real_names;
for (int i=0;i<num_members;i++)
{
new_real_names.push_back(get_new_member_name("empcov"));
}
new_dp.set_real_names(new_real_names);
new_dp.reset_org_real_names();

Eigen::MatrixXd anom,cov;
anom = _dp.get_eigen_anomalies();
cov = anom.transpose() * anom;

Covariance covmat(new_dp.get_var_names(),cov.sparseView());

new_dp.set_trans_status(_dp.get_trans_status());
new_dp.enforce_bounds(performance_log,false);
new_dp.check_for_normal("new emp-cov population");

/*if (_dp.get_fixed_info().get_map_size() > 0) {
vector<string> fi_fixed_names = _dp.get_fixed_info().get_fixed_names();
new_dp.get_fixed_info().set_fixed_names(fi_fixed_names);
map<string, double> fi;
vector<string> rnames = _dp.get_fixed_info().get_real_names();
set<string> sdp_rnames(rnames.begin(),rnames.end());
set<string>::iterator dpend = sdp_rnames.end();
rnames = temp.get_fixed_info().get_real_names();
set<string> stemp_rnames(rnames.begin(),rnames.end());
set<string>::iterator tend = stemp_rnames.end();
for (auto &p : primary_parent_map) {
if (sdp_rnames.find(p.second) != dpend)
fi = _dp.get_fixed_info().get_real_fixed_values(p.second);
else if (stemp_rnames.find(p.second) != tend)
fi = temp.get_fixed_info().get_real_fixed_values(p.second);
else
throw_moea_error("fixed info for existing realization '"+p.second+"' not found");
new_dp.get_fixed_info().add_realization(p.first, fi);
}*/
//}
return new_dp;
}


ParameterEnsemble MOEA::simplex_cceua_kn(ParameterEnsemble s, int k, int optbounds)
{
//C++ implementation of the cceua algorithm, Duan et al. (1992) with the addition of k worst points
Expand Down
5 changes: 3 additions & 2 deletions src/libs/pestpp_common/MOEA.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Ensemble.h"
#include "constraints.h"
#include "EnsembleMethodUtils.h"
#include "RedSVD-h.h"

const string POP_SUM_TAG = "pareto.summary.csv";
const string ARC_SUM_TAG = "pareto.archive.summary.csv";
Expand Down Expand Up @@ -212,13 +213,13 @@ class MOEA
ParameterEnsemble generate_pso_population(int num_members, ParameterEnsemble& _dp);
ParameterEnsemble simplex_cceua_kn(ParameterEnsemble s, int k, int optbounds);
ParameterEnsemble generate_simplex_population(int num_members, ParameterEnsemble& _dp, ObservationEnsemble& _op);

ParameterEnsemble generate_empcov_population(int num_members, ParameterEnsemble& _dp, ObservationEnsemble& _op);
ParameterEnsemble get_updated_pso_velocty(ParameterEnsemble& _dp, vector<string>& gbest_solutions);

vector<string> get_pso_gbest_solutions(int num_reals, ParameterEnsemble& _dp, ObservationEnsemble& _op);
void update_pso_pbest(ParameterEnsemble& _dp, ObservationEnsemble& _op);

map<string, string> current_pso_lineage_map;
map<string, string> current_pso_lineage_map, current_empcov_lineage_map;

vector<int> selection(int num_to_select, ParameterEnsemble& _dp, MouMateType& matetype);

Expand Down
3 changes: 0 additions & 3 deletions src/libs/run_managers/yamr/PantherAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,9 +829,6 @@ void PANTHERAgent::start_impl(const string &host, const string &port)
int group_id = net_pack.get_group_id();
int run_id = net_pack.get_run_id();
string info_txt = net_pack.get_info_txt();
//jwhite 25 may 2020 - commented this out in develop merge from Ayman's develop
//so that I can pull in the run mgr message passing enhancements
//will uncommented later when merging in pestpp-da
pest_utils::upper_ip(info_txt);
int da_cycle = NetPackage::NULL_DA_CYCLE;
if (info_txt.find("DA_CYCLE:") != string::npos)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/run_managers/yamr/RunManagerPanther.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ RunManagerAbstract::RUN_UNTIL_COND RunManagerPanther::run_until(RUN_UNTIL_COND c
if (agent_info_set.size() == 0)
{
ss.str("");
ss << "lost comms with all agents, closing all reminaing open file transfers";
ss << "lost comms with all agents, closing all remaining open file transfers";
report(ss.str(),true);
for (auto& m : open_file_socket_map) {
string fname = m.second;
Expand Down

0 comments on commit 29d7ef3

Please sign in to comment.