diff --git a/src/descriptor_identifier/SISSORegressor.cpp b/src/descriptor_identifier/SISSORegressor.cpp index 55fa4a0353852e19c2cad69f79f4d46472faa2b1..c7fdca7479ccd2992f80511a598e9c3d123677ff 100644 --- a/src/descriptor_identifier/SISSORegressor.cpp +++ b/src/descriptor_identifier/SISSORegressor.cpp @@ -225,11 +225,24 @@ void SISSORegressor::l0_norm(std::vector<double>& prop, int n_dim) } while(util_funcs::iterate(inds, inds.size(), _mpi_comm->size())); std::vector<double> all_min_error(_mpi_comm->size() * _n_residual); - // std::vector<std::vector<std::vector<int>>> all_inds_min; std::vector<int> all_inds_min(_mpi_comm->size() *_n_residual * n_dim); - mpi::all_gather(*_mpi_comm, min_errors.data(), _n_residual, all_min_error); - mpi::all_gather(*_mpi_comm, inds_min.data(), _n_residual * n_dim, all_inds_min); + if(_mpi_comm->rank() == 0) + { + mpi::gather(*_mpi_comm, min_errors.data(), min_errors.size(), all_min_error.data(), 0); + mpi::broadcast(*_mpi_comm, all_min_error.data(), all_min_error.size(), 0); + + mpi::gather(*_mpi_comm, inds_min.data(), inds_min.size(), all_inds_min.data(), 0); + mpi::broadcast(*_mpi_comm, all_inds_min.data(), all_inds_min.size(), 0); + } + else + { + mpi::gather(*_mpi_comm, min_errors.data(), min_errors.size(), 0); + mpi::broadcast(*_mpi_comm, all_min_error.data(), all_min_error.size(), 0); + + mpi::gather(*_mpi_comm, inds_min.data(), inds_min.size(), 0); + mpi::broadcast(*_mpi_comm, all_inds_min.data(), all_inds_min.size(), 0); + } inds = util_funcs::argsort(all_min_error); diff --git a/src/feature_creation/feature_space/FeatureSpace.cpp b/src/feature_creation/feature_space/FeatureSpace.cpp index 7e9d4168ae54f1cdcda9f7d4f93e1ae11e5e6ec7..b853bc08ec40fc91d3938af08e2f155f0fbeafd3 100644 --- a/src/feature_creation/feature_space/FeatureSpace.cpp +++ b/src/feature_creation/feature_space/FeatureSpace.cpp @@ -28,7 +28,6 @@ FeatureSpace::FeatureSpace( int n_sis_select, int max_store_rung, int n_rung_generate, - int max_temp_store, double min_abs_feat_val, double max_abs_feat_val ): @@ -47,8 +46,7 @@ FeatureSpace::FeatureSpace( _n_samp(phi_0[0]->n_samp()), _n_feat(phi_0.size()), _n_rung_store(max_store_rung), - _n_rung_generate(n_rung_generate), - _max_temp_store(max_temp_store) + _n_rung_generate(n_rung_generate) { initialize_fs(prop); @@ -63,7 +61,6 @@ FeatureSpace::FeatureSpace( int n_sis_select, int max_store_rung, int n_rung_generate, - int max_temp_store, double min_abs_feat_val, double max_abs_feat_val ): @@ -81,8 +78,7 @@ FeatureSpace::FeatureSpace( _n_sis_select(n_sis_select), _n_feat(python::len(phi_0)), _n_rung_store(max_store_rung), - _n_rung_generate(n_rung_generate), - _max_temp_store(max_temp_store) + _n_rung_generate(n_rung_generate) { _n_samp = _phi_0[0]->n_samp(); initialize_fs(python_conv_utils::from_list<double>(prop)); @@ -97,7 +93,6 @@ FeatureSpace::FeatureSpace( int n_sis_select, int max_store_rung, int n_rung_generate, - int max_temp_store, double min_abs_feat_val, double max_abs_feat_val ): @@ -115,8 +110,7 @@ FeatureSpace::FeatureSpace( _n_sis_select(n_sis_select), _n_feat(python::len(phi_0)), _n_rung_store(max_store_rung), - _n_rung_generate(n_rung_generate), - _max_temp_store(max_temp_store) + _n_rung_generate(n_rung_generate) { _n_samp = _phi_0[0]->n_samp(); initialize_fs(python_conv_utils::from_ndarray<double>(prop)); @@ -138,10 +132,6 @@ void FeatureSpace::initialize_fs(std::vector<double> prop) out_file_stream << std::setw(14) <<std::left << "# FEAT_ID" << std::setw(24) << std::left << "Score" << "Feature Expression" << std::endl; out_file_stream.close(); } - - if(_max_temp_store != -1) - _max_temp_store /= 3; - _project = project_funcs::project_r; for(auto & op : _allowed_ops) @@ -315,10 +305,7 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop) if(nn <= _n_rung_store) { bool use_temp = (nn != _max_phi) || (_max_phi > _n_rung_store); - if(_max_temp_store == -1) - node_value_arrs::resize_values_arr(_n_rung_store, _phi.size(), _phi.size(), use_temp); - else - node_value_arrs::resize_values_arr(_n_rung_store, _phi.size(), _max_temp_store, use_temp); + node_value_arrs::resize_values_arr(nn, _phi.size(), use_temp); for(int ff = _start_gen[0]; ff < _phi.size(); ++ff) { @@ -457,11 +444,7 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop) if(_max_phi <= _n_rung_store) { bool use_temp = (_max_phi > _n_rung_store); - if(_max_temp_store == -1) - node_value_arrs::resize_values_arr(_n_rung_store, _phi.size(), _phi.size(), use_temp); - else - node_value_arrs::resize_values_arr(_n_rung_store, _phi.size(), _max_temp_store, use_temp); - + node_value_arrs::resize_values_arr(nn, _phi.size(), use_temp); } for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) { @@ -821,8 +804,8 @@ void FeatureSpace::register_python() void (FeatureSpace::*sis_list)(list) = &FeatureSpace::sis; void (FeatureSpace::*sis_ndarray)(np::ndarray) = &FeatureSpace::sis; - class_<FeatureSpace>("FeatureSpace", init<list, list, np::ndarray, list, optional<int, int, int, int, int, double, double>>()) - .def(init<list, list, list, list, optional<int, int, int, int, int, double, double>>()) + class_<FeatureSpace>("FeatureSpace", init<list, list, np::ndarray, list, optional<int, int, int, int, double, double>>()) + .def(init<list, list, list, list, optional<int, int, int, int, double, double>>()) .def("sis", sis_list) .def("sis", sis_ndarray) .def("feat_in_phi", &FeatureSpace::feat_in_phi) diff --git a/src/feature_creation/feature_space/FeatureSpace.hpp b/src/feature_creation/feature_space/FeatureSpace.hpp index 8caf3cef2c6be819f0d034e5fa1a0018ff020595..02bde78c9d14b6192cdbdf9743f02cfd2f897b80 100644 --- a/src/feature_creation/feature_space/FeatureSpace.hpp +++ b/src/feature_creation/feature_space/FeatureSpace.hpp @@ -74,7 +74,6 @@ public: int n_sis_select=1, int max_store_rung=-1, int n_rung_generate=0, - int max_temp_store=-1, double min_abs_feat_val=1e-50, double max_abs_feat_val=1e50 ); @@ -98,7 +97,6 @@ public: int n_sis_select=1, int max_store_rung=-1, int n_rung_generate=0, - int max_temp_store=-1, double min_abs_feat_val=1e-50, double max_abs_feat_val=1e50 ); @@ -122,7 +120,6 @@ public: int n_sis_select=1, int max_store_rung=-1, int n_rung_generate=0, - int max_temp_store=-1, double min_abs_feat_val=1e-50, double max_abs_feat_val=1e50 ); diff --git a/src/feature_creation/node/FeatureNode.cpp b/src/feature_creation/node/FeatureNode.cpp index abdadceee6ef87964313d817ac0501be62c9f12b..f68cf77399fd0b9b8b94a1d941946a10cfc2dc72 100644 --- a/src/feature_creation/node/FeatureNode.cpp +++ b/src/feature_creation/node/FeatureNode.cpp @@ -27,7 +27,7 @@ FeatureNode::FeatureNode(int feat_ind, std::string expr, np::ndarray value, np:: else if((_n_samp != node_value_arrs::N_SAMPLES) || (_n_test_samp != node_value_arrs::N_SAMPLES_TEST)) throw std::logic_error("Number of samples in current feature is not the same as the others, (" + std::to_string(_n_samp) + " and " + std::to_string(_n_test_samp) + " vs. " + std::to_string(node_value_arrs::N_SAMPLES) + " and " + std::to_string(node_value_arrs::N_SAMPLES_TEST) + ")"); else if(feat_ind >= node_value_arrs::N_STORE_FEATURES) - node_value_arrs::resize_values_arr(0, node_value_arrs::N_STORE_FEATURES + 1, node_value_arrs::N_STORE_FEATURES + 1, true); + node_value_arrs::resize_values_arr(0, node_value_arrs::N_STORE_FEATURES + 1, true); set_value(); set_test_value(); @@ -47,7 +47,7 @@ FeatureNode::FeatureNode(int feat_ind, std::string expr, python::list value, pyt else if((_n_samp != node_value_arrs::N_SAMPLES) || (_n_test_samp != node_value_arrs::N_SAMPLES_TEST)) throw std::logic_error("Number of samples in current feature is not the same as the others, (" + std::to_string(_n_samp) + " and " + std::to_string(_n_test_samp) + " vs. " + std::to_string(node_value_arrs::N_SAMPLES) + " and " + std::to_string(node_value_arrs::N_SAMPLES_TEST) + ")"); else if(feat_ind >= node_value_arrs::N_STORE_FEATURES) - node_value_arrs::resize_values_arr(0, node_value_arrs::N_STORE_FEATURES + 1, node_value_arrs::N_STORE_FEATURES + 1, true); + node_value_arrs::resize_values_arr(0, node_value_arrs::N_STORE_FEATURES + 1, true); set_value(); set_test_value(); 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 654a6c2027af5575aae5ff30d307d02ea00bb118..01ab7c32f127f55c9774a39f9d317d70d9373711 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.cpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.cpp @@ -3,7 +3,6 @@ int node_value_arrs::N_SELECTED = 0; int node_value_arrs::N_SAMPLES = 0; int node_value_arrs::N_STORE_FEATURES = 0; -int node_value_arrs::N_TEMP_STORE_FEATURES = 0; int node_value_arrs::N_RUNGS_STORED = 0; int node_value_arrs::N_SAMPLES_TEST = 0; @@ -63,25 +62,23 @@ void node_value_arrs::initialize_values_arr(int n_samples, int n_samples_test, i N_SAMPLES_TEST = n_samples_test; N_RUNGS_STORED = 0; N_STORE_FEATURES = n_primary_feat; - N_TEMP_STORE_FEATURES = n_primary_feat; - VALUES_ARR = std::vector<double>(N_TEMP_STORE_FEATURES * N_SAMPLES); - TEST_VALUES_ARR = std::vector<double>(N_TEMP_STORE_FEATURES * N_SAMPLES_TEST); + VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES); + TEST_VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES_TEST); - TEMP_STORAGE_ARR = std::vector<double>(3 * N_TEMP_STORE_FEATURES * N_SAMPLES); - TEMP_STORAGE_REG = std::vector<int>(3 * N_TEMP_STORE_FEATURES, -1); + TEMP_STORAGE_ARR = std::vector<double>(3 * N_STORE_FEATURES * N_SAMPLES); + TEMP_STORAGE_REG = std::vector<int>(3 * N_STORE_FEATURES, -1); - TEMP_STORAGE_TEST_ARR = std::vector<double>(3 * N_TEMP_STORE_FEATURES * N_SAMPLES_TEST); - TEMP_STORAGE_TEST_REG = std::vector<int>(3 * N_TEMP_STORE_FEATURES, -1); + TEMP_STORAGE_TEST_ARR = std::vector<double>(3 * N_STORE_FEATURES * N_SAMPLES_TEST); + TEMP_STORAGE_TEST_REG = std::vector<int>(3 * N_STORE_FEATURES, -1); } -void node_value_arrs::resize_values_arr(int n_dims, int n_feat, int max_temp_store, bool use_temp) +void node_value_arrs::resize_values_arr(int n_dims, int n_feat, bool use_temp) { N_RUNGS_STORED = n_dims; N_STORE_FEATURES = n_feat; - N_TEMP_STORE_FEATURES = std::min(n_feat, max_temp_store); - if(N_TEMP_STORE_FEATURES == 0) - N_TEMP_STORE_FEATURES = 1; + if(N_STORE_FEATURES == 0) + N_STORE_FEATURES = 1; VALUES_ARR.resize(N_STORE_FEATURES * N_SAMPLES); VALUES_ARR.shrink_to_fit(); @@ -91,16 +88,16 @@ void node_value_arrs::resize_values_arr(int n_dims, int n_feat, int max_temp_sto if(use_temp) { - TEMP_STORAGE_ARR.resize(3 * N_TEMP_STORE_FEATURES * N_SAMPLES); + TEMP_STORAGE_ARR.resize(3 * N_STORE_FEATURES * N_SAMPLES); TEMP_STORAGE_ARR.shrink_to_fit(); - TEMP_STORAGE_REG.resize(3 * N_TEMP_STORE_FEATURES, - 1); + TEMP_STORAGE_REG.resize(3 * N_STORE_FEATURES, - 1); TEMP_STORAGE_REG.shrink_to_fit(); - TEMP_STORAGE_TEST_ARR.resize(3 * N_TEMP_STORE_FEATURES * N_SAMPLES_TEST); + TEMP_STORAGE_TEST_ARR.resize(3 * N_STORE_FEATURES * N_SAMPLES_TEST); TEMP_STORAGE_TEST_ARR.shrink_to_fit(); - TEMP_STORAGE_TEST_REG.resize(3 * N_TEMP_STORE_FEATURES, - 1); + TEMP_STORAGE_TEST_REG.resize(3 * N_STORE_FEATURES, - 1); TEMP_STORAGE_TEST_REG.shrink_to_fit(); } else @@ -116,7 +113,7 @@ double* node_value_arrs::get_value_ptr(int arr_ind, int feat_ind, int offset) return access_value_arr(arr_ind); temp_storage_reg(arr_ind, offset) = feat_ind; - return access_temp_storage((arr_ind % N_TEMP_STORE_FEATURES) + (offset % 3) * N_TEMP_STORE_FEATURES); + return access_temp_storage((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES); } double* node_value_arrs::get_test_value_ptr(int arr_ind, int feat_ind, int offset) @@ -125,7 +122,7 @@ double* node_value_arrs::get_test_value_ptr(int arr_ind, int feat_ind, int offse return access_test_value_arr(arr_ind); temp_storage_test_reg(arr_ind, offset) = feat_ind; - return access_temp_storage_test((arr_ind % N_TEMP_STORE_FEATURES) + (offset % 3) * N_TEMP_STORE_FEATURES); + 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 0fbb0d40df0610f83b2a720a2a8c4fa18b12131a..dcf657c4c4783fc2b0365797e018316a91bfa9aa 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.hpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.hpp @@ -21,7 +21,6 @@ namespace node_value_arrs 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_TEMP_STORE_FEATURES; //!< Number of feature that can be stored in TEMP_STORAGE ARRs values extern int N_RUNGS_STORED; //!< Number of rungs with values stored @@ -63,7 +62,7 @@ namespace node_value_arrs * @param n_feat number of features to store * @param use_temp If true keep the temporary_storage */ - void resize_values_arr(int n_dims, int n_feat, int max_temp_store, bool use_temp); + void resize_values_arr(int n_dims, int n_feat, bool use_temp); /** * @brief set of the value arrays @@ -90,7 +89,7 @@ namespace node_value_arrs * * @return The register element for a given feature index and offset */ - inline int& temp_storage_reg(int ind, int offset = 0){return TEMP_STORAGE_REG[(ind % N_TEMP_STORE_FEATURES) + (offset % 3) * N_TEMP_STORE_FEATURES];} + inline int& temp_storage_reg(int ind, int offset = 0){return TEMP_STORAGE_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES];} /** * @brief Get a reference slot/feature test register @@ -100,7 +99,7 @@ namespace node_value_arrs * * @return The register element for a given feature index and offset */ - inline int& temp_storage_test_reg(int ind, int offset = 0){return TEMP_STORAGE_TEST_REG[(ind % N_TEMP_STORE_FEATURES) + (offset % 3) * N_TEMP_STORE_FEATURES];} + inline int& temp_storage_test_reg(int ind, int offset = 0){return TEMP_STORAGE_TEST_REG[(ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES];} /** * @brief Access element of the permanent storage array diff --git a/src/inputs/InputParser.cpp b/src/inputs/InputParser.cpp index 8822bbda6657c8ca99b5f84472afe6af6e0998b6..c444ac2eb5cbd50b440f67bc34362beac71037d6 100644 --- a/src/inputs/InputParser.cpp +++ b/src/inputs/InputParser.cpp @@ -14,8 +14,7 @@ InputParser::InputParser(boost::property_tree::ptree IP, std::string fn, std::sh _max_store_rung(IP.get<int>("n_rung_store", _max_rung - 1)), _n_rung_generate(IP.get<int>("n_rung_generate", 0)), _n_samp(0), - _n_residuals(IP.get<int>("n_residual", 1)), - _max_temp_store(IP.get<int>("max_temp_storage", -1)) + _n_residuals(IP.get<int>("n_residual", 1)) { std::ifstream data_stream; std::string line; @@ -269,7 +268,7 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm, st 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, _prop_train, _task_sizes_train, _max_rung, _n_sis_select, _max_store_rung, _n_rung_generate, _max_temp_store, _l_bound, _u_bound); + _feat_space = std::make_shared<FeatureSpace>(comm, phi_0, _opset, _prop_train, _task_sizes_train, _max_rung, _n_sis_select, _max_store_rung, _n_rung_generate, _l_bound, _u_bound); } void stripComments(std::string& filename) diff --git a/src/inputs/InputParser.hpp b/src/inputs/InputParser.hpp index 07b744316c5e64dc6bffebe5a2b5182faa0297e4..1342bfdbdb396fb478ed2c8a843a959e6953ebf5 100644 --- a/src/inputs/InputParser.hpp +++ b/src/inputs/InputParser.hpp @@ -50,7 +50,6 @@ public: int _n_sis_select; int _n_samp; int _n_residuals; - int _max_temp_store; //!< Maximum number of features to store in temporary storage 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;}