From 5865dc1e28e501e01fd52c20a1e5167cd6a2d4cb Mon Sep 17 00:00:00 2001 From: Guilherme Aldeia Date: Fri, 17 Nov 2023 16:45:25 -0500 Subject: [PATCH 1/7] Fixed "command not found" when using `./configure tests` --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 6e8d8ccce..b3a05365e 100755 --- a/configure +++ b/configure @@ -38,7 +38,7 @@ elif [ "$1" == "lpc_cuda" ] ; then BUILD_DIR="buildGPU" OMP=OFF EXTRA_FLAGS="-DCORE_USE_CUDA=ON" -elif [ "$1" == "tests" || "$1" == "test" ] ; then +elif [[ "$1" == "tests" || "$1" == "test" ]] ; then EXTRA_FLAGS="-DGTEST=ON" elif [ "$1" == "gpu" ] ; then BUILD_DIR="buildGPU" From 6a8f0e2f17065bb1d4cfcc5e12d4f3acc144cea2 Mon Sep 17 00:00:00 2001 From: Guilherme Aldeia Date: Fri, 17 Nov 2023 16:57:15 -0500 Subject: [PATCH 2/7] Parameterized selection tests --- tests/selectionTests.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/selectionTests.cc b/tests/selectionTests.cc index 79960b22e..58355715d 100755 --- a/tests/selectionTests.cc +++ b/tests/selectionTests.cc @@ -1,10 +1,22 @@ #include "testsHeader.h" -TEST(Selection, SelectionOperator) +class SelectionTest : public testing::TestWithParam { +protected: + void SetUp() override { + selectionType = GetParam(); + } + + std::string selectionType; +}; + +TEST_P(SelectionTest, SelectionOperator) { Feat feat = make_estimator(100, 100, "LinearRidgeRegression", false, 1, 666); feat.set_scorer("mae"); + feat.set_selection(selectionType); + ASSERT_STREQ(selectionType.c_str(), feat.selector.get_type().c_str()); + MatrixXf X(7,2); X << 0,1, 0.47942554,0.87758256, @@ -58,3 +70,7 @@ TEST(Selection, SelectionOperator) ASSERT_EQ(parents.size(), feat.get_pop_size()); } + +INSTANTIATE_TEST_SUITE_P(AllSelectionTypes, SelectionTest, + testing::Values("lexicase", "fair_lexicase", "simanneal", "tournament", + "offspring", "random", "nsga2")); \ No newline at end of file From 7427a09dd8ae72970a0442a503a526fe15a96ad0 Mon Sep 17 00:00:00 2001 From: Guilherme Aldeia Date: Fri, 17 Nov 2023 17:06:21 -0500 Subject: [PATCH 3/7] Added binds to retrieve information about expression complexity --- feat/feat.py | 5 ++++- src/pybind.cc | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/feat/feat.py b/feat/feat.py index d2adfed2b..0684e314a 100644 --- a/feat/feat.py +++ b/feat/feat.py @@ -398,7 +398,10 @@ def _check_shape(self, X): def get_representation(self): return self.cfeat_.get_representation() def get_model(self, sort=True): return self.cfeat_.get_model(sort) def get_coefs(self): return self.cfeat_.get_coefs() - + def get_n_params(self): return self.cfeat_.get_n_params() + def get_dim(self): return self.cfeat_.get_dim() + def get_n_nodes(self): return self.cfeat_.get_n_nodes() + class FeatRegressor(Feat): """Convenience method that enforces regression options.""" def __init__(self,**kwargs): diff --git a/src/pybind.cc b/src/pybind.cc index 3794220eb..849c99347 100644 --- a/src/pybind.cc +++ b/src/pybind.cc @@ -149,6 +149,9 @@ PYBIND11_MODULE(_feat, m) .def("save", &Feat::save) .def("load", &Feat::load) .def("get_representation", &Feat::get_representation) + .def("get_n_params", &Feat::get_n_params) + .def("get_dim", &Feat::get_dim) + .def("get_n_nodes", &Feat::get_n_nodes) .def("get_model", &Feat::get_model, py::arg("sort") = true) .def("get_eqn", &Feat::get_eqn, py::arg("sort") = true) ; From f5b12021bf777d611136fde12a4eb52dff46b5fb Mon Sep 17 00:00:00 2001 From: Guilherme Aldeia Date: Fri, 17 Nov 2023 17:16:02 -0500 Subject: [PATCH 4/7] Fixed empy logfile when a file path was specified, but verbosity <= 1 --- src/feat.cc | 17 ++++++++++------- src/feat.h | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/feat.cc b/src/feat.cc index 7ff04027d..f5a980f16 100755 --- a/src/feat.cc +++ b/src/feat.cc @@ -725,6 +725,9 @@ void Feat::run_generation(unsigned int g, else if(params.verbosity == 1) printProgress(fraction); + if (!logfile.empty()) + log_stats(log); + if (save_pop > 1) pop.save(this->logfile+".pop.gen" + to_string(params.current_gen) + ".json"); @@ -1539,13 +1542,13 @@ void Feat::print_stats(std::ofstream& log, float fraction) << "med_dim\n"; } - log << params.current_gen << sep - << timer.Elapsed().count() << sep - << stats.min_loss.back() << sep - << this->min_loss_v << sep - << stats.med_loss.back() << sep - << stats.med_loss_v.back() << sep - << stats.med_size.back() << sep + log << params.current_gen << sep + << timer.Elapsed().count() << sep + << stats.min_loss.back() << sep + << this->min_loss_v << sep + << stats.med_loss.back() << sep + << stats.med_loss_v.back() << sep + << stats.med_size.back() << sep << stats.med_complexity.back() << sep << stats.med_num_params.back() << sep << stats.med_dim.back() << "\n"; diff --git a/src/feat.h b/src/feat.h index a9885fa67..13eee1137 100755 --- a/src/feat.h +++ b/src/feat.h @@ -433,7 +433,8 @@ class Feat void calculate_stats(const DataRef& d); void print_stats(std::ofstream& log, float fraction); - + void log_stats(std::ofstream& log); + // gets weights via univariate initial models vector univariate_initial_model(DataRef &d, int n_feats); /// method to fit inital ml model From a6f8ccec1441c7d91f991ce3df37f9c1c5ce530c Mon Sep 17 00:00:00 2001 From: Guilherme Aldeia Date: Fri, 17 Nov 2023 17:17:14 -0500 Subject: [PATCH 5/7] Updated documentation string for `functions` argument --- feat/feat.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/feat/feat.py b/feat/feat.py index 0684e314a..8bace88c6 100644 --- a/feat/feat.py +++ b/feat/feat.py @@ -52,9 +52,9 @@ class Feat(BaseEstimator): 'a': all 'b': boolean only 'f': floating point only - functions: string, optional (default: "") + functions: list[string], optional (default: []) A comma-separated string of operators to use to build features. - If functions="", all the available functions are used. + If functions=[], all the available functions are used. Options: +, -, *, /, ^2, ^3, sqrt, sin, cos, exp, log, ^, logit, tanh, gauss, relu, split, split_c, b2f, c2f, and, or, not, xor, =, <, <=, >, >=, if, ite @@ -401,7 +401,7 @@ def get_coefs(self): return self.cfeat_.get_coefs() def get_n_params(self): return self.cfeat_.get_n_params() def get_dim(self): return self.cfeat_.get_dim() def get_n_nodes(self): return self.cfeat_.get_n_nodes() - + class FeatRegressor(Feat): """Convenience method that enforces regression options.""" def __init__(self,**kwargs): From 283d7ab221a0e09e18eeac515593f9a46dcb41f6 Mon Sep 17 00:00:00 2001 From: Guilherme Aldeia Date: Fri, 17 Nov 2023 17:30:43 -0500 Subject: [PATCH 6/7] Fixed stats not being calculated for logfile Previously, complexity was set just if `use_arch=true` or one of `sel` or `surv` parameters would use a pareto dominance criteria (because they are calculated only if strictly needed). If we want a logfile, but `use_arch=false` and no pareto dominance is calculated in `sel` or `surv`, then the logfile would have all zeros for complexity statistics. Now we make sure we calculate the stats if they are being reported to the user, regardless if is in archive, in verbosity, or in a logfile. --- src/feat.cc | 74 +++++++++++++++++++++++++------------------ src/pop/archive.cc | 4 --- src/sel/tournament.cc | 2 +- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/feat.cc b/src/feat.cc index f5a980f16..b1cf020c0 100755 --- a/src/feat.cc +++ b/src/feat.cc @@ -716,6 +716,13 @@ void Feat::run_generation(unsigned int g, if (params.max_stall > 0) update_stall_count(stall_count, updated_best); + if ( (use_arch || params.verbosity>1) || !logfile.empty()) { + // set objectives to make sure they are reported in log/verbose/arch + #pragma omp parallel for + for (unsigned int i=0; ipop.size()); i = 0; for (auto& p : this->pop.individuals) - { + { + // Calculate to assure it gets reported in stats (even if's not used as an obj) Complexities(i) = p.get_complexity(); ++i; } @@ -1523,37 +1531,43 @@ void Feat::print_stats(std::ofstream& log, float fraction) } std::cout <<"\n\n"; - - if (!logfile.empty()) - { - // print stats in tabular format - string sep = ","; - if (params.current_gen == 0) // print header - { - log << "generation" << sep - << "time" << sep - << "min_loss" << sep - << "min_loss_val" << sep - << "med_loss" << sep - << "med_loss_val" << sep - << "med_size" << sep - << "med_complexity" << sep - << "med_num_params" << sep - << "med_dim\n"; - } +} - log << params.current_gen << sep - << timer.Elapsed().count() << sep - << stats.min_loss.back() << sep - << this->min_loss_v << sep - << stats.med_loss.back() << sep - << stats.med_loss_v.back() << sep - << stats.med_size.back() << sep - << stats.med_complexity.back() << sep - << stats.med_num_params.back() << sep - << stats.med_dim.back() << "\n"; - } +void Feat::log_stats(std::ofstream& log) +{ + // print stats in tabular format + string sep = ","; + if (params.current_gen == 0) // print header + { + log << "generation" << sep + << "time" << sep + << "min_loss" << sep + << "min_loss_val" << sep + << "med_loss" << sep + << "med_loss_val" << sep + << "med_size" << sep + << "med_complexity" << sep + << "med_num_params" << sep + << "min_tests_used" << sep + << "med_tests_used" << sep + << "max_tests_used" << sep + << "med_dim" << "\n"; + } + log << params.current_gen << sep + << timer.Elapsed().count() << sep + << stats.min_loss.back() << sep + << this->min_loss_v << sep + << stats.med_loss.back() << sep + << stats.med_loss_v.back() << sep + << stats.med_size.back() << sep + << stats.med_complexity.back() << sep + << stats.med_num_params.back() << sep + << stats.min_tests_used.back() << sep + << stats.med_tests_used.back() << sep + << stats.max_tests_used.back() << sep + << stats.med_dim.back() << "\n"; } + //TODO: replace these with json json Feat::get_stats() { diff --git a/src/pop/archive.cc b/src/pop/archive.cc index b33929bd2..8aba8d8ad 100755 --- a/src/pop/archive.cc +++ b/src/pop/archive.cc @@ -78,10 +78,6 @@ namespace FT{ vector tmp = pop.individuals; - #pragma omp parallel for - for (unsigned int i=0; i Date: Fri, 17 Nov 2023 17:51:06 -0500 Subject: [PATCH 7/7] Removing wrong attributes (these are from my experiment branch!) --- src/feat.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/feat.cc b/src/feat.cc index b1cf020c0..534468512 100755 --- a/src/feat.cc +++ b/src/feat.cc @@ -1548,9 +1548,6 @@ void Feat::log_stats(std::ofstream& log) << "med_size" << sep << "med_complexity" << sep << "med_num_params" << sep - << "min_tests_used" << sep - << "med_tests_used" << sep - << "max_tests_used" << sep << "med_dim" << "\n"; } log << params.current_gen << sep @@ -1562,9 +1559,6 @@ void Feat::log_stats(std::ofstream& log) << stats.med_size.back() << sep << stats.med_complexity.back() << sep << stats.med_num_params.back() << sep - << stats.min_tests_used.back() << sep - << stats.med_tests_used.back() << sep - << stats.max_tests_used.back() << sep << stats.med_dim.back() << "\n"; }