From bbac673f7487c73268913d5656ae7773680c3b19 Mon Sep 17 00:00:00 2001 From: Thomas Purcell <purcell@fhi-berlin.mpg.de> Date: Tue, 9 Jun 2020 15:21:35 +0200 Subject: [PATCH] bug fixes for feature bounds --- src/descriptor_identifier/SISSORegressor.cpp | 19 +++++------ src/descriptor_identifier/SISSORegressor.hpp | 21 +++++++----- .../feature_space/FeatureSpace.cpp | 23 +++++-------- .../feature_space/FeatureSpace.hpp | 4 +-- .../absolute_difference.hpp | 4 +-- .../allowed_operator_nodes/absolute_value.hpp | 4 +-- .../allowed_operator_nodes/add.hpp | 4 +-- .../allowed_operator_nodes/cos.hpp | 4 +-- .../allowed_operator_nodes/cube.hpp | 4 +-- .../allowed_operator_nodes/cube_root.hpp | 4 +-- .../allowed_operator_nodes/divide.hpp | 4 +-- .../allowed_operator_nodes/exponential.hpp | 4 +-- .../allowed_operator_nodes/inverse.hpp | 4 +-- .../allowed_operator_nodes/log.hpp | 4 +-- .../allowed_operator_nodes/multiply.hpp | 4 +-- .../negative_exponential.hpp | 4 +-- .../allowed_operator_nodes/sin.hpp | 4 +-- .../allowed_operator_nodes/sixth_power.hpp | 4 +-- .../allowed_operator_nodes/square.hpp | 4 +-- .../allowed_operator_nodes/square_root.hpp | 4 +-- .../allowed_operator_nodes/subtract.hpp | 4 +-- .../node/operator_nodes/allowed_ops.cpp | 34 +++++++++---------- src/inputs/InputParser.cpp | 16 +++++---- src/inputs/InputParser.hpp | 23 +++++++------ 24 files changed, 105 insertions(+), 103 deletions(-) diff --git a/src/descriptor_identifier/SISSORegressor.cpp b/src/descriptor_identifier/SISSORegressor.cpp index 4db934c2..1c547dd1 100644 --- a/src/descriptor_identifier/SISSORegressor.cpp +++ b/src/descriptor_identifier/SISSORegressor.cpp @@ -1,22 +1,21 @@ #include <descriptor_identifier/SISSORegressor.hpp> SISSORegressor::SISSORegressor(std::shared_ptr<FeatureSpace> feat_space, std::vector<double> prop, std::vector<double> prop_test, int n_dim, int n_residual): + _prop(prop), + _prop_test(prop_test), + _a(new double[(n_dim + 1) * prop.size()]), + _b(new double[prop.size()]), + _ones(new double[prop.size()]), + _error(new double[prop.size()]), + _work(nullptr), + _s(new double[n_dim + 1]), _feat_space(feat_space), _mpi_comm(feat_space->mpi_comm()), _n_samp(prop.size()), _n_dim(n_dim), _n_residual(n_residual), _lwork(-1), - _rank(0), - _a(new double[(_n_dim + 1) * _n_samp]), - _b(new double[_n_samp]), - _ones(new double[_n_samp]), - _error(new double[_n_samp]), - _work(nullptr), - _s(new double[n_dim + 1]), - _models(), - _prop(prop), - _prop_test(prop_test) + _rank(0) { // Initialize a, b, ones, s, and _error arrays diff --git a/src/descriptor_identifier/SISSORegressor.hpp b/src/descriptor_identifier/SISSORegressor.hpp index ab4e7e68..02d1af20 100644 --- a/src/descriptor_identifier/SISSORegressor.hpp +++ b/src/descriptor_identifier/SISSORegressor.hpp @@ -12,6 +12,18 @@ class SISSORegressor { protected: + std::vector<std::vector<Model>> _models; //!< List of models + + std::vector<double> _prop; //!< Property array + std::vector<double> _prop_test; //!< Property array + + std::unique_ptr<double[]> _a; //!< A matrix for least squares + std::unique_ptr<double[]> _b; //!< Solution array for least squares + std::unique_ptr<double[]> _ones; //!< Array of ones to copy over for least squares comparison + std::unique_ptr<double[]> _error; //!< Array to calculate the residuals for the models + std::unique_ptr<double[]> _work; //!< The work array for least squares problems + std::unique_ptr<double[]> _s; //!< The S array for least squares problems + std::shared_ptr<FeatureSpace> _feat_space; //!< Feature Space for the problem std::shared_ptr<MPI_Interface> _mpi_comm; //!< MPI Communicator @@ -21,16 +33,7 @@ protected: int _lwork; //!< size of the work array int _rank; //!< Ranks for the least squares problem - std::unique_ptr<double[]> _a; //!< A matrix for least squares - std::unique_ptr<double[]> _b; //!< Solution array for least squares - std::unique_ptr<double[]> _ones; //!< Array of ones to copy over for least squares comparison - std::unique_ptr<double[]> _error; //!< Array to calculate the residuals for the models - std::unique_ptr<double[]> _work; //!< The work array for least squares problems - std::unique_ptr<double[]> _s; //!< The S array for least squares problems - std::vector<std::vector<Model>> _models; //!< List of models - std::vector<double> _prop; //!< Property array - std::vector<double> _prop_test; //!< Property array public: /** diff --git a/src/feature_creation/feature_space/FeatureSpace.cpp b/src/feature_creation/feature_space/FeatureSpace.cpp index e27a8bd3..38e8e96a 100644 --- a/src/feature_creation/feature_space/FeatureSpace.cpp +++ b/src/feature_creation/feature_space/FeatureSpace.cpp @@ -25,8 +25,8 @@ FeatureSpace::FeatureSpace( int max_phi, int n_sis_select, int max_store_rung, - double max_abs_feat_val, - double min_abs_feat_val + double min_abs_feat_val, + double max_abs_feat_val ): _phi(phi_0), _phi_0(phi_0), @@ -386,12 +386,9 @@ void FeatureSpace::sis(std::vector<double>& prop) int unique_scores = 1; if(_mpi_comm->rank() == 0) { - std::vector<mpi::request> reqs(_mpi_comm->size()-1); std::copy_n(scores_selected.data(), _n_sis_select, sent_scores.data()); for(int rr = 1; rr < _mpi_comm->size(); ++rr) - reqs[rr - 1] = _mpi_comm->irecv(rr, _mpi_comm->cantorTagGen(rr, 0, 1, 0), &sent_scores[rr * _n_sis_select], _n_sis_select); - - mpi::wait_all(reqs.begin(), reqs.end()); + _mpi_comm->recv(rr, _mpi_comm->cantorTagGen(rr, 0, 1, 0), &sent_scores[rr * _n_sis_select], _n_sis_select); // Sort the scores and see how many features we need to guarantee we get n_sis unique features inds = util_funcs::argsort(sent_scores); @@ -408,7 +405,7 @@ void FeatureSpace::sis(std::vector<double>& prop) } else { - _mpi_comm->isend(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 1, 0), scores_selected.data(), _n_sis_select); + _mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 1, 0), scores_selected.data(), _n_sis_select); inds = {}; } mpi::broadcast(*_mpi_comm, inds, 0); @@ -435,14 +432,12 @@ void FeatureSpace::sis(std::vector<double>& prop) std::copy_n(scores_selected.begin(), _n_sis_select, sent_scores.begin()); std::copy_n(phi_selected.begin(), _n_sis_select, sent_phi.begin()); - std::vector<mpi::request> reqs(2 * (_mpi_comm->size()-1)); for(int rr = 1; rr < _mpi_comm->size(); ++rr) { - reqs[2*(rr - 1)] = _mpi_comm->irecv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 0), &sent_scores[rr * _n_sis_select], _n_sis_select); - reqs[2*(rr - 1)+1] = _mpi_comm->irecv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 1), &sent_phi[rr * _n_sis_select], _n_sis_select); + _mpi_comm->recv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 0), &sent_scores[rr * _n_sis_select], _n_sis_select); + _mpi_comm->recv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 1), &sent_phi[rr * _n_sis_select], _n_sis_select); } - mpi::wait_all(reqs.begin(), reqs.end()); if(inds.size() == unique_scores) { inds = util_funcs::argsort(sent_scores); @@ -488,14 +483,14 @@ void FeatureSpace::sis(std::vector<double>& prop) ++ii; } } - if(cur_feat_local != _n_sis_select) + if(_phi_selected.size() != node_value_arrs::N_SELECTED) throw std::logic_error("SIS went through all features and did not select enough."); cur_feat -= cur_feat_local; } else { - _mpi_comm->isend(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 0), scores_selected.data(), _n_sis_select); - _mpi_comm->isend(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 1), phi_selected.data(), _n_sis_select); + _mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 0), scores_selected.data(), _n_sis_select); + _mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 1), phi_selected.data(), _n_sis_select); _phi_selected.resize(node_value_arrs::N_SELECTED); } mpi::broadcast(*_mpi_comm, &_phi_selected[_phi_selected.size() - _n_sis_select], _n_sis_select, 0); diff --git a/src/feature_creation/feature_space/FeatureSpace.hpp b/src/feature_creation/feature_space/FeatureSpace.hpp index 33ce9d29..de7f41a9 100644 --- a/src/feature_creation/feature_space/FeatureSpace.hpp +++ b/src/feature_creation/feature_space/FeatureSpace.hpp @@ -62,8 +62,8 @@ public: int max_phi=1, int n_sis_select=1, int max_store_rung=2, - double max_abs_feat_val=1e50, - double min_abs_feat_val=1e-50 + double min_abs_feat_val=1e-50, + double max_abs_feat_val=1e50 ); /** diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_difference.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_difference.hpp index ef1c8af6..0aca9016 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_difference.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_difference.hpp @@ -16,9 +16,9 @@ class AbsDiffNode: public OperatorNode<2> public: AbsDiffNode(); - AbsDiffNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + AbsDiffNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound); - AbsDiffNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + AbsDiffNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_value.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_value.hpp index dee59b37..c42265ca 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_value.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/absolute_value.hpp @@ -15,9 +15,9 @@ class AbsNode: public OperatorNode<1> public: AbsNode(); - AbsNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + AbsNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - AbsNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + AbsNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add.hpp index 4cb33729..b2579b81 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add.hpp @@ -15,9 +15,9 @@ class AddNode: public OperatorNode<2> public: AddNode(); - AddNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + AddNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound); - AddNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + AddNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos.hpp index 28824afa..c006a46b 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos.hpp @@ -15,9 +15,9 @@ class CosNode: public OperatorNode<1> public: CosNode(); - CosNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + CosNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - CosNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + CosNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return Unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube.hpp index 50e33677..3d7eac11 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube.hpp @@ -15,9 +15,9 @@ class CbNode: public OperatorNode<1> public: CbNode(); - CbNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + CbNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - CbNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + CbNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit()^(3.0);} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.hpp index 0d34ae51..1509726f 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.hpp @@ -15,9 +15,9 @@ class CbrtNode: public OperatorNode<1> public: CbrtNode(); - CbrtNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + CbrtNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - CbrtNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + CbrtNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit()^(1.0 / 3.0);} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/divide.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/divide.hpp index 24395909..7b6e07d7 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/divide.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/divide.hpp @@ -15,9 +15,9 @@ class DivNode: public OperatorNode<2> public: DivNode(); - DivNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + DivNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound); - DivNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + DivNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit() / _feats[1]->unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exponential.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exponential.hpp index 61e3d720..7870d772 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exponential.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exponential.hpp @@ -15,9 +15,9 @@ class ExpNode: public OperatorNode<1> public: ExpNode(); - ExpNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + ExpNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - ExpNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + ExpNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return Unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.hpp index 197835b9..384fff3d 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.hpp @@ -16,9 +16,9 @@ class InvNode: public OperatorNode<1> public: InvNode(); - InvNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + InvNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - InvNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + InvNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit() ^ (-1.0);} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log.hpp index 2359c07a..11f0e846 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log.hpp @@ -15,9 +15,9 @@ class LogNode: public OperatorNode<1> public: LogNode(); - LogNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + LogNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - LogNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + LogNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return Unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/multiply.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/multiply.hpp index a6a7a841..58e8df98 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/multiply.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/multiply.hpp @@ -16,9 +16,9 @@ class MultNode: public OperatorNode<2> public: MultNode(); - MultNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + MultNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound); - MultNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + MultNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit() * _feats[1]->unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/negative_exponential.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/negative_exponential.hpp index de6ba660..2b509ade 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/negative_exponential.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/negative_exponential.hpp @@ -16,9 +16,9 @@ class NegExpNode: public OperatorNode<1> public: NegExpNode(); - NegExpNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + NegExpNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - NegExpNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + NegExpNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return Unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin.hpp index 3e3ff105..4654cc38 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin.hpp @@ -16,9 +16,9 @@ class SinNode: public OperatorNode<1> public: SinNode(); - SinNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SinNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - SinNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SinNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return Unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.hpp index 0dae9c87..8329bae7 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.hpp @@ -16,9 +16,9 @@ class SixPowNode: public OperatorNode<1> public: SixPowNode(); - SixPowNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SixPowNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - SixPowNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SixPowNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit()^(6.0);} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square.hpp index 1836c609..449c6b48 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square.hpp @@ -15,9 +15,9 @@ class SqNode: public OperatorNode<1> public: SqNode(); - SqNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SqNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - SqNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SqNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit()^(2.0);} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.hpp index b701f53d..1cfbe8ce 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.hpp @@ -16,9 +16,9 @@ class SqrtNode: public OperatorNode<1> public: SqrtNode(); - SqrtNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SqrtNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound); - SqrtNode(node_ptr feat, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SqrtNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit()^(0.5);} diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/subtract.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/subtract.hpp index 6dd01afe..0ea056ca 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/subtract.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/subtract.hpp @@ -16,9 +16,9 @@ class SubNode: public OperatorNode<2> public: SubNode(); - SubNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SubNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound); - SubNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound = 1e-50, double u_bound = 1e50); + SubNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound); inline Unit unit(){return _feats[0]->unit();} diff --git a/src/feature_creation/node/operator_nodes/allowed_ops.cpp b/src/feature_creation/node/operator_nodes/allowed_ops.cpp index 21da62c1..f93bd046 100644 --- a/src/feature_creation/node/operator_nodes/allowed_ops.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_ops.cpp @@ -5,22 +5,22 @@ std::map<std::string, bin_op_node_gen> allowed_op_maps::binary_operator_map; void allowed_op_maps::set_node_maps() { - allowed_op_maps::binary_operator_map["add"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<AddNode>(f1, f2, rung, feat_ind);}; - allowed_op_maps::binary_operator_map["sub"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SubNode>(f1, f2, rung, feat_ind);};; - allowed_op_maps::binary_operator_map["abs_diff"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<AbsDiffNode>(f1, f2, rung, feat_ind);};; - allowed_op_maps::binary_operator_map["mult"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<MultNode>(f1, f2, rung, feat_ind);};; - allowed_op_maps::binary_operator_map["div"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<DivNode>(f1, f2, rung, feat_ind);};; + allowed_op_maps::binary_operator_map["add"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<AddNode>(f1, f2, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::binary_operator_map["sub"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SubNode>(f1, f2, rung, feat_ind, l_bound, u_bound);};; + allowed_op_maps::binary_operator_map["abs_diff"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<AbsDiffNode>(f1, f2, rung, feat_ind, l_bound, u_bound);};; + allowed_op_maps::binary_operator_map["mult"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<MultNode>(f1, f2, rung, feat_ind, l_bound, u_bound);};; + allowed_op_maps::binary_operator_map["div"] = [](node_ptr f1, node_ptr f2, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<DivNode>(f1, f2, rung, feat_ind, l_bound, u_bound);};; - allowed_op_maps::unary_operator_map["exp"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<ExpNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["neg_exp"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<NegExpNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["inv"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<InvNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["sq"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SqNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["cb"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<CbNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["six_pow"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SixPowNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["sqrt"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SqrtNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["cbrt"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<CbrtNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["log"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<LogNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["abs"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<AbsNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["sin"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SinNode>(f1, rung, feat_ind);}; - allowed_op_maps::unary_operator_map["cos"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<CosNode>(f1, rung, feat_ind);}; + allowed_op_maps::unary_operator_map["exp"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<ExpNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["neg_exp"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<NegExpNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["inv"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<InvNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["sq"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SqNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["cb"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<CbNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["six_pow"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SixPowNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["sqrt"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SqrtNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["cbrt"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<CbrtNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["log"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<LogNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["abs"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<AbsNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["sin"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<SinNode>(f1, rung, feat_ind, l_bound, u_bound);}; + allowed_op_maps::unary_operator_map["cos"] = [](node_ptr f1, int rung, int feat_ind, double l_bound, double u_bound){return std::make_shared<CosNode>(f1, rung, feat_ind, l_bound, u_bound);}; } diff --git a/src/inputs/InputParser.cpp b/src/inputs/InputParser.cpp index 16f6cbd6..58063aad 100644 --- a/src/inputs/InputParser.cpp +++ b/src/inputs/InputParser.cpp @@ -1,17 +1,19 @@ #include <inputs/InputParser.hpp> InputParser::InputParser(boost::property_tree::ptree IP, std::string fn, std::shared_ptr<MPI_Interface> comm) : + _opset(as_vector<std::string>(IP, "opset")), + _leave_out_inds(as_vector<int>(IP, "leave_out_inds")), + _filename(fn), + _data_file(IP.get<std::string>("data_file", "data.csv")), + _prop_key(IP.get<std::string>("property_key", "prop")), + _l_bound(IP.get<double>("min_abs_feat_val", 1e-50)), + _u_bound(IP.get<double>("max_abs_feat_val", 1e50)), _n_dim(IP.get<int>("desc_dim")), _n_sis_select(IP.get<int>("_n_sis_select")), _max_rung(IP.get<int>("max_rung")), _max_store_rung(IP.get<int>("n_rung_store", _max_rung - 1)), _n_samp(-1), - _n_residuals(IP.get<int>("n_residual", 1)), - _filename(fn), - _data_file(IP.get<std::string>("data_file", "data.csv")), - _prop_key(IP.get<std::string>("property_key", "prop")), - _leave_out_inds(as_vector<int>(IP, "leave_out_inds")), - _opset(as_vector<std::string>(IP, "opset")) + _n_residuals(IP.get<int>("n_residual", 1)) { std::ifstream data_stream; @@ -177,7 +179,7 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm) for(int ff = 0; ff < headers.size(); ++ff) phi_0.push_back(std::make_shared<FeatureNode>(ff, headers[ff], data[ff], test_data[ff], units[ff])); - _feat_space = std::make_shared<FeatureSpace>(comm, phi_0, _opset, _max_rung, _n_sis_select, _max_store_rung); + _feat_space = std::make_shared<FeatureSpace>(comm, phi_0, _opset, _max_rung, _n_sis_select, _max_store_rung, _l_bound, _u_bound); } void stripComments(std::string& filename) diff --git a/src/inputs/InputParser.hpp b/src/inputs/InputParser.hpp index e0ec8b10..a3801fac 100644 --- a/src/inputs/InputParser.hpp +++ b/src/inputs/InputParser.hpp @@ -25,7 +25,20 @@ class InputParser { public: + std::vector<std::string> _opset; + std::vector<double> _prop_train; + std::vector<double> _prop_test; + std::vector<int> _leave_out_inds; + + std::string _filename; + std::string _data_file; + std::string _prop_key; + std::shared_ptr<FeatureSpace> _feat_space; + + double _l_bound; + double _u_bound; + int _n_dim; int _max_rung; int _max_store_rung; @@ -34,16 +47,6 @@ public: int _n_residuals; int _n_leave_out; - std::string _filename; - std::string _data_file; - std::string _prop_key; - - std::vector<int> _leave_out_inds; - std::vector<double> _prop_train; - std::vector<double> _prop_test; - std::vector<std::string> _opset; - - InputParser(boost::property_tree::ptree IP, std::string fn, std::shared_ptr<MPI_Interface> comm); inline std::shared_ptr<FeatureSpace> feat_space(){return _feat_space;} void generate_feature_space(std::shared_ptr<MPI_Interface> comm); -- GitLab