Commit 7c50a993 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Move reordering of parameterized features to be before Broadcast

Prevent similar errors to what was seen with remove duplicates
parent 04ea60aa
......@@ -573,6 +573,45 @@ void FeatureSpace::generate_non_param_feats(
}
}
#ifdef PARAMETERIZE
int FeatureSpace::reorder_by_n_params(std::vector<node_ptr>& feat_set, int start)
{
std::cout << "in" << std::endl;
std::vector<int> feat_n_params(feat_set.size() - start);
std::cout << "transform 1" << std::endl;
std::transform(
feat_set.begin() + start,
feat_set.end(),
feat_n_params.begin(),
[](node_ptr feat){return feat->n_params();}
);
std::cout << "inds 1" << std::endl;
std::vector<int> inds = util_funcs::argsort<int>(feat_n_params);
std::vector<node_ptr> feat_set_copy(feat_n_params.size());
std::copy_n(feat_set.begin() + start, feat_n_params.size(), feat_set_copy.begin());
std::cout << "transform 2" << std::endl;
std::transform(
inds.begin(),
inds.end(),
feat_set.begin() + start,
[&feat_set_copy](int ind){return feat_set_copy[ind];}
);
for(int ff = start; ff < feat_set.size(); ++ff)
{
feat_set[ff]->reindex(ff);
}
// Set how many features have no parameters
std::cout << "ret" << std::endl;
return start + std::count_if(
feat_n_params.begin(),
feat_n_params.end(),
[](int n_param){return n_param == 0;}
);
}
#endif
void FeatureSpace::remove_duplicate_features(std::vector<node_ptr>& feat_set, int start)
{
std::vector<double> scores(feat_set.size(), 0.0);
......@@ -766,6 +805,14 @@ void FeatureSpace::generate_feature_space(
{
remove_duplicate_features(feat_set, start_rung.back());
}
#ifdef PARAMETERIZE
if(!reparam)
{
int no_param_sz = reorder_by_n_params(feat_set, start_rung.back());
mpi::broadcast(*_mpi_comm, no_param_sz, 0);
_end_no_params.push_back(no_param_sz);
}
#endif
new_phi_size = feat_set.size();
mpi::broadcast(*_mpi_comm, new_phi_size, 0);
mpi::broadcast(*_mpi_comm, &feat_set[start_rung.back()], new_phi_size - start_rung.back(), 0);
......@@ -773,8 +820,17 @@ void FeatureSpace::generate_feature_space(
else
{
mpi::gather(*_mpi_comm, next_phi, 0);
mpi::broadcast(*_mpi_comm, new_phi_size, 0);
#ifdef PARAMETERIZE
if(!reparam)
{
int no_param_sz;
mpi::broadcast(*_mpi_comm, no_param_sz, 0);
_end_no_params.push_back(no_param_sz);
}
#endif
mpi::broadcast(*_mpi_comm, new_phi_size, 0);
feat_set.resize(new_phi_size);
mpi::broadcast(*_mpi_comm, &feat_set[start_rung.back()], new_phi_size - start_rung.back(), 0);
}
......@@ -946,40 +1002,6 @@ void FeatureSpace::generate_feature_space(
feat_set[ff]->set_test_value();
}
}
#ifdef PARAMETERIZE
if(!reparam)
{
// Reorder features based on the number of parameters they have (none goes first)
std::vector<int> feat_n_params(feat_set.size() - start_rung.back());
std::transform(
feat_set.begin() + start_rung.back(),
feat_set.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(feat_set.begin() + start_rung.back(), feat_n_params.size(), next_phi.begin());
std::transform(
inds.begin(),
inds.end(),
feat_set.begin() + start_rung.back(),
[&next_phi](int ind){return next_phi[ind];}
);
for(int ff = start_rung.back(); ff < feat_set.size(); ++ff)
{
feat_set[ff]->reindex(ff);
feat_set[ff]->set_value();
}
// Set how many features have no parameters
_end_no_params.push_back(
start_rung.back() +
std::count_if(feat_n_params.begin(), feat_n_params.end(), [](int n_param){return n_param == 0;})
);
}
#endif
}
}
......
......@@ -154,6 +154,16 @@ public:
*/
void remove_duplicate_features(std::vector<node_ptr>& feat_set, int start);
#ifdef PARAMETERIZE
/**
* @brief Reorder features based on the number of parameters they have (smallest to largest)
*
* @param feat_set Feature space to remove the duplicates from
* @param start The index to start the removal from
*/
int reorder_by_n_params(std::vector<node_ptr>& feat_set, int start);
#endif
/**
* @brief Populate _phi using _phi_0 and the allowed operators up to (_max_rung - _n_rung_generate)^th rung
*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment