Skip to content
Snippets Groups Projects
Commit 00ff6620 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Allow for optional temp storage size

temp storage can be set manually
parent 7243259e
No related branches found
No related tags found
No related merge requests found
...@@ -28,6 +28,7 @@ FeatureSpace::FeatureSpace( ...@@ -28,6 +28,7 @@ FeatureSpace::FeatureSpace(
int n_sis_select, int n_sis_select,
int max_store_rung, int max_store_rung,
int n_rung_generate, int n_rung_generate,
int max_temp_store,
double min_abs_feat_val, double min_abs_feat_val,
double max_abs_feat_val double max_abs_feat_val
): ):
...@@ -46,8 +47,11 @@ FeatureSpace::FeatureSpace( ...@@ -46,8 +47,11 @@ FeatureSpace::FeatureSpace(
_n_samp(phi_0[0]->n_samp()), _n_samp(phi_0[0]->n_samp()),
_n_feat(phi_0.size()), _n_feat(phi_0.size()),
_n_rung_store(max_store_rung), _n_rung_store(max_store_rung),
_n_rung_generate(n_rung_generate) _n_rung_generate(n_rung_generate),
_max_temp_store(max_temp_store)
{ {
if(_max_temp_store != -1)
_max_temp_store /= 3;
_project = project_funcs::project_r; _project = project_funcs::project_r;
if(_n_rung_generate > 1) if(_n_rung_generate > 1)
...@@ -203,7 +207,10 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop) ...@@ -203,7 +207,10 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop)
if(nn <= _n_rung_store) if(nn <= _n_rung_store)
{ {
bool use_temp = (nn != _max_phi) || (_max_phi > _n_rung_store); bool use_temp = (nn != _max_phi) || (_max_phi > _n_rung_store);
node_value_arrs::resize_values_arr(nn, _phi.size(), use_temp); 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);
for(int ff = _start_gen[0]; ff < _phi.size(); ++ff) for(int ff = _start_gen[0]; ff < _phi.size(); ++ff)
{ {
_phi[ff]->set_value(); _phi[ff]->set_value();
...@@ -318,7 +325,10 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop) ...@@ -318,7 +325,10 @@ void FeatureSpace::generate_feature_space(std::vector<double>& prop)
if(_max_phi <= _n_rung_store) if(_max_phi <= _n_rung_store)
{ {
bool use_temp = (_max_phi > _n_rung_store); bool use_temp = (_max_phi > _n_rung_store);
node_value_arrs::resize_values_arr(_n_rung_store, _phi.size(), use_temp); 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);
} }
for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) for(int ff = _start_gen.back(); ff < _phi.size(); ++ff)
{ {
......
...@@ -48,7 +48,7 @@ class FeatureSpace ...@@ -48,7 +48,7 @@ class FeatureSpace
int _n_feat; //!< Total number of features int _n_feat; //!< Total number of features
int _n_rung_store; //!< Total rungs stored int _n_rung_store; //!< Total rungs stored
int _n_rung_generate; //!< Total number of rungs to generate on the fly int _n_rung_generate; //!< Total number of rungs to generate on the fly
int _max_temp_store; //!< Maximum number of features to store in temporary storage
public: public:
/** /**
...@@ -71,6 +71,7 @@ public: ...@@ -71,6 +71,7 @@ public:
int n_sis_select=1, int n_sis_select=1,
int max_store_rung=2, int max_store_rung=2,
int n_rung_generate=0, int n_rung_generate=0,
int max_temp_store=-1,
double min_abs_feat_val=1e-50, double min_abs_feat_val=1e-50,
double max_abs_feat_val=1e50 double max_abs_feat_val=1e50
); );
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
int node_value_arrs::N_SELECTED; int node_value_arrs::N_SELECTED;
int node_value_arrs::N_SAMPLES; int node_value_arrs::N_SAMPLES;
int node_value_arrs::N_STORE_FEATURES; int node_value_arrs::N_STORE_FEATURES;
int node_value_arrs::N_TEMP_STORE_FEATURES;
int node_value_arrs::N_RUNGS_STORED; int node_value_arrs::N_RUNGS_STORED;
int node_value_arrs::N_SAMPLES_TEST; int node_value_arrs::N_SAMPLES_TEST;
...@@ -62,21 +63,23 @@ void node_value_arrs::initialize_values_arr(int n_samples, int n_samples_test, i ...@@ -62,21 +63,23 @@ void node_value_arrs::initialize_values_arr(int n_samples, int n_samples_test, i
N_SAMPLES_TEST = n_samples_test; N_SAMPLES_TEST = n_samples_test;
N_RUNGS_STORED = 0; N_RUNGS_STORED = 0;
N_STORE_FEATURES = n_primary_feat; N_STORE_FEATURES = n_primary_feat;
N_TEMP_STORE_FEATURES = n_primary_feat;
VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES); VALUES_ARR = std::vector<double>(N_TEMP_STORE_FEATURES * N_SAMPLES);
TEST_VALUES_ARR = std::vector<double>(N_STORE_FEATURES * N_SAMPLES_TEST); TEST_VALUES_ARR = std::vector<double>(N_TEMP_STORE_FEATURES * N_SAMPLES_TEST);
TEMP_STORAGE_ARR = std::vector<double>(3 * N_STORE_FEATURES * N_SAMPLES); TEMP_STORAGE_ARR = std::vector<double>(3 * N_TEMP_STORE_FEATURES * N_SAMPLES);
TEMP_STORAGE_REG = std::vector<int>(3 * N_STORE_FEATURES, -1); TEMP_STORAGE_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_ARR = std::vector<double>(3 * N_TEMP_STORE_FEATURES * N_SAMPLES_TEST);
TEMP_STORAGE_TEST_REG = std::vector<int>(3 * N_STORE_FEATURES, -1); TEMP_STORAGE_TEST_REG = std::vector<int>(3 * N_TEMP_STORE_FEATURES, -1);
} }
void node_value_arrs::resize_values_arr(int n_dims, int n_feat, bool use_temp) void node_value_arrs::resize_values_arr(int n_dims, int n_feat, int max_temp_store, bool use_temp)
{ {
N_RUNGS_STORED = n_dims; N_RUNGS_STORED = n_dims;
N_STORE_FEATURES = n_feat; N_STORE_FEATURES = n_feat;
N_TEMP_STORE_FEATURES = std::min(n_feat, max_temp_store);
VALUES_ARR.resize(N_STORE_FEATURES * N_SAMPLES); VALUES_ARR.resize(N_STORE_FEATURES * N_SAMPLES);
VALUES_ARR.shrink_to_fit(); VALUES_ARR.shrink_to_fit();
...@@ -86,16 +89,16 @@ void node_value_arrs::resize_values_arr(int n_dims, int n_feat, bool use_temp) ...@@ -86,16 +89,16 @@ void node_value_arrs::resize_values_arr(int n_dims, int n_feat, bool use_temp)
if(use_temp) if(use_temp)
{ {
TEMP_STORAGE_ARR.resize(3 * N_STORE_FEATURES * N_SAMPLES); TEMP_STORAGE_ARR.resize(3 * N_TEMP_STORE_FEATURES * N_SAMPLES);
TEMP_STORAGE_ARR.shrink_to_fit(); TEMP_STORAGE_ARR.shrink_to_fit();
TEMP_STORAGE_REG.resize(3 * N_STORE_FEATURES, - 1); TEMP_STORAGE_REG.resize(3 * N_TEMP_STORE_FEATURES, - 1);
TEMP_STORAGE_REG.shrink_to_fit(); TEMP_STORAGE_REG.shrink_to_fit();
TEMP_STORAGE_TEST_ARR.resize(3 * N_STORE_FEATURES * N_SAMPLES_TEST); TEMP_STORAGE_TEST_ARR.resize(3 * N_TEMP_STORE_FEATURES * N_SAMPLES_TEST);
TEMP_STORAGE_TEST_ARR.shrink_to_fit(); TEMP_STORAGE_TEST_ARR.shrink_to_fit();
TEMP_STORAGE_TEST_REG.resize(3 * N_STORE_FEATURES, - 1); TEMP_STORAGE_TEST_REG.resize(3 * N_TEMP_STORE_FEATURES, - 1);
TEMP_STORAGE_TEST_REG.shrink_to_fit(); TEMP_STORAGE_TEST_REG.shrink_to_fit();
} }
else else
...@@ -109,16 +112,18 @@ double* node_value_arrs::get_value_ptr(int arr_ind, int feat_ind, int offset) ...@@ -109,16 +112,18 @@ double* node_value_arrs::get_value_ptr(int arr_ind, int feat_ind, int offset)
{ {
if(arr_ind < N_STORE_FEATURES) if(arr_ind < N_STORE_FEATURES)
return access_value_arr(arr_ind); return access_value_arr(arr_ind);
temp_storage_reg(arr_ind, offset) = feat_ind; temp_storage_reg(arr_ind, offset) = feat_ind;
return access_temp_storage((arr_ind % N_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES); return access_temp_storage((arr_ind % N_TEMP_STORE_FEATURES) + (offset % 3) * N_TEMP_STORE_FEATURES);
} }
double* node_value_arrs::get_test_value_ptr(int arr_ind, int feat_ind, int offset) double* node_value_arrs::get_test_value_ptr(int arr_ind, int feat_ind, int offset)
{ {
if(arr_ind < N_STORE_FEATURES) if(arr_ind < N_STORE_FEATURES)
return access_test_value_arr(arr_ind); return access_test_value_arr(arr_ind);
temp_storage_test_reg(arr_ind, offset) = feat_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); return access_temp_storage_test((arr_ind % N_TEMP_STORE_FEATURES) + (offset % 3) * N_TEMP_STORE_FEATURES);
} }
void node_value_arrs::initialize_d_matrix_arr() void node_value_arrs::initialize_d_matrix_arr()
......
...@@ -21,6 +21,7 @@ namespace node_value_arrs ...@@ -21,6 +21,7 @@ namespace node_value_arrs
extern int N_SAMPLES; //!< Number of samples in the nodes extern int N_SAMPLES; //!< Number of samples in the nodes
extern int N_SAMPLES_TEST; //!< 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_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 extern int N_RUNGS_STORED; //!< Number of rungs with values stored
...@@ -62,7 +63,7 @@ namespace node_value_arrs ...@@ -62,7 +63,7 @@ namespace node_value_arrs
* @param n_feat number of features to store * @param n_feat number of features to store
* @param use_temp If true keep the temporary_storage * @param use_temp If true keep the temporary_storage
*/ */
void resize_values_arr(int n_dims, int n_feat, bool use_temp); void resize_values_arr(int n_dims, int n_feat, int max_temp_store, bool use_temp);
/** /**
* @brief set of the value arrays * @brief set of the value arrays
...@@ -89,7 +90,7 @@ namespace node_value_arrs ...@@ -89,7 +90,7 @@ namespace node_value_arrs
* *
* @return The register element for a given feature index and offset * @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_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES];} 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];}
/** /**
* @brief Get a reference slot/feature test register * @brief Get a reference slot/feature test register
...@@ -99,7 +100,7 @@ namespace node_value_arrs ...@@ -99,7 +100,7 @@ namespace node_value_arrs
* *
* @return The register element for a given feature index and offset * @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_STORE_FEATURES) + (offset % 3) * N_STORE_FEATURES];} 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];}
/** /**
* @brief Access element of the permanent storage array * @brief Access element of the permanent storage array
......
...@@ -14,7 +14,8 @@ InputParser::InputParser(boost::property_tree::ptree IP, std::string fn, std::sh ...@@ -14,7 +14,8 @@ InputParser::InputParser(boost::property_tree::ptree IP, std::string fn, std::sh
_max_store_rung(IP.get<int>("n_rung_store", _max_rung - 1)), _max_store_rung(IP.get<int>("n_rung_store", _max_rung - 1)),
_n_rung_generate(IP.get<int>("n_rung_generate", 0)), _n_rung_generate(IP.get<int>("n_rung_generate", 0)),
_n_samp(0), _n_samp(0),
_n_residuals(IP.get<int>("n_residual", 1)) _n_residuals(IP.get<int>("n_residual", 1)),
_max_temp_store(IP.get<int>("max_temp_storage", -1))
{ {
std::ifstream data_stream; std::ifstream data_stream;
std::string line; std::string line;
...@@ -268,7 +269,7 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm, st ...@@ -268,7 +269,7 @@ void InputParser::generate_feature_space(std::shared_ptr<MPI_Interface> comm, st
for(int ff = 0; ff < headers.size(); ++ff) 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])); 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, _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, _max_temp_store, _l_bound, _u_bound);
} }
void stripComments(std::string& filename) void stripComments(std::string& filename)
......
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
int _n_sis_select; int _n_sis_select;
int _n_samp; int _n_samp;
int _n_residuals; 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); 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;} inline std::shared_ptr<FeatureSpace> feat_space(){return _feat_space;}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment