From b0162a2be49bcf827a8f116448293360e38694eb Mon Sep 17 00:00:00 2001 From: Thomas Purcell <purcell@fhi-berlin.mpg.de> Date: Sat, 27 Jun 2020 22:39:19 +0200 Subject: [PATCH] Bug Fix There were errors with temp_storage_reg and setting selected feature values --- src/descriptor_identifier/SISSORegressor.cpp | 2 +- .../feature_space/FeatureSpace.cpp | 81 +++++++++---------- src/feature_creation/node/FeatureNode.hpp | 2 +- src/feature_creation/node/Node.hpp | 2 +- .../node/operator_nodes/OperatorNode.hpp | 10 +-- .../absolute_difference.hpp | 2 +- .../allowed_operator_nodes/absolute_value.hpp | 2 +- .../allowed_operator_nodes/add.hpp | 2 +- .../allowed_operator_nodes/cos.hpp | 2 +- .../allowed_operator_nodes/cube.hpp | 2 +- .../allowed_operator_nodes/cube_root.cpp | 4 +- .../allowed_operator_nodes/cube_root.hpp | 2 +- .../allowed_operator_nodes/divide.hpp | 2 +- .../allowed_operator_nodes/exponential.hpp | 2 +- .../allowed_operator_nodes/inverse.hpp | 2 +- .../allowed_operator_nodes/log.hpp | 2 +- .../allowed_operator_nodes/multiply.hpp | 2 +- .../negative_exponential.hpp | 2 +- .../allowed_operator_nodes/sin.hpp | 2 +- .../allowed_operator_nodes/sixth_power.cpp | 4 +- .../allowed_operator_nodes/sixth_power.hpp | 2 +- .../allowed_operator_nodes/square.hpp | 2 +- .../allowed_operator_nodes/square_root.cpp | 4 +- .../allowed_operator_nodes/square_root.hpp | 2 +- .../allowed_operator_nodes/subtract.hpp | 2 +- .../value_storage/nodes_value_containers.cpp | 20 ++--- .../value_storage/nodes_value_containers.hpp | 7 +- 27 files changed, 86 insertions(+), 84 deletions(-) diff --git a/src/descriptor_identifier/SISSORegressor.cpp b/src/descriptor_identifier/SISSORegressor.cpp index c4cde777..2fb93748 100644 --- a/src/descriptor_identifier/SISSORegressor.cpp +++ b/src/descriptor_identifier/SISSORegressor.cpp @@ -56,7 +56,7 @@ void SISSORegressor::least_squares(std::vector<int>& inds, double* coeffs, int s std::copy_n(_b.get(), n_dim, coeffs); else { - std::string err_msg = "least_squares failed, " + std::to_string(info); + std::string err_msg = "least_squares failed, " + std::to_string(info) + ", on rank: " + std::to_string(_mpi_comm->rank()); for(auto& ind : inds) err_msg += ", " + std::to_string(ind) + ": " + std::to_string(node_value_arrs::get_d_matrix_ptr(ind)[0]); throw std::logic_error(err_msg); diff --git a/src/feature_creation/feature_space/FeatureSpace.cpp b/src/feature_creation/feature_space/FeatureSpace.cpp index a4d5f340..c5a3ab37 100644 --- a/src/feature_creation/feature_space/FeatureSpace.cpp +++ b/src/feature_creation/feature_space/FeatureSpace.cpp @@ -146,12 +146,12 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop) _n_feat = _phi.size(); int feat_ind = _phi.size(); - for(auto feat_1 = _phi.begin() + _mpi_comm->rank(); feat_1 < _phi.end(); feat_1 += _mpi_comm->size()) + for(auto feat_1 = _phi.begin() + _mpi_comm->rank() + _start_gen.back(); feat_1 < _phi.end(); feat_1 += _mpi_comm->size()) generate_new_feats(feat_1, next_phi, feat_ind, l_bound, u_bound); - _mpi_comm->barrier(); _start_gen.push_back(_phi.size()); - if((nn < _max_phi) || (_mpi_comm->size() == 1)) + + if((nn < _max_phi) || (nn <= _n_rung_store) || (_mpi_comm->size() == 1)) { std::vector<std::vector<node_ptr>> next_phi_gathered; mpi::all_gather(*_mpi_comm, next_phi, next_phi_gathered); @@ -168,9 +168,10 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop) } } + node_value_arrs::clear_temp_reg(); if(nn < _max_phi) { - 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_REG.data(), node_value_arrs::TEMP_STORAGE_REG.size(), -1); // Remove identical features _scores.resize(_phi.size()); @@ -181,14 +182,13 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop) std::vector<int> del_inds; + _mpi_comm->barrier(); + + for(int sc = 0; sc < _scores.size() - 1; ++sc) - { - if(_scores[inds[sc]] - _scores[inds[sc + 1]] < 1e-10) - { - if(1.0 - std::abs(util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(), _phi[_start_gen.back() + inds[sc + 1]]->value_ptr(), _n_samp)) < 1e-13) + if(_scores[inds[sc + 1]] - _scores[inds[sc]] < 1e-10) + if(std::abs(util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(), _phi[_start_gen.back() + inds[sc]]->value_ptr(), _n_samp) - util_funcs::r(_phi[_start_gen.back() + inds[sc]]->value_ptr(), _phi[_start_gen.back() + inds[sc + 1]]->value_ptr(), _n_samp)) < 1e-13) del_inds.push_back(-1 * (inds[sc] + _start_gen.back())); - } - } inds = util_funcs::argsort(del_inds); for(int ii = 0; ii < inds.size(); ++ii) @@ -327,6 +327,7 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop) } } } + _n_feat = _phi.size(); } @@ -344,8 +345,8 @@ void FeatureSpace::project_generated(double* prop, int size, std::vector<node_pt for(auto feat = _phi.begin() + _start_gen.back() + _mpi_comm->rank(); feat < _phi.end(); feat += _mpi_comm->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); + node_value_arrs::clear_temp_reg(); + node_value_arrs::clear_temp_test_reg(); int feat_ind = _phi.size(); std::vector<node_ptr> generated_phi; @@ -407,7 +408,7 @@ bool FeatureSpace::valid_score_against_past(double* val_ptr, double cur_score, s if(*std::min_element(scores_comp.begin(), scores_comp.end()) < 1e-10) { int dd = std::min_element(scores_comp.begin(), scores_comp.end()) - scores_comp.begin(); - if(1.0 - std::abs(util_funcs::r(node_value_arrs::get_d_matrix_ptr(dd), val_ptr, _n_samp)) < 1e-13) + if(std::abs(util_funcs::r(val_ptr, val_ptr, _n_samp) - util_funcs::r(node_value_arrs::get_d_matrix_ptr(dd), val_ptr, _n_samp)) < 1e-10) return false; } return true; @@ -420,14 +421,25 @@ bool FeatureSpace::valid_score_against_current(int end_check, double* val_ptr, d if(*std::min_element(scores_comp.begin(), scores_comp.begin() + end_check) < 1e-10) { int dd = std::min_element(scores_comp.begin(), scores_comp.begin() + end_check) - scores_comp.begin(); - if(1.0 - std::abs(util_funcs::r(node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd), val_ptr, _n_samp)) < 1e-13) + if(std::abs(util_funcs::r(val_ptr, val_ptr, _n_samp) - util_funcs::r(node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd), val_ptr, _n_samp)) < 1e-10) return false; + else + { + std::vector<double> test(_n_samp); + std::transform(val_ptr, val_ptr + _n_samp, node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd), test.data(), std::minus<double>()); + std::cout << std::setw(24) << std::setprecision(20) << *std::min_element(test.begin(), test.end()) << '\t' << *std::max_element(test.begin(), test.end()) << std::endl; + std::cout << std::setw(24) << std::setprecision(20) << *val_ptr << *node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd) << std::endl; + std::cout << std::setw(24) << std::setprecision(20) << std::abs(util_funcs::r(val_ptr, val_ptr, _n_samp) - util_funcs::r(node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd), val_ptr, _n_samp)) << std::endl; + } } return true; } void FeatureSpace::sis(std::vector<double>& prop) { + // 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); + std::vector<double> scores_comp(std::max(node_value_arrs::N_SELECTED, _n_sis_select), 1.0); std::vector<double> scores_sel(_n_sis_select, 0.0); @@ -481,7 +493,7 @@ void FeatureSpace::sis(std::vector<double>& prop) phi_sel.resize(cur_feat_local); scores_sel.resize(cur_feat_local); project_generated(prop.data(), prop.size(), phi_sel, scores_sel, scores_comp); - std::fill_n(node_value_arrs::TEMP_STORAGE_TEST_REG.data(), node_value_arrs::TEMP_STORAGE_TEST_REG.size(), -1); + // std::fill_n(node_value_arrs::TEMP_STORAGE_TEST_REG.data(), node_value_arrs::TEMP_STORAGE_TEST_REG.size(), -1); } @@ -534,10 +546,15 @@ void FeatureSpace::sis(std::vector<double>& prop) if(std::none_of(inds.begin(), inds.end(), [&compare_ind](int i1){return i1 == compare_ind;})) { scores_sel.erase(scores_sel.begin() + ii); - phi_sel.back()->selected() = false; - phi_sel.back()->set_dmat_ind(-1); + phi_sel[ii]->selected() = false; + phi_sel[ii]->set_dmat_ind(-1); phi_sel.erase(phi_sel.begin() + ii); } + else + { + phi_sel[ii]->selected() = false; + phi_sel[ii]->set_dmat_ind(-1); + } } for(auto& feat : phi_sel) feat->selected() = false; @@ -560,6 +577,7 @@ void FeatureSpace::sis(std::vector<double>& prop) _mpi_comm->recv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 1), &sent_phi[rr * _n_sis_select], _n_sis_select); } + // std::fill_n(node_value_arrs::TEMP_STORAGE_REG.data(), node_value_arrs::TEMP_STORAGE_REG.size(), -1); if(inds.size() == unique_scores) { inds = util_funcs::argsort(sent_scores); @@ -600,20 +618,6 @@ void FeatureSpace::sis(std::vector<double>& prop) ++cur_feat_local; ++cur_feat; } - else - { - sent_phi[inds[ii]]->selected() = false; - sent_phi[inds[ii]]->set_dmat_ind(-1); - } - ++ii; - } - while(ii < sent_phi.size()) - { - if(sent_phi[inds[ii]]) - { - sent_phi[inds[ii]]->selected() = false; - sent_phi[inds[ii]]->set_dmat_ind(-1); - } ++ii; } } @@ -626,19 +630,14 @@ void FeatureSpace::sis(std::vector<double>& prop) _mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 0), scores_sel.data(), _n_sis_select); _mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 1), phi_sel.data(), _n_sis_select); _phi_selected.resize(node_value_arrs::N_SELECTED); - for(auto& feat : phi_sel) - { - if(feat) - { - feat->selected() = false; - feat->set_dmat_ind(-1); - } - } } mpi::broadcast(*_mpi_comm, &_phi_selected[_phi_selected.size() - _n_sis_select], _n_sis_select, 0); - for(int ii = _phi_selected.size() - _n_sis_select; ii < _phi_selected.size(); ++ii) + std::vector<int> rungs(_n_sis_select, 0); + std::transform(_phi_selected.end() - _n_sis_select, _phi_selected.end(), rungs.begin(), [](node_ptr feat){return feat->rung();}); + inds = util_funcs::argsort(rungs); + for(int ii = 0; ii < inds.size(); ++ii) { - _phi_selected[ii]->set_value(); + _phi_selected[inds[ii] + node_value_arrs::N_SELECTED - _n_sis_select]->set_value(); ++cur_feat; } } diff --git a/src/feature_creation/node/FeatureNode.hpp b/src/feature_creation/node/FeatureNode.hpp index 5c55766d..4f7bef88 100644 --- a/src/feature_creation/node/FeatureNode.hpp +++ b/src/feature_creation/node/FeatureNode.hpp @@ -117,7 +117,7 @@ public: /** * @brief Accessor function to the value of the feature */ - inline double* value_ptr(int offset = 0){return _selected ? node_value_arrs::get_d_matrix_ptr(_d_mat_ind) : node_value_arrs::get_value_ptr(_arr_ind, offset);} + inline double* value_ptr(int offset = 0){return _selected ? node_value_arrs::get_d_matrix_ptr(_d_mat_ind) : node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset);} /** * @brief Accessor function to the value of the feature's test set diff --git a/src/feature_creation/node/Node.hpp b/src/feature_creation/node/Node.hpp index 4062d52f..5e28fa08 100644 --- a/src/feature_creation/node/Node.hpp +++ b/src/feature_creation/node/Node.hpp @@ -151,7 +151,7 @@ public: /** * @brief Accessor function to the test value of the feature */ - virtual double* test_value_ptr(int offset = 0) = 0; + virtual double* test_value_ptr(int offset = -1) = 0; /** * @brief Check if the feature contains NaN diff --git a/src/feature_creation/node/operator_nodes/OperatorNode.hpp b/src/feature_creation/node/operator_nodes/OperatorNode.hpp index 368ee562..6e358cea 100644 --- a/src/feature_creation/node/operator_nodes/OperatorNode.hpp +++ b/src/feature_creation/node/operator_nodes/OperatorNode.hpp @@ -98,12 +98,12 @@ public: return node_value_arrs::get_d_matrix_ptr(_d_mat_ind); offset = (offset == -1) ? rung() : offset; - if((rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_arr_ind, offset) != _arr_ind)) + if((rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_arr_ind, offset) != _feat_ind)) { set_value(offset); - node_value_arrs::temp_storage_reg(_arr_ind, offset) = _arr_ind; + node_value_arrs::temp_storage_reg(_arr_ind, offset) = _feat_ind; } - return node_value_arrs::get_value_ptr(_arr_ind, offset); + return node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset); } /** @@ -117,10 +117,10 @@ public: double* test_value_ptr(int offset=-1) { offset = (offset == -1) ? rung() : offset; - if((rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_test_reg(_arr_ind, offset) != _arr_ind)) + if((rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_test_reg(_arr_ind, offset) != _feat_ind)) { set_test_value(offset); - node_value_arrs::temp_storage_test_reg(_arr_ind, offset) = _arr_ind; + // node_value_arrs::temp_storage_test_reg(_arr_ind, offset) = _feat_ind; } return node_value_arrs::get_test_value_ptr(_arr_ind, offset); 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 2cd40b66..994e8029 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 @@ -30,7 +30,7 @@ public: allowed_op_funcs::abs_diff(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::abs_diff(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::abs_diff(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 dcbeb7bf..44d7fc2a 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::abs(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::abs(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::abs(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 a36acfac..f00fe1c4 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::add(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::add(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::add(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 d8227784..b40670a9 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::cos(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::cos(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::cos(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 10e5057b..5dd0071b 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::cb(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::cb(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::cb(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.cpp index 7cf21d64..47f4daff 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cube_root.cpp @@ -6,7 +6,7 @@ CbrtNode::CbrtNode() CbrtNode::CbrtNode(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::CB) || (feats[0]->type() == NODE_TYPE::SQ) || (feats[0]->type() == NODE_TYPE::INV)) + if((feats[0]->type() == NODE_TYPE::CB) || (feats[0]->type() == NODE_TYPE::SQ) || (feats[0]->type() == NODE_TYPE::SIX_POW) || (feats[0]->type() == NODE_TYPE::INV)) throw InvalidFeatureException(); set_value(); @@ -19,7 +19,7 @@ CbrtNode::CbrtNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, CbrtNode::CbrtNode(node_ptr feat, int feat_ind, double l_bound, double u_bound): OperatorNode({feat}, feat_ind) { - if((feat->type() == NODE_TYPE::CB) || (feat->type() == NODE_TYPE::SQ) || (feat->type() == NODE_TYPE::INV)) + if((feat->type() == NODE_TYPE::CB) || (feat->type() == NODE_TYPE::SQ) || (feat->type() == NODE_TYPE::SIX_POW) || (feat->type() == NODE_TYPE::INV)) throw InvalidFeatureException(); set_value(); 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 56cdf525..5c2c636e 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::cbrt(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::cbrt(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::cbrt(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 9eb404cc..769a1739 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::div(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::div(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::div(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 58743210..138dde14 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::exp(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::exp(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::exp(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 849a6d8c..bc942c01 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 @@ -30,7 +30,7 @@ public: allowed_op_funcs::inv(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::inv(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::inv(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 5aa2598f..81b97ba7 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::log(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::log(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::log(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 28280c74..a937ca35 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 @@ -30,7 +30,7 @@ public: allowed_op_funcs::mult(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::mult(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::mult(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 04a8cbff..81f622c0 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 @@ -30,7 +30,7 @@ public: allowed_op_funcs::neg_exp(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::neg_exp(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::neg_exp(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); }; inline void set_test_value(int offset = -1) 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 8c27f117..1463ef34 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 @@ -30,7 +30,7 @@ public: allowed_op_funcs::sin(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::sin(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::sin(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.cpp index 31c8b2fe..2e67b4b7 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sixth_power.cpp @@ -6,7 +6,7 @@ SixPowNode::SixPowNode() SixPowNode::SixPowNode(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::CBRT) || (feats[0]->type() == NODE_TYPE::SQRT) || (feats[0]->type() == NODE_TYPE::INV)) + if((feats[0]->type() == NODE_TYPE::CBRT) || (feats[0]->type() == NODE_TYPE::SQRT) || (feats[0]->type() == NODE_TYPE::SQ) || (feats[0]->type() == NODE_TYPE::CB) || (feats[0]->type() == NODE_TYPE::INV)) throw InvalidFeatureException(); set_value(); @@ -19,7 +19,7 @@ SixPowNode::SixPowNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bou SixPowNode::SixPowNode(node_ptr feat, int feat_ind, double l_bound, double u_bound): OperatorNode({feat}, feat_ind) { - if((feat->type() == NODE_TYPE::CBRT) || (feat->type() == NODE_TYPE::SQRT) || (feat->type() == NODE_TYPE::INV)) + if((feat->type() == NODE_TYPE::CBRT) || (feat->type() == NODE_TYPE::SQRT) || (feat->type() == NODE_TYPE::SQ) || (feat->type() == NODE_TYPE::CB) || (feat->type() == NODE_TYPE::INV)) throw InvalidFeatureException(); set_value(); 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 a5fb6a38..770af9f9 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 @@ -30,7 +30,7 @@ public: allowed_op_funcs::sixth_pow(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::sixth_pow(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::sixth_pow(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 a8d28729..7c46c86d 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 @@ -29,7 +29,7 @@ public: allowed_op_funcs::sq(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::sq(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::sq(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.cpp index 951f55ec..ea54c2cd 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/square_root.cpp @@ -6,7 +6,7 @@ SqrtNode::SqrtNode() SqrtNode::SqrtNode(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::SQ) || (feats[0]->type() == NODE_TYPE::CB) || (feats[0]->type() == NODE_TYPE::CBRT) || (feats[0]->type() == NODE_TYPE::INV)) + if((feats[0]->type() == NODE_TYPE::SQ) || (feats[0]->type() == NODE_TYPE::CB) || (feats[0]->type() == NODE_TYPE::SIX_POW) || (feats[0]->type() == NODE_TYPE::CBRT) || (feats[0]->type() == NODE_TYPE::INV)) throw InvalidFeatureException(); set_value(); @@ -19,7 +19,7 @@ SqrtNode::SqrtNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, SqrtNode::SqrtNode(node_ptr feat, int feat_ind, double l_bound, double u_bound): OperatorNode({feat}, feat_ind) { - if((feat->type() == NODE_TYPE::SQ) || (feat->type() == NODE_TYPE::CB) || (feat->type() == NODE_TYPE::CBRT) || (feat->type() == NODE_TYPE::INV)) + if((feat->type() == NODE_TYPE::SQ) || (feat->type() == NODE_TYPE::CB) || (feat->type() == NODE_TYPE::SIX_POW) || (feat->type() == NODE_TYPE::CBRT) || (feat->type() == NODE_TYPE::INV)) throw InvalidFeatureException(); set_value(); 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 a3082257..3f327423 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 @@ -30,7 +30,7 @@ public: allowed_op_funcs::sqrt(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::sqrt(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::sqrt(_n_samp, _feats[0]->value_ptr(offset + 2), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) 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 f49d4c06..40b87a26 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 @@ -30,7 +30,7 @@ public: allowed_op_funcs::sub(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_d_matrix_ptr(_d_mat_ind)); offset = (offset == -1) ? rung() : offset; - allowed_op_funcs::sub(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, offset)); + allowed_op_funcs::sub(_n_samp, _feats[0]->value_ptr(offset + 2), _feats[1]->value_ptr(offset + 1), node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, offset)); } inline void set_test_value(int offset = -1) diff --git a/src/feature_creation/node/value_storage/nodes_value_containers.cpp b/src/feature_creation/node/value_storage/nodes_value_containers.cpp index 6ab863bb..11664d6b 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.cpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.cpp @@ -105,20 +105,20 @@ void node_value_arrs::resize_values_arr(int n_dims, int n_feat, bool use_temp) } } -double* node_value_arrs::get_value_ptr(int ind, int offset) +double* node_value_arrs::get_value_ptr(int arr_ind, int feat_ind, int offset) { - if(ind < N_STORE_FEATURES) - return access_value_arr(ind); - temp_storage_reg(ind, offset) = ind; - return access_temp_storage((ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES); + if(arr_ind < N_STORE_FEATURES) + return access_value_arr(arr_ind); + temp_storage_reg(arr_ind, offset) = feat_ind; + return access_temp_storage((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES); } -double* node_value_arrs::get_test_value_ptr(int ind, int offset) +double* node_value_arrs::get_test_value_ptr(int arr_ind, int feat_ind, int offset) { - if(ind < N_STORE_FEATURES) - return access_test_value_arr(ind); - temp_storage_test_reg(ind, offset) = ind; - return access_temp_storage_test((ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES); + if(arr_ind < N_STORE_FEATURES) + return access_test_value_arr(arr_ind); + temp_storage_test_reg(arr_ind, offset) = feat_ind; + return access_temp_storage_test((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES); } void node_value_arrs::initialize_d_matrix_arr() 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 7918fa1b..dcf657c4 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.hpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.hpp @@ -145,7 +145,7 @@ namespace node_value_arrs * * @return The value pointer */ - double* get_value_ptr(int ind, int offset = 0); + double* get_value_ptr(int arr_ind, int feat_ind, int offset = 0); /** * @brief Access the test_value_ptr to a feature @@ -155,7 +155,7 @@ namespace node_value_arrs * * @return The value pointer */ - double* get_test_value_ptr(int ind, int offset = 0); + double* get_test_value_ptr(int arr_ind, int feat_ind, int offset = 0); /** * @brief Get the pointer to a primary feature @@ -167,6 +167,9 @@ namespace node_value_arrs { return D_MATRIX.data() + ind * N_SAMPLES; } + + inline void clear_temp_reg(){std::fill_n(TEMP_STORAGE_REG.data(), TEMP_STORAGE_REG.size(), -1);} + inline void clear_temp_test_reg(){std::fill_n(TEMP_STORAGE_TEST_REG.data(), TEMP_STORAGE_TEST_REG.size(), -1);} } #endif -- GitLab