diff --git a/src/feature_creation/feature_space/FeatureSpace.cpp b/src/feature_creation/feature_space/FeatureSpace.cpp index b9951fce31e9a5d5ff8cc3d4ec554410a44901c0..1434b91b1a31a3f68846a7d5caf986c07a87e6c5 100644 --- a/src/feature_creation/feature_space/FeatureSpace.cpp +++ b/src/feature_creation/feature_space/FeatureSpace.cpp @@ -24,6 +24,7 @@ FeatureSpace::FeatureSpace( std::vector<std::string> allowed_ops, int max_phi, int n_sis_select, + int max_store_rung, double max_abs_feat_val ): _mpi_comm(mpi_comm), @@ -31,6 +32,7 @@ FeatureSpace::FeatureSpace( _n_sis_select(n_sis_select), _n_samp(phi_0[0]->n_samp()), _n_feat(phi_0.size()), + _n_rung_store(max_store_rung), _max_abs_feat_val(max_abs_feat_val), _start_gen(1, 0), _scores(phi_0.size(), 0.0), @@ -55,7 +57,6 @@ FeatureSpace::FeatureSpace( void FeatureSpace::generate_feature_space() { - std::vector<double> scores(_phi.size()); for(int nn = 1; nn <= _max_phi; ++nn) { std::vector<node_ptr> next_phi; @@ -66,8 +67,6 @@ void FeatureSpace::generate_feature_space() int feat_ind = _n_feat + node_value_arrs::get_max_number_features(_allowed_ops, 1, start_end[0]); next_phi.reserve(node_value_arrs::get_max_number_features(_allowed_ops, 1, start_end[1] - start_end[0])); - scores.resize(node_value_arrs::get_max_number_features(_allowed_ops, 1, _phi.size())); - scores.reserve(node_value_arrs::get_max_number_features(_allowed_ops, 1, _phi.size())); for(auto feat_1 = _phi.begin() + start_end[0]; feat_1 != _phi.begin() + start_end[1]; ++feat_1) { @@ -135,19 +134,22 @@ void FeatureSpace::generate_feature_space() { _phi.reserve(_phi.size() + next_phi_vec.size()); for(auto& feat : next_phi_vec) - { - if(nn <= node_value_arrs::N_RUNGS_STORED) - { - feat->set_value(); - _phi.push_back(feat); - } - else - { - _phi.push_back(feat); - } - } + _phi.push_back(feat); } } + + // if(0 < _n_rung_store < _max_phi) + // { + // node_value_arrs::resize_values_arr(_n_rung_store, _start_gen[_n_rung_store+1], true); + // for(auto feat = _phi.begin(); feat != _phi.begin() + _start_gen[_n_rung_store+1]; ++feat) + // (*feat)->set_value(); + // } + // else if(_n_rung_store > 0) + // { + // node_value_arrs::resize_values_arr(_max_phi, _phi.size(), false); + // for(auto feat = _phi.begin(); feat != _phi.end(); ++feat) + // (*feat)->set_value(); + // } _n_feat = _phi.size(); } diff --git a/src/feature_creation/feature_space/FeatureSpace.hpp b/src/feature_creation/feature_space/FeatureSpace.hpp index 54cf09e6c2dc94d361d4a72dee68de1623618e5b..ed77db523d168445b1aa6814a5592d023d4dcd11 100644 --- a/src/feature_creation/feature_space/FeatureSpace.hpp +++ b/src/feature_creation/feature_space/FeatureSpace.hpp @@ -4,6 +4,7 @@ #include <mpi_interface/MPI_Interface.hpp> #include <feature_creation/node/FeatureNode.hpp> #include <feature_creation/node/operator_nodes/allowed_ops.hpp> +#include <feature_creation/node/value_storage/nodes_value_containers.hpp> #include <boost/serialization/shared_ptr.hpp> @@ -22,6 +23,7 @@ class FeatureSpace int _n_sis_select; //!< Number of features to select for each dimensions int _n_samp; //!< Number of samples int _n_feat; //!< Total number of features + int _n_rung_store; //!< Total rungs stored double _max_abs_feat_val; //!< Maximum absolute value for any feature @@ -57,6 +59,7 @@ public: std::vector<std::string> allowed_ops, int max_phi=1, int n_sis_select=1, + int max_store_rung=2, double max_abs_feat_val=1e27 ); diff --git a/src/feature_creation/node/FeatureNode.hpp b/src/feature_creation/node/FeatureNode.hpp index f813e23a1ae8a29bfc3aa767f73150464e2a7ec6..776b7306ff9ab51e8f6548c4f81cd2b5fcc45160 100644 --- a/src/feature_creation/node/FeatureNode.hpp +++ b/src/feature_creation/node/FeatureNode.hpp @@ -57,7 +57,7 @@ public: /** * @brief Set the value for the feature */ - inline void set_value(int offset = -1){return;} + inline void set_value(int offset = -1){std::copy_n(node_value_arrs::PRIMARY_FEAT_ARR.get() + _feat_ind * _n_samp, _n_samp, value_ptr());} /** * @brief Check if the feature contains NaN 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 d14f1c61e1e13f16d041ed292838beab0d76606c..5e0464645d4c4eed371a40c28cd0eea3dae4cfc1 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.cpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.cpp @@ -4,9 +4,11 @@ int node_value_arrs::N_SAMPLES; int node_value_arrs::N_STORE_FEATURES; int node_value_arrs::N_RUNGS_STORED; -std::unique_ptr<int[]> node_value_arrs::TEMP_STORAGE_REG; -std::unique_ptr<double[]> node_value_arrs::VALUES_ARR; -std::unique_ptr<double[]> node_value_arrs::TEMP_STORAGE_ARR; +std::unique_ptr<int[]> node_value_arrs::TEMP_STORAGE_REG = nullptr; + +std::unique_ptr<double[]> node_value_arrs::VALUES_ARR = nullptr; +std::unique_ptr<double[]> node_value_arrs::PRIMARY_FEAT_ARR = nullptr; +std::unique_ptr<double[]> node_value_arrs::TEMP_STORAGE_ARR = nullptr; int node_value_arrs::get_number_new_features(std::string new_op, int n_current_features) { @@ -48,15 +50,31 @@ int node_value_arrs::get_max_number_features(std::vector<std::string> allowed_op return n_feats; } -void node_value_arrs::setup_values_arr(int n_samples, int n_rung, int n_primary_feat, std::vector<std::string> allowed_operators) +void node_value_arrs::initialize_values_arr(int n_samples, int n_primary_feat) { N_SAMPLES = n_samples; - N_RUNGS_STORED = n_rung; - N_STORE_FEATURES = get_max_number_features(allowed_operators, n_rung, n_primary_feat); + N_RUNGS_STORED = 0; + N_STORE_FEATURES = n_primary_feat; + PRIMARY_FEAT_ARR = std::unique_ptr<double[]>(new double[N_STORE_FEATURES * N_SAMPLES]); VALUES_ARR = std::unique_ptr<double[]>(new double[N_STORE_FEATURES * N_SAMPLES]); + TEMP_STORAGE_ARR = std::unique_ptr<double[]>(new double[3 * N_STORE_FEATURES * N_SAMPLES]); TEMP_STORAGE_REG = std::unique_ptr<int[]>(new int[3 * N_STORE_FEATURES]); std::copy_n(std::vector<int>(3*N_STORE_FEATURES, -1).data(), 3*N_STORE_FEATURES, TEMP_STORAGE_REG.get()); } +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; + + VALUES_ARR = std::unique_ptr<double[]>(new double[N_STORE_FEATURES * N_SAMPLES]); + + if(use_temp) + { + TEMP_STORAGE_ARR = std::unique_ptr<double[]>(new double[3 * N_STORE_FEATURES * N_SAMPLES]); + TEMP_STORAGE_REG = std::unique_ptr<int[]>(new int[3 * N_STORE_FEATURES]); + std::copy_n(std::vector<int>(3*N_STORE_FEATURES, -1).data(), 3*N_STORE_FEATURES, TEMP_STORAGE_REG.get()); + } +} \ No newline at end of file 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 a5a096820014a02efbd6296772924a72179fedb1..119e4e0affd6857f4d611f388015eb7870dc50c7 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.hpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.hpp @@ -14,6 +14,7 @@ namespace node_value_arrs extern int N_RUNGS_STORED; //!< Number of rungs with values stored extern std::unique_ptr<int[]> TEMP_STORAGE_REG; //!< Register to see which feature is stored in each slot + extern std::unique_ptr<double[]> PRIMARY_FEAT_ARR; //!< Value of the stored features extern std::unique_ptr<double[]> VALUES_ARR; //!< Value of the stored features extern std::unique_ptr<double[]> TEMP_STORAGE_ARR; //!< Array to temporarily store feature values @@ -42,11 +43,19 @@ namespace node_value_arrs * @details Take initial parameters and construct the feature arraies * * @param n_samples number of samples per feature - * @param n_dims Number of dimensions to store * @param n_primary_feat number of primary features - * @param allowed_operators list of allowed operators */ - void setup_values_arr(int n_samples, int n_dims, int n_primary_feat, std::vector<std::string> allowed_operators); + void initialize_values_arr(int n_samples, int n_primary_feat); + + /** + * @brief set of the value arrays + * @details Take initial parameters and construct the feature arraies + * + * @param n_dims Number of dimensions to store + * @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, bool use_temp); /** * @brief Get a reference slot/feature register @@ -91,6 +100,11 @@ namespace node_value_arrs temp_storage_reg(ind, offset) = ind; return access_temp_storage((ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES); } + + inline double* get_primary_feat_ptr(int ind) + { + return PRIMARY_FEAT_ARR.get() + ind * N_SAMPLES; + } } #endif \ No newline at end of file diff --git a/src/inputs/InputParser.cpp b/src/inputs/InputParser.cpp index 082a5b0e951885f6521d0f954d4e80a75883cb24..18d4ca46649680e061c533a1b4392ec04b8ed5b4 100644 --- a/src/inputs/InputParser.cpp +++ b/src/inputs/InputParser.cpp @@ -4,6 +4,7 @@ InputParser::InputParser(boost::property_tree::ptree IP, std::string fn, std::sh _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", 2)), _n_samp(0), _filename(fn), _data_file(IP.get<std::string>("data_file", "data.csv")), @@ -131,12 +132,15 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm) units.erase(units.begin() + _propind); } - node_value_arrs::setup_values_arr(_prop.size(), std::min(_max_rung, 2), headers.size(), _opset); + node_value_arrs::initialize_values_arr(_prop.size(), headers.size()); std::vector<node_ptr> phi_0; for(int ff = 0; ff < headers.size(); ++ff) + { phi_0.push_back(std::make_shared<FeatureNode>(ff, headers[ff], data[ff], units[ff])); + std::copy_n(data[ff].begin(), data[ff].size(), node_value_arrs::get_primary_feat_ptr(ff)); + } - _feat_space = std::make_shared<FeatureSpace>(comm, phi_0, _opset, _max_rung, _n_sis_select); + _feat_space = std::make_shared<FeatureSpace>(comm, phi_0, _opset, _max_rung, _n_sis_select, _max_store_rung); } void stripComments(std::string& filename) diff --git a/src/inputs/InputParser.hpp b/src/inputs/InputParser.hpp index 44a8722927fc0cea8fdc0752fc27222fabc948ac..b1c6c7a0de82fe953322d6686b32c4a4d1d1591d 100644 --- a/src/inputs/InputParser.hpp +++ b/src/inputs/InputParser.hpp @@ -24,6 +24,7 @@ public: std::shared_ptr<FeatureSpace> _feat_space; int _n_dim; int _max_rung; + int _max_store_rung; int _n_sis_select; int _n_samp;