diff --git a/src/feature_creation/feature_space/FeatureSpace.cpp b/src/feature_creation/feature_space/FeatureSpace.cpp index fbe072873c6547e3527d6a9c31d1d34ad4a72074..086a1cfa6926e202e30c84890d3847c6fb9a3209 100644 --- a/src/feature_creation/feature_space/FeatureSpace.cpp +++ b/src/feature_creation/feature_space/FeatureSpace.cpp @@ -515,17 +515,7 @@ void FeatureSpace::generate_feature_space() if(nn <= _n_rung_store) { - #ifdef PARAMETERIZE - bool use_temp = ( - (nn != _max_phi) || - (_un_param_operators.size() > 0) || - (_bin_param_operators.size() > 0) || - (_com_bin_param_operators.size() > 0) - ); - #else - bool use_temp = (nn != _max_phi); - #endif - node_value_arrs::resize_values_arr(nn, _phi.size(), use_temp); + node_value_arrs::resize_values_arr(nn, _phi.size(), (nn != _max_phi)); for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) { diff --git a/src/feature_creation/node/operator_nodes/OperatorNode.hpp b/src/feature_creation/node/operator_nodes/OperatorNode.hpp index 6ca3fa0e8c2fc2d43ec9e2f4e475f2ae6825975a..b55773a5f56d19d47e189ca6a3b653ae39643172 100644 --- a/src/feature_creation/node/operator_nodes/OperatorNode.hpp +++ b/src/feature_creation/node/operator_nodes/OperatorNode.hpp @@ -232,15 +232,19 @@ public: */ virtual double* value_ptr(int offset=-1, const bool for_comp=false) const { - if(_selected && (offset == -1)) + bool is_root = (offset == -1); + if(_selected && is_root) { return node_value_arrs::get_d_matrix_ptr(_d_mat_ind); } - offset += (offset == -1); - if((rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_arr_ind, rung(), offset, for_comp) != _feat_ind)) + if( + (rung() > node_value_arrs::N_RUNGS_STORED) && + (node_value_arrs::temp_storage_reg(_arr_ind, rung(), offset + is_root, for_comp) != _feat_ind) + ) { set_value(offset, for_comp); } + offset += is_root; return node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp); } @@ -257,11 +261,15 @@ public: virtual double* test_value_ptr(int offset=-1, const bool for_comp=false) const { - offset += (offset == -1); - if((rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_test_reg(_arr_ind, rung(), offset, for_comp) != _feat_ind)) + bool is_root = (offset == -1); + if( + (rung() > node_value_arrs::N_RUNGS_STORED) && + (node_value_arrs::temp_storage_test_reg(_arr_ind, rung(), offset + is_root, for_comp) != _feat_ind) + ) { set_test_value(offset, for_comp); } + offset += is_root; return node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp); } @@ -478,10 +486,10 @@ public: { return node_value_arrs::get_d_matrix_ptr(_d_mat_ind); } + set_value(params, offset, for_comp, depth); offset += (offset == -1); - set_value(params, offset, for_comp, depth); - return node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + return node_value_arrs::access_param_storage(rung(), offset, for_comp); } /** @@ -505,10 +513,10 @@ public: */ double* test_value_ptr(const double* params, int offset=-1, const bool for_comp=false, const int depth=0) const { - offset += (offset == -1); set_test_value(params, offset, for_comp, depth); - return node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + offset += (offset == -1); + return node_value_arrs::access_param_storage_test(rung(), offset, for_comp); } /** diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.cpp index 3dba04636e65492cca81919deb742f0f84647105..a152c40e4cc94fc101fbec0bd7f6d7535b9ca7f2 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/absolute_value.cpp @@ -22,7 +22,7 @@ void generateAbsNode( } int offset = -1; - double* val_ptr = feat->value_ptr(2 * offset); + double* val_ptr = feat->value_ptr(offset); // If the feature is strictly positive absolute values do nothing if(*std::min_element(val_ptr, val_ptr + feat->n_samp()) > 0.0) { diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.cpp index f8f9a8c1e33d8215632dad7ac457d6abb5b85cc9..843a2127c6492d430c699b762f5050cce0ad5f68 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs/parameterized_absolute_value.cpp @@ -107,7 +107,7 @@ void AbsNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -117,7 +117,7 @@ void AbsNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::abs(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -134,11 +134,11 @@ void AbsNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::abs( - _n_test_samp, vp_0, params[0], params[1], node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + _n_test_samp, vp_0, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.cpp index 73f85815c927f8ee7f7a075d9dd14a3925b2316f..f16c83ea592765de85b0c106d6ff39d2e9483343 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/abs_diff/parameterized_absolute_difference.cpp @@ -137,17 +137,17 @@ void AbsDiffNode::set_value(const double* params, int offset, const bool for_com } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->value_ptr(2 * offset + 1); + vp_1 = _feats[1]->value_ptr(2 * offset + 1, for_comp); } double* val_ptr; @@ -157,7 +157,7 @@ void AbsDiffNode::set_value(const double* params, int offset, const bool for_com } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::abs_diff(_n_samp, vp_0, vp_1, params[0], params[1], val_ptr); @@ -174,21 +174,21 @@ void AbsDiffNode::set_test_value(const double* params, int offset, const bool fo } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->test_value_ptr(2 * offset + 1); + vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp); } allowed_op_funcs::abs_diff( - _n_test_samp, vp_0, vp_1, params[0], params[1], node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + _n_test_samp, vp_0, vp_1, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.cpp index 88697fb18b897587e3ef0b975eaba21bff9f9585..f6fd65cecc41d270f7e4158528f74581e6248039 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.cpp @@ -142,18 +142,26 @@ void AddNode::update_div_mult_leaves(std::map<std::string, double>& div_mult_lea void AddNode::set_value(int offset, const bool for_comp) const { double* val_ptr; - if(_selected && (offset == -1)) + bool is_root = (offset == -1); + if(_selected && is_root) { - offset += (offset == -1); + offset += is_root; val_ptr = node_value_arrs::get_d_matrix_ptr(_d_mat_ind); } else { - offset += (offset == -1); + offset += is_root; val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp); } - allowed_op_funcs::add(_n_samp, _feats[0]->value_ptr(2 * offset, for_comp), _feats[1]->value_ptr(2 * offset + 1, for_comp), 1.0, 0.0, val_ptr); + allowed_op_funcs::add( + _n_samp, + _feats[0]->value_ptr(2 * offset, for_comp), + _feats[1]->value_ptr(2 * offset + 1, for_comp), + 1.0, + 0.0, + val_ptr + ); } void AddNode::set_test_value(int offset, const bool for_comp) const diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.hpp index addb49c0f2e58f48e237bed353304336d0609357..9e1bc382fb9776a60f3285c0f3cdc79008d89ba7 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/add.hpp @@ -241,7 +241,7 @@ public: inline std::string get_latex_expr(const double* params, const int depth=1) const { return fmt::format( - "\\left({} + {:.3}*{}\\right)", + "\\left({} + {:.3}{}\\right)", (depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->get_latex_expr(params + _feats[1]->n_params() + 2, depth + 1) : _feats[0]->get_latex_expr()), params[0], (depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->get_latex_expr(params + 2, depth + 1) : _feats[0]->get_latex_expr()) diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.cpp index f15c585e6f50eecc20fec6c15746e3921d454d09..ff048f83e0ec3959f71e80aaaa8ed7b792828229 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/add/parameterized_add.cpp @@ -100,17 +100,17 @@ void AddNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->value_ptr(2 * offset + 1); + vp_1 = _feats[1]->value_ptr(2 * offset + 1, for_comp); } double* val_ptr; @@ -120,7 +120,7 @@ void AddNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::add(_n_samp, vp_0, vp_1, params[0], params[1], val_ptr); @@ -137,17 +137,17 @@ void AddNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->test_value_ptr(2 * offset + 1); + vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp); } allowed_op_funcs::add( @@ -156,7 +156,7 @@ void AddNode::set_test_value(const double* params, int offset, const bool for_co vp_1, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.cpp index 67f5a7e00929c467874f9d9a289e215ad8a2df0c..7405f7a4a6ae17c234ef280c5871a05efea6a1ac 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cb/parameterized_cube.cpp @@ -134,7 +134,7 @@ void CbNode::set_value(const double* params, int offset, const bool for_comp, co } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -144,7 +144,7 @@ void CbNode::set_value(const double* params, int offset, const bool for_comp, co } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::cb(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -161,15 +161,15 @@ void CbNode::set_test_value(const double* params, int offset, const bool for_com } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::cb( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.cpp index 014cbe730c8f11dbcf2e3e9f38fa420851d411b0..8004b651d940ca801cc4a67c1d3163506b693a64 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cbrt/parameterized_cube_root.cpp @@ -121,7 +121,7 @@ void CbrtNode::set_value(const double* params, int offset, const bool for_comp, } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -131,7 +131,7 @@ void CbrtNode::set_value(const double* params, int offset, const bool for_comp, } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::cbrt(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -147,15 +147,15 @@ void CbrtNode::set_test_value(const double* params, int offset, const bool for_c } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::cbrt( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.cpp index 6fa600851a6e5ce89c60fec0ea26112aa9fd2b55..1e021e0e277bfaaae4b8210759394bb7f762d4bb 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/cos/parameterized_cos.cpp @@ -120,7 +120,7 @@ void CosNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -130,7 +130,7 @@ void CosNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::cos(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -147,15 +147,15 @@ void CosNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::cos( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.cpp index 965c559cc42d27cb771d40d4ca794b956abfa5ec..5cbf5402e41e3e6bdbca03292dc782cd21c54582 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/div/parameterized_divide.cpp @@ -127,17 +127,17 @@ void DivNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->value_ptr(2 * offset + 1); + vp_1 = _feats[1]->value_ptr(2 * offset + 1, for_comp); } double* val_ptr; @@ -147,7 +147,7 @@ void DivNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::div(_n_samp, vp_0, vp_1, params[0], params[1], val_ptr); @@ -164,17 +164,17 @@ void DivNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->test_value_ptr(2 * offset + 1); + vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp); } allowed_op_funcs::div( _n_test_samp, @@ -182,7 +182,7 @@ void DivNode::set_test_value(const double* params, int offset, const bool for_co vp_1, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.cpp index be8cad63d0a8a497a1f9dc14778c5b7d9e091e2d..406f9a1f4caab1842c5e22bb4e9ae979c47c1fe3 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/exp/parameterized_exponential.cpp @@ -132,7 +132,7 @@ void ExpNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -142,7 +142,7 @@ void ExpNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::exp(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -159,15 +159,15 @@ void ExpNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::exp( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.cpp index 2c1dd7a18b9ee31215368de9e4b31711ad898c44..fc14efc3e708889f38e162adba61fb8eccb11175 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/inv/parameterized_inverse.cpp @@ -128,7 +128,7 @@ void InvNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -138,7 +138,7 @@ void InvNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::inv(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -155,10 +155,10 @@ void InvNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } - allowed_op_funcs::inv(_n_test_samp, vp_0, params[0], params[1], node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false)); + allowed_op_funcs::inv(_n_test_samp, vp_0, params[0], params[1], node_value_arrs::access_param_storage_test(rung(), offset, for_comp)); } void InvNode::set_bounds(double* lb, double* ub, const int depth) const diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.cpp index 6f159b1b58e0afad164b0fc6efc3ea1269e8202d..55f10032679704be4fb1ef438f439c31045d0368 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/log/parameterized_log.cpp @@ -156,7 +156,7 @@ void LogNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -166,7 +166,7 @@ void LogNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::log(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -182,15 +182,15 @@ void LogNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::log( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.cpp index 05a8cfc0f8b7c96b799204bc3f449db97ee60fbf..b54761adf3e7c2264fb093587e9b20fa6a515b00 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/mult/parameterized_multiply.cpp @@ -99,17 +99,17 @@ void MultNode::set_value(const double* params, int offset, const bool for_comp, } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->value_ptr(2 * offset + 1); + vp_1 = _feats[1]->value_ptr(2 * offset + 1, for_comp); } double* val_ptr; @@ -119,7 +119,7 @@ void MultNode::set_value(const double* params, int offset, const bool for_comp, } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::mult(_n_samp, vp_0, vp_1, params[0], params[1], val_ptr); @@ -136,17 +136,17 @@ void MultNode::set_test_value(const double* params, int offset, const bool for_c } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->test_value_ptr(2 * offset + 1); + vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp); } allowed_op_funcs::mult( @@ -155,7 +155,7 @@ void MultNode::set_test_value(const double* params, int offset, const bool for_c vp_1, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.cpp index dc77ae48d455c8f9c714d7aeffa5d2e2a650933d..7fd8a2daee7963c94253dddef10c282c65a01473 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/neg_exp/parameterized_negative_exponential.cpp @@ -132,7 +132,7 @@ void NegExpNode::set_value(const double* params, int offset, const bool for_comp } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -142,7 +142,7 @@ void NegExpNode::set_value(const double* params, int offset, const bool for_comp } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::neg_exp(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -158,15 +158,15 @@ void NegExpNode::set_test_value(const double* params, int offset, const bool for } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::neg_exp( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.cpp index 69f3a8b9f5188f581dbca776fd3af9f6e8377865..20da40a77a16d3f02edce3d764d82a78dd0ec690 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sin/parameterized_sin.cpp @@ -120,7 +120,7 @@ void SinNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -130,7 +130,7 @@ void SinNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::sin(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -146,15 +146,15 @@ void SinNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::sin( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.cpp index 9dc34377b1fed821f258d9e709c27d93efeb259c..7a47dd573e16ed74629ada7e05e93504fd42e263 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/six_pow/parameterized_sixth_power.cpp @@ -135,7 +135,7 @@ void SixPowNode::set_value(const double* params, int offset, const bool for_comp } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -145,7 +145,7 @@ void SixPowNode::set_value(const double* params, int offset, const bool for_comp } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::sixth_pow(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -161,15 +161,15 @@ void SixPowNode::set_test_value(const double* params, int offset, const bool for } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::sixth_pow( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.cpp index a46eedb73e06fb60c6e10b2df7e325f71796e55a..3458c2dabeec8e7799b62a1317c1a6f3390506ee 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sq/parameterized_square.cpp @@ -126,7 +126,7 @@ void SqNode::set_value(const double* params, int offset, const bool for_comp, co } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -136,7 +136,7 @@ void SqNode::set_value(const double* params, int offset, const bool for_comp, co } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::sq(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -152,15 +152,15 @@ void SqNode::set_test_value(const double* params, int offset, const bool for_com } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::sq( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.cpp index abd46324d6c709491165cc626f2088fce6f75880..7d1d548f37acaf79c72b9ee4f1ad7907198703dc 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/parameterized_square_root.cpp @@ -152,7 +152,7 @@ void SqrtNode::set_value(const double* params, int offset, const bool for_comp, } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* val_ptr; @@ -162,7 +162,7 @@ void SqrtNode::set_value(const double* params, int offset, const bool for_comp, } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::sqrt(_n_samp, vp_0, params[0], params[1], val_ptr); @@ -178,15 +178,15 @@ void SqrtNode::set_test_value(const double* params, int offset, const bool for_c } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } allowed_op_funcs::sqrt( _n_test_samp, - _feats[0]->test_value_ptr(params + 2, 2 * offset), + vp_0, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.hpp index 4f64e4bfa82b9f46dd9a5288861f3c39bcb83219..3206b869216a3112f51df4a2a705d37157ee3dae 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sqrt/square_root.hpp @@ -215,7 +215,8 @@ public: inline std::string expr(const double* params, const int depth=1) const { return fmt::format( - "(sqrt({}{:+11.6e}))", + "(sqrt({:.1f}*{}{:+11.6e}))", + params[0], (depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->expr(params + 2, depth + 1) : _feats[0]->expr()), params[1] ); @@ -231,7 +232,8 @@ public: inline std::string get_latex_expr(const double* params, const int depth=1) const { return fmt::format( - "\\left(\\sqrt{{ {}{:+8.3e} }}\\right)", + "\\left(\\sqrt{{ {:.1f}{}{:+8.3e} }}\\right)", + params[0], (depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->get_latex_expr(params + 2, depth + 1) : _feats[0]->get_latex_expr()), params[1] ); @@ -247,7 +249,8 @@ public: inline std::string matlab_fxn_expr(const double* params, const int depth=1) const { return fmt::format( - "sqrt({}{:+11.6e})", + "sqrt({:.1f}.*{}{:+11.6e})", + params[0], (depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->matlab_fxn_expr(params + 2, depth + 1) : _feats[0]->matlab_fxn_expr()), params[1] ); diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.cpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.cpp index ecd5c318f5eaf64903423d0abaa77c706c53ed49..af894157c879844da4bcebd81964ec741acd3102 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.cpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/parameterized_subtract.cpp @@ -100,17 +100,17 @@ void SubNode::set_value(const double* params, int offset, const bool for_comp, c } else { - vp_0 = _feats[0]->value_ptr(2 * offset); + vp_0 = _feats[0]->value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->value_ptr(2 * offset + 1); + vp_1 = _feats[1]->value_ptr(2 * offset + 1, for_comp); } double* val_ptr; @@ -120,7 +120,7 @@ void SubNode::set_value(const double* params, int offset, const bool for_comp, c } else { - val_ptr = node_value_arrs::get_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false); + val_ptr = node_value_arrs::access_param_storage(rung(), offset, for_comp); } allowed_op_funcs::sub(_n_samp, vp_0, vp_1, params[0], params[1], val_ptr); @@ -137,17 +137,17 @@ void SubNode::set_test_value(const double* params, int offset, const bool for_co } else { - vp_0 = _feats[0]->test_value_ptr(2 * offset); + vp_0 = _feats[0]->test_value_ptr(2 * offset, for_comp); } double* vp_1; if(depth < nlopt_wrapper::MAX_PARAM_DEPTH) { - vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, depth + 1); + vp_1 = _feats[1]->test_value_ptr(params + 2, 2 * offset + 1, for_comp, depth + 1); } else { - vp_1 = _feats[1]->test_value_ptr(2 * offset + 1); + vp_1 = _feats[1]->test_value_ptr(2 * offset + 1, for_comp); } allowed_op_funcs::sub( _n_test_samp, @@ -155,7 +155,7 @@ void SubNode::set_test_value(const double* params, int offset, const bool for_co vp_1, params[0], params[1], - node_value_arrs::get_test_value_ptr(_arr_ind, _feat_ind, rung(), offset, for_comp, false) + node_value_arrs::access_param_storage_test(rung(), offset, for_comp) ); } diff --git a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.hpp b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.hpp index 8e3ca9129ec544ed82c55553bee21020891be80f..9ec532c6a5346ce4e1ec8a7f60553de946822557 100644 --- a/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.hpp +++ b/src/feature_creation/node/operator_nodes/allowed_operator_nodes/sub/subtract.hpp @@ -245,7 +245,7 @@ public: inline std::string get_latex_expr(const double* params, const int depth=1) const { return fmt::format( - "\\left({} - \\left({:.3e}*{}\\right)\\right)", + "\\left({} - \\left({:.3e}{}\\right)\\right)", (depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->get_latex_expr(params + _feats[1]->n_params() + 2, depth + 1) : _feats[0]->get_latex_expr()), params[0], (depth < nlopt_wrapper::MAX_PARAM_DEPTH ? _feats[0]->get_latex_expr(params + 2, depth + 1) : _feats[0]->get_latex_expr()) 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 9ecd3de95f3f7ed307caa17a744e83eeafbf3c19..6155fad844dbb59a5aa5591b69843b0e30f680db 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.cpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.cpp @@ -7,6 +7,7 @@ int node_value_arrs::N_RUNGS_STORED = 0; int node_value_arrs::N_SAMPLES_TEST = 0; int node_value_arrs::MAX_N_THREADS = omp_get_max_threads(); int node_value_arrs::N_OP_SLOTS = 0; +int node_value_arrs::N_PARAM_OP_SLOTS = 0; int node_value_arrs::MAX_RUNG = 0; std::vector<int> node_value_arrs::TEMP_STORAGE_REG; @@ -15,13 +16,22 @@ std::vector<int> node_value_arrs::TEMP_STORAGE_TEST_REG; std::vector<int> node_value_arrs::TASK_SZ_TRAIN; std::vector<int> node_value_arrs::TASK_SZ_TEST; +std::vector<double> node_value_arrs::PARAM_STORAGE_ARR; +std::vector<double> node_value_arrs::PARAM_STORAGE_TEST_ARR; std::vector<double> node_value_arrs::D_MATRIX; std::vector<double> node_value_arrs::VALUES_ARR; std::vector<double> node_value_arrs::TEST_VALUES_ARR; std::vector<double> node_value_arrs::TEMP_STORAGE_ARR; std::vector<double> node_value_arrs::TEMP_STORAGE_TEST_ARR; -void node_value_arrs::initialize_values_arr(const int n_samples, const int n_samples_test, const int n_primary_feat, const int max_rung, const bool set_task_sz) +void node_value_arrs::initialize_values_arr( + const int n_samples, + const int n_samples_test, + const int n_primary_feat, + const int max_rung, + const bool set_task_sz, + const bool use_params +) { if(max_rung < 0) { @@ -58,9 +68,20 @@ void node_value_arrs::initialize_values_arr(const int n_samples, const int n_sam TEMP_STORAGE_TEST_ARR = std::vector<double>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES_TEST); TEMP_STORAGE_TEST_REG = std::vector<int>(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1), -1); + + if(use_params) + { + initialize_param_storage(); + } } -void node_value_arrs::initialize_values_arr(const std::vector<int> task_sz_train, const std::vector<int> task_sz_test, const int n_primary_feat, const int max_rung) +void node_value_arrs::initialize_values_arr( + const std::vector<int> task_sz_train, + const std::vector<int> task_sz_test, + const int n_primary_feat, + const int max_rung, + const bool use_params +) { TASK_SZ_TRAIN = task_sz_train; TASK_SZ_TEST = task_sz_test; @@ -70,10 +91,19 @@ void node_value_arrs::initialize_values_arr(const std::vector<int> task_sz_train std::accumulate(task_sz_test.begin(), task_sz_test.end(), 0), n_primary_feat, max_rung, - false + false, + use_params ); } +void node_value_arrs::initialize_param_storage() +{ + N_PARAM_OP_SLOTS = 2 * (static_cast<int>(std::pow(2, MAX_RUNG)) - 1); + + PARAM_STORAGE_ARR = std::vector<double>(N_SAMPLES * (N_PARAM_OP_SLOTS + 1) * MAX_N_THREADS); + PARAM_STORAGE_TEST_ARR = std::vector<double>(N_SAMPLES_TEST * (N_PARAM_OP_SLOTS + 1) * MAX_N_THREADS); +} + void node_value_arrs::set_task_sz_train(const std::vector<int> task_sz_train) { if(std::accumulate(task_sz_train.begin(), task_sz_train.end(), 0) != N_SAMPLES) @@ -114,7 +144,7 @@ void node_value_arrs::resize_values_arr(const int n_dims, const int n_feat, cons if(use_temp) { - N_OP_SLOTS = 2 * std::max(1, (static_cast<int>(std::pow(2, MAX_RUNG - N_RUNGS_STORED)) - 1)); + N_OP_SLOTS = 2 * (static_cast<int>(std::pow(2, MAX_RUNG - N_RUNGS_STORED)) - 1); TEMP_STORAGE_ARR.resize(MAX_N_THREADS * (N_OP_SLOTS * N_STORE_FEATURES + 1) * N_SAMPLES); TEMP_STORAGE_ARR.shrink_to_fit(); @@ -143,11 +173,10 @@ double* node_value_arrs::get_value_ptr( const unsigned long int feat_ind, const int rung, const int offset, - const bool for_comp, - const bool modify_reg + const bool for_comp ) { - if(modify_reg && (rung <= N_RUNGS_STORED)) + if(rung <= N_RUNGS_STORED) { if(arr_ind > N_STORE_FEATURES) { @@ -157,7 +186,7 @@ double* node_value_arrs::get_value_ptr( } int op_slot = get_op_slot(rung, offset, for_comp); - temp_storage_reg(arr_ind, op_slot) = feat_ind * modify_reg - (!modify_reg); + temp_storage_reg(arr_ind, op_slot) = feat_ind; return access_temp_storage( (arr_ind % N_STORE_FEATURES) + (op_slot % N_OP_SLOTS) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1) ); @@ -168,11 +197,10 @@ double* node_value_arrs::get_test_value_ptr( const unsigned long int feat_ind, const int rung, const int offset, - const bool for_comp, - const bool modify_reg + const bool for_comp ) { - if(modify_reg && (rung <= N_RUNGS_STORED)) + if(rung <= N_RUNGS_STORED) { if(arr_ind > N_STORE_FEATURES) { @@ -182,7 +210,7 @@ double* node_value_arrs::get_test_value_ptr( } int op_slot = get_op_slot(rung, offset, for_comp); - temp_storage_test_reg(arr_ind, op_slot) = feat_ind * modify_reg - (!modify_reg); + temp_storage_test_reg(arr_ind, op_slot) = feat_ind; return access_temp_storage_test( (arr_ind % N_STORE_FEATURES) + (op_slot % N_OP_SLOTS) * N_STORE_FEATURES + omp_get_thread_num() * (N_STORE_FEATURES * N_OP_SLOTS + 1) ); 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 a0b1039c576704f794ffa1e62796fcd813a05af6..61f9748b6b8f415280e7aa2e2fba67870be2fae5 100644 --- a/src/feature_creation/node/value_storage/nodes_value_containers.hpp +++ b/src/feature_creation/node/value_storage/nodes_value_containers.hpp @@ -28,9 +28,11 @@ namespace node_value_arrs extern std::vector<double> TEMP_STORAGE_TEST_ARR; //!< Array to temporarily store feature test data extern std::vector<double> TEST_VALUES_ARR; //!< Value of the stored features test data extern std::vector<double> D_MATRIX; //!< The descriptor matrix + extern std::vector<double> PARAM_STORAGE_ARR; //!< Array to store parameterized feature values + extern std::vector<double> PARAM_STORAGE_TEST_ARR; //!< Array to store parameterized feature values for the test set + extern std::vector<int> TEMP_STORAGE_REG; //!< Register to see which feature is stored in each slot for the training data extern std::vector<int> TEMP_STORAGE_TEST_REG; //!< Register to see which feature is stored in each slot for the test data - extern std::vector<int> TASK_SZ_TRAIN; //!< Number of training samples per task extern std::vector<int> TASK_SZ_TEST; //!< Number of test sample per task @@ -41,6 +43,7 @@ namespace node_value_arrs extern int N_RUNGS_STORED; //!< Number of rungs with values stored extern int MAX_N_THREADS; //!< Get the maximum number of threads possible extern int N_OP_SLOTS; //!< The number of possible operator slots + extern int N_PARAM_OP_SLOTS; //!< The maximum number of possible operator slots extern int MAX_RUNG; //!< The maximum rung for all features /** @@ -52,8 +55,16 @@ namespace node_value_arrs * @param n_primary_feat Number of primary features * @param max_rung Largest rung of a feature * @param set_test_task_sz If True reset the task_sz vectors + * @param use_params If True set up parameter storage */ - void initialize_values_arr(const int n_samples, const int n_samples_test, const int n_primary_feat, const int max_rung, const bool et_task_sz); + void initialize_values_arr( + const int n_samples, + const int n_samples_test, + const int n_primary_feat, + const int max_rung, + const bool set_task_sz, + const bool use_params + ); /** * @brief Initialize the node value arrays @@ -63,10 +74,16 @@ namespace node_value_arrs * @param n_samples_test Number of test samples for each feature * @param n_primary_feat Number of primary features * @param max_rung Largest rung of a feature + * @param use_params If True set up parameter storage */ - inline void initialize_values_arr(const int n_samples, const int n_samples_test, const int n_primary_feat, const int max_rung) + inline void initialize_values_arr( + const int n_samples, + const int n_samples_test, + const int n_primary_feat, + const int max_rung + ) { - initialize_values_arr(n_samples, n_samples_test, n_primary_feat, max_rung, true); + initialize_values_arr(n_samples, n_samples_test, n_primary_feat, max_rung, true, false); } /** @@ -77,8 +94,15 @@ namespace node_value_arrs * @param task_sz_test Number of test sample per task * @param n_primary_feat Number of primary features * @param max_rung Largest rung of a feature + * @param use_params If True set up parameter storage */ - void initialize_values_arr(const std::vector<int> task_sz_train, const std::vector<int> task_sz_test, const int n_primary_feat, const int max_rung); + void initialize_values_arr( + const std::vector<int> task_sz_train, + const std::vector<int> task_sz_test, + const int n_primary_feat, + const int max_rung, + const bool use_params + ); /** * @brief Resize the node value arrays @@ -90,6 +114,11 @@ namespace node_value_arrs */ void resize_values_arr(const int n_dims, const int n_feat, const bool use_temp); + /** + * @brief Initialize the parameter storage array + */ + void initialize_param_storage(); + /** * @brief Initialize the descriptor matrix * @details Initialize an empty descriptor matrix @@ -133,6 +162,20 @@ namespace node_value_arrs return std::abs(N_OP_SLOTS / (1 + !for_comp) - static_cast<int>(std::pow(2, MAX_RUNG - rung)) - offset); } + /** + * @brief Get the parameter operator slot associated with a given rung/offset + * + * @param rung Rung of the feature + * @param offset Offset used to prevent overwrites + * @param for_comp If true get a slot dedicated to comparing features + * + * @return The operator slot to use + */ + inline int get_param_op_slot(const int rung, const int offset, const bool for_comp) + { + return std::abs(N_PARAM_OP_SLOTS / (1 + !for_comp) - static_cast<int>(std::pow(2, MAX_RUNG - rung)) - offset); + } + /** * @brief Get a reference slot/feature register of the training data * @@ -237,6 +280,44 @@ namespace node_value_arrs */ inline double* access_temp_storage_test(const unsigned long int slot){return &TEMP_STORAGE_TEST_ARR[slot*N_SAMPLES_TEST];} + /** + * @brief Access the param storage array + * + * @param rung Rung of the feature + * @param offset(int) the offset for temporary storage access + * @param for_comp If true get a slot dedicated to comparing features + * @return pointer to the correct element of the PARAM_STORAGE_ARR + */ + inline double* access_param_storage(const int rung=0, const int offset=0, const bool for_comp=false) + { + return &PARAM_STORAGE_ARR[ + N_SAMPLES * + ( + (get_param_op_slot(rung, offset, for_comp) % N_PARAM_OP_SLOTS) + + omp_get_thread_num() * (N_PARAM_OP_SLOTS + 1) + ) + ]; + } + + /** + * @brief Access the param storage array for the test set + * + * @param rung Rung of the feature + * @param offset(int) the offset for temporary storage access + * @param for_comp If true get a slot dedicated to comparing features + * @return pointer to the correct element of the PARAM_STORAGE_ARR + */ + inline double* access_param_storage_test(const int rung=0, const int offset=0, const bool for_comp=false) + { + return &PARAM_STORAGE_TEST_ARR[ + N_SAMPLES_TEST * + ( + (get_param_op_slot(rung, offset, for_comp) % N_PARAM_OP_SLOTS) + + omp_get_thread_num() * (N_PARAM_OP_SLOTS + 1) + ) + ]; + } + /** * @brief Get a Node's value_ptr * @@ -245,7 +326,6 @@ namespace node_value_arrs * @param rung Rung of the feature * @param offset(int) the offset for temporary storage access * @param for_comp If true get a slot dedicated to comparing features - * @param modify_reg If true modify the register of the array (if false set the register to -1) * * @return The value pointer */ @@ -254,8 +334,7 @@ namespace node_value_arrs const unsigned long int feat_ind, const int rung=0, const int offset=0, - const bool for_comp=false, - const bool modify_reg=true + const bool for_comp=false ); /** @@ -266,7 +345,6 @@ namespace node_value_arrs * @param rung Rung of the feature * @param offset(int) the offset for temporary storage access * @param for_comp If true get a slot dedicated to comparing features - * @param modify_reg If true modify the register of the array (if false set the register to -1) * * @return The value pointer */ @@ -275,8 +353,7 @@ namespace node_value_arrs const unsigned long int feat_ind, const int rung=0, const int offset=0, - const bool for_comp=false, - const bool modify_reg=true + const bool for_comp=false ); /** diff --git a/src/inputs/InputParser.cpp b/src/inputs/InputParser.cpp index c24131c6c2e32cc24ca65cd55c7df14ac64350ca..4deb53b9752c5d8ec9b114417a76584f333a8ae6 100644 --- a/src/inputs/InputParser.cpp +++ b/src/inputs/InputParser.cpp @@ -376,7 +376,11 @@ void InputParser::generate_feature_space( } // Initialize the central data storage area - node_value_arrs::initialize_values_arr(_prop_train.size(), _prop_test.size(), headers.size(), _max_rung); + #ifdef PARAMETERIZE + node_value_arrs::initialize_values_arr(_task_sizes_train, _task_sizes_test, headers.size(), _max_rung, _param_opset.size() > 0); + #else + node_value_arrs::initialize_values_arr(_task_sizes_train, _task_sizes_test, headers.size(), _max_rung, false); + #endif // Create \Phi_0 of primary features std::vector<node_ptr> phi_0; diff --git a/src/python/__init__.py b/src/python/__init__.py index 3022a3445816ef1dda3f9487e3580a2674ceb36e..3f05b19c0fcdd111924dd35de727f19830f0c10f 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -182,6 +182,7 @@ def generate_phi_0_from_csv( units = list([get_unit(col) for col in columns]) initialize_values_arr(len(train_inds), len(leave_out_inds), len(columns), max_rung) + initialize_param_storage() test_values = df.to_numpy().T[:, leave_out_inds] values = df.to_numpy().T[:, train_inds] diff --git a/src/python/bindings_docstring_keyed.cpp b/src/python/bindings_docstring_keyed.cpp index c127c339d37a928b91a3d2d44d4cb29ab50200c7..059bd677e66c021bfac7480dac2491d0b0ca9a19 100644 --- a/src/python/bindings_docstring_keyed.cpp +++ b/src/python/bindings_docstring_keyed.cpp @@ -83,6 +83,8 @@ void sisso::register_all() NLOptimizerClassification(*get_class_optimizer_arr_list)(np::ndarray, py::list, int, int, bool) = &nlopt_wrapper::get_class_optimizer; NLOptimizerClassification(*get_class_optimizer_arr_arr)(np::ndarray, np::ndarray, int, int, bool) = &nlopt_wrapper::get_class_optimizer; + def("initialize_param_storage", &node_value_arrs::initialize_param_storage); + def("get_reg_optimizer", get_reg_optimizer_list_list, "@DocString_nlopt_wrapper_get_reg_optimizer_list_list"); def("get_reg_optimizer", get_reg_optimizer_list_arr, "@DocString_nlopt_wrapper_get_reg_optimizer_list_arr"); def("get_reg_optimizer", get_reg_optimizer_arr_list, "@DocString_nlopt_wrapper_get_reg_optimizer_arr_list"); diff --git a/src/python/feature_creation/FeatureSpace.cpp b/src/python/feature_creation/FeatureSpace.cpp index 15be757a2f642c95e528f879d490f30ac1c2f749..d47d1c1ff54cbe56a1a99d3d83991c4a9c4f2ada 100644 --- a/src/python/feature_creation/FeatureSpace.cpp +++ b/src/python/feature_creation/FeatureSpace.cpp @@ -265,6 +265,7 @@ FeatureSpace::FeatureSpace( { throw std::logic_error("The maximum parameter depth could not be determined from the file."); } + node_value_arrs::initialize_param_storage(); #endif _scores.resize(_n_feat); } @@ -372,6 +373,7 @@ FeatureSpace::FeatureSpace( { throw std::logic_error("The maximum parameter depth could not be determined from the file."); } + node_value_arrs::initialize_param_storage(); #endif _scores.resize(_n_feat); } diff --git a/src/utils/compare_features.cpp b/src/utils/compare_features.cpp index a2db02e8bf78c9ce5d9d8450598286b721953471..6f30b37a2e8f00ae3eca83929927e67b91adb45b 100644 --- a/src/utils/compare_features.cpp +++ b/src/utils/compare_features.cpp @@ -1,4 +1,5 @@ #include "utils/compare_features.hpp" +#include <iomanip> std::vector<double> comp_feats::CORR_CHECK; std::vector<double> comp_feats::RANK; std::vector<int> comp_feats::INDEX; @@ -63,7 +64,11 @@ bool comp_feats::valid_feature_against_selected_pearson_max_corr_1( { continue; } - if((base_val - std::abs(util_funcs::r(val_ptr, node_value_arrs::get_d_matrix_ptr(dd), n_samp, mean, stand_dev))) < 1.01e-8) + + double comp_value = ( + base_val - std::abs(util_funcs::r(val_ptr, node_value_arrs::get_d_matrix_ptr(dd), n_samp, mean, stand_dev)) + ); + if(std::abs(comp_value) < 1.0e-5) { return false; } @@ -91,7 +96,10 @@ bool comp_feats::valid_feature_against_selected_pearson_max_corr_1_feat_list( continue; } - if((base_val - std::abs(util_funcs::r(val_ptr, selected[ff]->value_ptr(-1, true), n_samp, mean, stand_dev))) < 1.01e-8) + double comp_value = ( + base_val - std::abs(util_funcs::r(val_ptr, selected[ff]->value_ptr(-1, true), n_samp, mean, stand_dev)) + ); + if(std::abs(comp_value) < 1.0e-5) { return false; } @@ -118,7 +126,10 @@ bool comp_feats::valid_feature_against_selected_pearson_max_corr_1_mpi_op( continue; } - if((base_val - std::abs(util_funcs::r(val_ptr, std::get<0>(feat_sc)->value_ptr(-1, true), n_samp, mean, stand_dev))) < 1.01e-8) + double comp_value = ( + base_val - std::abs(util_funcs::r(val_ptr, std::get<0>(feat_sc)->value_ptr(-1, true), n_samp, mean, stand_dev)) + ); + if(std::abs(comp_value) < 1.0e-5) { return false; } @@ -151,7 +162,10 @@ bool comp_feats::valid_feature_against_selected_pearson( continue; } - if((base_val - std::abs(util_funcs::r(val_ptr, node_value_arrs::get_d_matrix_ptr(dd), n_samp, mean, stand_dev))) < (1.0 - cross_cor_max + 1.01e-8)) + double comp_value = ( + base_val - std::abs(util_funcs::r(val_ptr, node_value_arrs::get_d_matrix_ptr(dd), n_samp, mean, stand_dev)) + ); + if(std::abs(comp_value) < (1.0 - cross_cor_max + 1.0e-5)) { is_valid = false; } @@ -174,7 +188,10 @@ bool comp_feats::valid_feature_against_selected_pearson_feat_list( for(auto& feat : selected) { - if((base_val - std::abs(util_funcs::r(val_ptr, feat->value_ptr(-1, true), n_samp, mean, stand_dev))) < (1.0 - cross_cor_max + 1.01e-8)) + double comp_value = ( + base_val - std::abs(util_funcs::r(val_ptr, feat->value_ptr(-1, true), n_samp, mean, stand_dev)) + ); + if(std::abs(comp_value) < (1.0 - cross_cor_max + 1.0e-5)) { return false; } @@ -196,7 +213,10 @@ bool comp_feats::valid_feature_against_selected_pearson_mpi_op( for(auto& feat_sc : out_vec) { - if((base_val - std::abs(util_funcs::r(val_ptr, std::get<0>(feat_sc)->value_ptr(-1, true), n_samp, mean, stand_dev))) < (1.0 - cross_cor_max + 1.01e-8)) + double comp_value = ( + base_val - std::abs(util_funcs::r(val_ptr, std::get<0>(feat_sc)->value_ptr(-1, true), n_samp, mean, stand_dev)) + ); + if(std::abs(comp_value) < (1.0 - cross_cor_max + 1.0e-5)) { return false; } @@ -235,7 +255,10 @@ bool comp_feats::valid_feature_against_selected_spearman_max_corr_1( // Rank the new variable and take the Pearson correlation of the rank variables (val_ptr rank still in &RANK[(omp_get_thread_num() * 4 + 2) * n_samp]) util_funcs::rank(node_value_arrs::get_d_matrix_ptr(dd), &RANK[omp_get_thread_num() * 4 * n_samp], &INDEX[omp_get_thread_num() * 2 * n_samp], n_samp); - if((base_val - std::abs(util_funcs::r(&RANK[omp_get_thread_num() * 4 * n_samp], &RANK[(omp_get_thread_num() * 4 + 2) * n_samp], n_samp))) < 1.01e-8) + double comp_value = ( + base_val - std::abs(util_funcs::r(&RANK[omp_get_thread_num() * 4 * n_samp], &RANK[(omp_get_thread_num() * 4 + 2) * n_samp], n_samp)) + ); + if(std::abs(comp_value) < 1.0e-5) { return false; } @@ -272,7 +295,10 @@ bool comp_feats::valid_feature_against_selected_spearman_max_corr_1_feat_list( // Rank the new variable and take the Pearson correlation of the rank variables (val_ptr rank still in &RANK[(omp_get_thread_num() * 4 + 2) * n_samp]) util_funcs::rank(selected[ff]->value_ptr(-1, true), &RANK[omp_get_thread_num() * 4 * n_samp], &INDEX[omp_get_thread_num() * 2 * n_samp], n_samp); - if((base_val - std::abs(util_funcs::r(&RANK[omp_get_thread_num() * 4 * n_samp], &RANK[(omp_get_thread_num() * 4 + 2) * n_samp], n_samp))) < 1.01e-8) + double comp_value = ( + base_val - std::abs(util_funcs::r(&RANK[omp_get_thread_num() * 4 * n_samp], &RANK[(omp_get_thread_num() * 4 + 2) * n_samp], n_samp)) + ); + if(std::abs(comp_value) < 1.0e-5) { return false; } @@ -313,7 +339,7 @@ bool comp_feats::valid_feature_against_selected_spearman_max_corr_1_mpi_op( base_val - std::abs(util_funcs::r(&RANK[omp_get_thread_num() * 4 * n_samp], &RANK[(omp_get_thread_num() * 4 + 2) * n_samp], n_samp)) ); - if(comp_value < cross_cor_max + 1.01e-8) + if(std::abs(comp_value) < cross_cor_max + 1.0e-5) { return false; } @@ -354,7 +380,7 @@ bool comp_feats::valid_feature_against_selected_spearman( double comp_value = ( base_val - std::abs(util_funcs::r(&RANK[omp_get_thread_num() * 4 * n_samp], &RANK[(omp_get_thread_num() * 4 + 2) * n_samp], n_samp)) ); - if(comp_value < cross_cor_max + 1.01e-8) + if(std::abs(comp_value) < cross_cor_max + 1.0e-5) { is_valid = false; } @@ -389,7 +415,7 @@ bool comp_feats::valid_feature_against_selected_spearman_feat_list( double comp_value = ( base_val - std::abs(util_funcs::r(&RANK[omp_get_thread_num() * 4 * n_samp], &RANK[(omp_get_thread_num() * 4 + 2) * n_samp], n_samp)) ); - if(comp_value < cross_cor_max + 1.01e-8) + if(std::abs(comp_value) < cross_cor_max + 1.0e-5) { return false; } @@ -424,7 +450,7 @@ bool comp_feats::valid_feature_against_selected_spearman_mpi_op( double comp_value = ( base_val - std::abs(util_funcs::r(&RANK[omp_get_thread_num() * 4 * n_samp], &RANK[(omp_get_thread_num() * 4 + 2) * n_samp], n_samp)) ); - if(comp_value < cross_cor_max + 1.01e-8) + if(std::abs(comp_value) < cross_cor_max + 1.0e-5) { return false; }