From 0806656a07b1edb5eb35eae43dd0fc1dea4bb7be Mon Sep 17 00:00:00 2001 From: Thomas Purcell <purcell@fhi-berlin.mpg.de> Date: Wed, 10 Jun 2020 14:03:56 +0200 Subject: [PATCH] Bug fixes More feature elimination steps. Clear out register when doing generation/proejction --- .../feature_space/FeatureSpace.cpp | 7 ++++--- .../node/operator_nodes/OperatorNode.hpp | 3 ++- .../allowed_operator_nodes/inverse.cpp | 4 ++-- .../node/value_storage/nodes_value_containers.hpp | 15 ++++++++------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/feature_creation/feature_space/FeatureSpace.cpp b/src/feature_creation/feature_space/FeatureSpace.cpp index 626e45df..7629a5da 100644 --- a/src/feature_creation/feature_space/FeatureSpace.cpp +++ b/src/feature_creation/feature_space/FeatureSpace.cpp @@ -324,10 +324,12 @@ std::vector<double> FeatureSpace::project_r(double* prop, int size, std::vector< void FeatureSpace::project_generated(double* prop, int size, std::vector<std::shared_ptr<FeatureNode>>& phi_sel, std::vector<double>& scores_sel, std::vector<double>& scores_comp) { - for(auto feat = _phi.begin() + _mpi_comm->rank(); feat < _phi.end(); feat += _mpi_comm->size()) + for(auto feat = _phi.begin() + _start_gen.back() + _mpi_comm->rank(); feat < _phi.end(); feat += _mpi_comm->size()) { - int feat_ind = _phi.size(); + std::fill_n(node_value_arrs::TEMP_STORAGE_REG.data(), node_value_arrs::TEMP_STORAGE_REG.size(), -1); + std::fill_n(node_value_arrs::TEMP_STORAGE_TEST_REG.data(), node_value_arrs::TEMP_STORAGE_TEST_REG.size(), -1); + int feat_ind = _phi.size(); std::vector<node_ptr> generated_phi; generate_new_feats(feat, generated_phi, feat_ind, _l_bound, _u_bound); @@ -440,7 +442,6 @@ void FeatureSpace::sis(std::vector<double>& prop) if(is_valid) { - std::cout << _phi[inds[ii]]->expr() << _scores[inds[ii]] << std::endl; scores_sel[cur_feat_local] = _scores[inds[ii]]; phi_sel.push_back(std::make_shared<FeatureNode>(cur_feat + cur_feat_local, _phi[inds[ii]]->expr(), _phi[inds[ii]]->value(), _phi[inds[ii]]->test_value(), _phi[inds[ii]]->unit(), true)); ++cur_feat_local; diff --git a/src/feature_creation/node/operator_nodes/OperatorNode.hpp b/src/feature_creation/node/operator_nodes/OperatorNode.hpp index 7e3b252b..31e91775 100644 --- a/src/feature_creation/node/operator_nodes/OperatorNode.hpp +++ b/src/feature_creation/node/operator_nodes/OperatorNode.hpp @@ -100,7 +100,8 @@ public: set_value(offset); node_value_arrs::temp_storage_reg(_arr_ind, offset) = _arr_ind; } - + // for(auto& feat: _feats) + // std::cout << *feat->value_ptr() << '\t'; return node_value_arrs::get_value_ptr(_arr_ind, offset); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.cpp index 65eea3bd..8f1dbd83 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inverse.cpp @@ -6,7 +6,7 @@ InvNode::InvNode() InvNode::InvNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, double u_bound): OperatorNode(feats, feat_ind) { - if((feats[0]->type() == NODE_TYPE::DIV) || (feats[0]->type() == NODE_TYPE::EXP) || (feats[0]->type() == NODE_TYPE::NEG_EXP)) + if((feats[0]->type() == NODE_TYPE::DIV) || (feats[0]->type() == NODE_TYPE::EXP) || (feats[0]->type() == NODE_TYPE::NEG_EXP) || (feats[0]->type() == NODE_TYPE::CB) || (feats[0]->type() == NODE_TYPE::SQ) || (feats[0]->type() == NODE_TYPE::CBRT) || (feats[0]->type() == NODE_TYPE::SQRT) || (feats[0]->type() == NODE_TYPE::SIX_POW )) throw InvalidFeatureException(); set_value(); @@ -19,7 +19,7 @@ InvNode::InvNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, do InvNode::InvNode(node_ptr feat, int feat_ind, double l_bound, double u_bound): OperatorNode({feat}, feat_ind) { - if((feat->type() == NODE_TYPE::DIV) || (feat->type() == NODE_TYPE::EXP) || (feat->type() == NODE_TYPE::NEG_EXP)) + if((feat->type() == NODE_TYPE::DIV) || (feat->type() == NODE_TYPE::EXP) || (feat->type() == NODE_TYPE::NEG_EXP) || (feat->type() == NODE_TYPE::CB) || (feat->type() == NODE_TYPE::SQ) || (feat->type() == NODE_TYPE::CBRT) || (feat->type() == NODE_TYPE::SQRT) || (feat->type() == NODE_TYPE::SIX_POW )) throw InvalidFeatureException(); set_value(); diff --git a/src/feature_creation/node/value_storage/nodes_value_containers.hpp b/src/feature_creation/node/value_storage/nodes_value_containers.hpp index c992eaa3..7918fa1b 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.hpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.hpp @@ -9,19 +9,20 @@ namespace node_value_arrs { + extern std::vector<double> TEMP_STORAGE_ARR; //!< Array to temporarily store feature values + extern std::vector<double> VALUES_ARR; //!< Value of the stored features + extern std::vector<double> TEMP_STORAGE_TEST_ARR; //!< Array to temporarily store feature values + extern std::vector<double> TEST_VALUES_ARR; //!< Value of the stored features test values + extern std::vector<double> D_MATRIX; //!< The descriptor matrix + extern std::vector<int> TEMP_STORAGE_REG; //!< Register to see which feature is stored in each slot + extern std::vector<int> TEMP_STORAGE_TEST_REG; //!< Register to see which feature is stored in each slot + extern int N_SELECTED; //!< Number of features selected extern int N_SAMPLES; //!< Number of samples in the nodes extern int N_SAMPLES_TEST; //!< Number of samples in the nodes extern int N_STORE_FEATURES; //!< Number of features with stored values extern int N_RUNGS_STORED; //!< Number of rungs with values stored - extern std::vector<int> TEMP_STORAGE_REG; //!< Register to see which feature is stored in each slot - extern std::vector<int> TEMP_STORAGE_TEST_REG; //!< Register to see which feature is stored in each slot - extern std::vector<double> D_MATRIX; //!< The descriptor matrix - extern std::vector<double> VALUES_ARR; //!< Value of the stored features - extern std::vector<double> TEST_VALUES_ARR; //!< Value of the stored features test values - extern std::vector<double> TEMP_STORAGE_ARR; //!< Array to temporarily store feature values - extern std::vector<double> TEMP_STORAGE_TEST_ARR; //!< Array to temporarily store feature values /** * @brief Get the maximum number of new features for each rung -- GitLab