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

Bug fixes for new reparam setup

Index bugs and array filling issues fixed
parent 8eed2356
Branches
No related tags found
No related merge requests found
...@@ -731,29 +731,6 @@ void FeatureSpace::generate_feature_space() ...@@ -731,29 +731,6 @@ void FeatureSpace::generate_feature_space()
_phi.erase(_phi.begin() - del_inds[inds[ii]]); _phi.erase(_phi.begin() - del_inds[inds[ii]]);
} }
// Reorder features based on the number of parameters they have (none goes first)
std::vector<int> feat_n_params(_phi.size() - _start_gen.back());
std::transform(
_phi.begin() + _start_gen.back(),
_phi.end(),
feat_n_params.begin(),
[](node_ptr feat){return feat->n_params();}
);
inds = util_funcs::argsort<int>(feat_n_params);
next_phi.resize(feat_n_params.size());
std::copy_n(_phi.begin() + _start_gen.back(), feat_n_params.size(), next_phi.begin());
std::transform(
inds.begin(),
inds.end(),
_phi.begin() + _start_gen.back(),
[&next_phi](int ind){return next_phi[ind];}
);
// Set how many features have no parameters
_end_no_params.push_back(
std::count_if(feat_n_params.begin(), feat_n_params.end(), [](int n_param){return n_param == 0;})
);
// Reindex // Reindex
for(int ff = _start_gen.back(); ff < _phi.size(); ++ff) for(int ff = _start_gen.back(); ff < _phi.size(); ++ff)
{ {
...@@ -921,6 +898,37 @@ void FeatureSpace::generate_feature_space() ...@@ -921,6 +898,37 @@ void FeatureSpace::generate_feature_space()
_phi[ff]->set_test_value(); _phi[ff]->set_test_value();
} }
} }
#ifdef PARAMETERIZE
// Reorder features based on the number of parameters they have (none goes first)
std::vector<int> feat_n_params(_phi.size() - _start_gen.back());
std::transform(
_phi.begin() + _start_gen.back(),
_phi.end(),
feat_n_params.begin(),
[](node_ptr feat){return feat->n_params();}
);
inds = util_funcs::argsort<int>(feat_n_params);
next_phi.resize(feat_n_params.size());
std::copy_n(_phi.begin() + _start_gen.back(), feat_n_params.size(), next_phi.begin());
std::transform(
inds.begin(),
inds.end(),
_phi.begin() + _start_gen.back(),
[&next_phi](int ind){return next_phi[ind];}
);
int cur_ind = _start_gen.back();
std::for_each(
_phi.begin() + _start_gen.back(),
_phi.end(),
[&cur_ind](node_ptr feat){feat->reindex(cur_ind); ++cur_ind;}
);
// Set how many features have no parameters
_end_no_params.push_back(
std::count_if(feat_n_params.begin(), feat_n_params.end(), [](int n_param){return n_param == 0;})
);
#endif
} }
_n_feat = _phi.size(); _n_feat = _phi.size();
} }
... ...
......
...@@ -20,6 +20,8 @@ FeatureSpace::FeatureSpace( ...@@ -20,6 +20,8 @@ FeatureSpace::FeatureSpace(
): ):
_phi(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)), _phi(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)),
_phi_0(_phi), _phi_0(_phi),
_end_no_params(1, 0),
_start_gen_reparam(1, 0),
_allowed_param_ops(python_conv_utils::from_list<std::string>(allowed_param_ops)), _allowed_param_ops(python_conv_utils::from_list<std::string>(allowed_param_ops)),
_allowed_ops(python_conv_utils::from_list<std::string>(allowed_ops)), _allowed_ops(python_conv_utils::from_list<std::string>(allowed_ops)),
_prop(python_conv_utils::from_list<double>(prop)), _prop(python_conv_utils::from_list<double>(prop)),
...@@ -64,6 +66,8 @@ FeatureSpace::FeatureSpace( ...@@ -64,6 +66,8 @@ FeatureSpace::FeatureSpace(
): ):
_phi(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)), _phi(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)),
_phi_0(_phi), _phi_0(_phi),
_end_no_params(1, 0),
_start_gen_reparam(1, 0),
_allowed_param_ops(python_conv_utils::from_list<std::string>(allowed_param_ops)), _allowed_param_ops(python_conv_utils::from_list<std::string>(allowed_param_ops)),
_allowed_ops(python_conv_utils::from_list<std::string>(allowed_ops)), _allowed_ops(python_conv_utils::from_list<std::string>(allowed_ops)),
_prop(python_conv_utils::from_ndarray<double>(prop)), _prop(python_conv_utils::from_ndarray<double>(prop)),
...@@ -181,6 +185,7 @@ FeatureSpace::FeatureSpace( ...@@ -181,6 +185,7 @@ FeatureSpace::FeatureSpace(
_phi_0(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)), _phi_0(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)),
_prop(python_conv_utils::from_ndarray<double>(prop)), _prop(python_conv_utils::from_ndarray<double>(prop)),
_scores(py::len(phi_0), 0.0), _scores(py::len(phi_0), 0.0),
_start_gen(1, 0),
_task_sizes(python_conv_utils::from_list<int>(task_sizes)), _task_sizes(python_conv_utils::from_list<int>(task_sizes)),
_feature_space_file("feature_space/selected_features.txt"), _feature_space_file("feature_space/selected_features.txt"),
_feature_space_summary_file("feature_space/SIS_summary.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"),
...@@ -202,6 +207,7 @@ FeatureSpace::FeatureSpace( ...@@ -202,6 +207,7 @@ FeatureSpace::FeatureSpace(
mpi_reduce_op::set_op(_project_type, _cross_cor_max, _n_sis_select); mpi_reduce_op::set_op(_project_type, _cross_cor_max, _n_sis_select);
std::vector<node_ptr> phi_temp = str2node::phi_from_file(feature_file, _phi_0); std::vector<node_ptr> phi_temp = str2node::phi_from_file(feature_file, _phi_0);
phi_temp.insert(phi_temp.begin(), _phi_0.begin(), _phi_0.end());
_n_feat = phi_temp.size(); _n_feat = phi_temp.size();
_phi.resize(_n_feat); _phi.resize(_n_feat);
...@@ -251,6 +257,8 @@ FeatureSpace::FeatureSpace( ...@@ -251,6 +257,8 @@ FeatureSpace::FeatureSpace(
} }
} }
#ifdef PARAMETERIZE #ifdef PARAMETERIZE
_start_gen_reparam = {0};
_end_no_params = {0};
for(int rr = 1; rr < _max_phi; ++rr) for(int rr = 1; rr < _max_phi; ++rr)
{ {
nlopt_wrapper::MAX_PARAM_DEPTH = rr; nlopt_wrapper::MAX_PARAM_DEPTH = rr;
...@@ -275,6 +283,43 @@ FeatureSpace::FeatureSpace( ...@@ -275,6 +283,43 @@ FeatureSpace::FeatureSpace(
throw std::logic_error("The maximum parameter depth could not be determined from the file."); throw std::logic_error("The maximum parameter depth could not be determined from the file.");
} }
node_value_arrs::initialize_param_storage(); node_value_arrs::initialize_param_storage();
for(int rr = 1; rr <= _max_phi; ++rr)
{
int n_feat_in_rung = (rr < _max_phi ?_start_gen[rr + 1] : _phi.size()) - _start_gen[rr];
// Reorder features based on the number of parameters they have (none goes first)
std::vector<int> feat_n_params(n_feat_in_rung);
std::transform(
_phi.begin() + _start_gen[rr],
_phi.begin() + _start_gen[rr] + n_feat_in_rung,
feat_n_params.begin(),
[](node_ptr feat){return feat->n_params();}
);
std::vector<int> inds = util_funcs::argsort<int>(feat_n_params);
std::vector<node_ptr>phi_copy(n_feat_in_rung);
std::copy_n(_phi.begin() + _start_gen.back(), n_feat_in_rung, phi_copy.begin());
std::transform(
inds.begin(),
inds.end(),
_phi.begin() + _start_gen[rr],
[&phi_copy](int ind){return phi_copy[ind];}
);
// Reindex the features to match the sorted order
int cur_ind = _start_gen.back();
std::for_each(
_phi.begin() + _start_gen.back(),
_phi.begin() + _start_gen.back() + n_feat_in_rung,
[&cur_ind](node_ptr feat){feat->reindex(cur_ind); ++cur_ind;}
);
// Set how many features have no parameters
_end_no_params.push_back(
std::count_if(feat_n_params.begin(), feat_n_params.end(), [](int n_param){return n_param == 0;})
);
std::cout << "out" << std::endl;
}
#endif #endif
_scores.resize(_n_feat); _scores.resize(_n_feat);
} }
...@@ -291,6 +336,7 @@ FeatureSpace::FeatureSpace( ...@@ -291,6 +336,7 @@ FeatureSpace::FeatureSpace(
_phi_0(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)), _phi_0(python_conv_utils::shared_ptr_vec_from_list<Node, FeatureNode>(phi_0)),
_prop(python_conv_utils::from_list<double>(prop)), _prop(python_conv_utils::from_list<double>(prop)),
_scores(py::len(phi_0), 0.0), _scores(py::len(phi_0), 0.0),
_start_gen(1, 0),
_task_sizes(python_conv_utils::from_list<int>(task_sizes)), _task_sizes(python_conv_utils::from_list<int>(task_sizes)),
_feature_space_file("feature_space/selected_features.txt"), _feature_space_file("feature_space/selected_features.txt"),
_feature_space_summary_file("feature_space/SIS_summary.txt"), _feature_space_summary_file("feature_space/SIS_summary.txt"),
...@@ -311,6 +357,7 @@ FeatureSpace::FeatureSpace( ...@@ -311,6 +357,7 @@ FeatureSpace::FeatureSpace(
mpi_reduce_op::set_op(_project_type, _cross_cor_max, _n_sis_select); mpi_reduce_op::set_op(_project_type, _cross_cor_max, _n_sis_select);
std::vector<node_ptr> phi_temp = str2node::phi_from_file(feature_file, _phi_0); std::vector<node_ptr> phi_temp = str2node::phi_from_file(feature_file, _phi_0);
phi_temp.insert(phi_temp.begin(), _phi_0.begin(), _phi_0.end());
_n_feat = phi_temp.size(); _n_feat = phi_temp.size();
_phi.resize(_n_feat); _phi.resize(_n_feat);
...@@ -360,6 +407,8 @@ FeatureSpace::FeatureSpace( ...@@ -360,6 +407,8 @@ FeatureSpace::FeatureSpace(
} }
} }
#ifdef PARAMETERIZE #ifdef PARAMETERIZE
_start_gen_reparam = {0};
_end_no_params = {0};
for(int rr = 1; rr < _max_phi; ++rr) for(int rr = 1; rr < _max_phi; ++rr)
{ {
nlopt_wrapper::MAX_PARAM_DEPTH = rr; nlopt_wrapper::MAX_PARAM_DEPTH = rr;
...@@ -384,6 +433,43 @@ FeatureSpace::FeatureSpace( ...@@ -384,6 +433,43 @@ FeatureSpace::FeatureSpace(
throw std::logic_error("The maximum parameter depth could not be determined from the file."); throw std::logic_error("The maximum parameter depth could not be determined from the file.");
} }
node_value_arrs::initialize_param_storage(); node_value_arrs::initialize_param_storage();
for(int rr = 1; rr <= _max_phi; ++rr)
{
int n_feat_in_rung = (rr < _max_phi ?_start_gen[rr + 1] : _phi.size()) - _start_gen[rr];
// Reorder features based on the number of parameters they have (none goes first)
std::vector<int> feat_n_params(n_feat_in_rung);
std::transform(
_phi.begin() + _start_gen[rr],
_phi.begin() + _start_gen[rr] + n_feat_in_rung,
feat_n_params.begin(),
[](node_ptr feat){return feat->n_params();}
);
std::vector<int> inds = util_funcs::argsort<int>(feat_n_params);
std::vector<node_ptr>phi_copy(n_feat_in_rung);
std::copy_n(_phi.begin() + _start_gen.back(), n_feat_in_rung, phi_copy.begin());
std::transform(
inds.begin(),
inds.end(),
_phi.begin() + _start_gen[rr],
[&phi_copy](int ind){return phi_copy[ind];}
);
// Reindex the features to match the sorted order
int cur_ind = _start_gen.back();
std::for_each(
_phi.begin() + _start_gen.back(),
_phi.begin() + _start_gen.back() + n_feat_in_rung,
[&cur_ind](node_ptr feat){feat->reindex(cur_ind); ++cur_ind;}
);
// Set how many features have no parameters
_end_no_params.push_back(
std::count_if(feat_n_params.begin(), feat_n_params.end(), [](int n_param){return n_param == 0;})
);
}
#endif #endif
_scores.resize(_n_feat); _scores.resize(_n_feat);
} }
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment