Commit e5ec0e95 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Minor Bug/imporvents to accessing features

don't need to set things as often

check for cross correlation in the stored rungs
parent fe2eac21
......@@ -75,6 +75,7 @@ FeatureSpace::FeatureSpace(FeatureSpace &o) :
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;
......@@ -85,6 +86,8 @@ 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)
{
......@@ -142,11 +145,6 @@ void FeatureSpace::generate_feature_space()
}
}
}
// for(auto& feat : next_phi)
// {
// feat->set_feat_val_ptrs();
// feat->set_value();
// }
_mpi_comm->barrier();
if(_mpi_comm->rank() == 0)
std::cout << "NEXT_PHI MADE" << std::endl;
......@@ -167,21 +165,29 @@ void FeatureSpace::generate_feature_space()
for(auto& feat : next_phi_vec)
{
if(nn <= node_value_arrs::N_RUNGS_STORED)
{
std::transform(_phi.begin(), _phi.end(), scores.begin(), [&feat](node_ptr f){return 1.0 - std::abs(util_funcs::r(feat->value_ptr(), f->value_ptr(), f->n_samp()));});
if(*std::min_element(scores.begin(), scores.begin()+_phi.size()) > 1e-13)
_phi.push_back(feat);
feat->set_value();
_phi.push_back(feat);
}
else
{
_phi.push_back(feat);
}
}
}
std::cout << "DONE"<< std::endl;
}
}
void FeatureSpace::project_r(std::vector<double>& prop)
void FeatureSpace::project_r(double* prop)
{
std::array<int, 2> start_end = _mpi_comm->get_start_end_for_iterator(_phi.size(), 0);
std::vector<double> scores(start_end[1] - start_end[0], 0.0);
for(int ff = start_end[0]; ff < start_end[1]; ++ff)
scores[ff - start_end[0]] = -1.0 * std::abs(util_funcs::r(prop.data(), _phi[ff]->value_ptr(), prop.size()));
scores[ff - start_end[0]] = -1.0 * std::abs(util_funcs::r(prop, _phi[ff]->value_ptr(), _n_samp));
std::vector<std::vector<double>> all_scores;
mpi::all_gather(*_mpi_comm, scores, all_scores);
......@@ -205,7 +211,7 @@ void FeatureSpace::sis(std::vector<double>& prop)
_phi_selected.reserve(_phi_selected.size());
project_r(prop);
project_r(prop.data());
std::vector<int> inds = util_funcs::argsort(_scores);
int ii = 0;
......
......@@ -58,7 +58,7 @@ public:
inline std::shared_ptr<MPI_Interface> mpi_comm(){return _mpi_comm;}
inline double* D(int ind){return &_D[ind * _n_samp];}
void project_r(std::vector<double>& prop);
void project_r(double* prop);
void sis(std::vector<double>& prop);
};
......
......@@ -34,8 +34,8 @@ void AbsDiffNode::set_value()
if((_feats[1]->rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) != _feats[1]->feat_ind()))
{
_feats[1]->set_value();
std::copy_n(_feats[1]->value_ptr(), _n_samp, _feat_val_ptrs[1]);
node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) = _feats[1]->feat_ind();
}
allowed_op_funcs::abs_diff(_n_samp, _feat_val_ptrs, _value_ptr);
}
......@@ -32,7 +32,6 @@ void AddNode::set_value()
if((_feats[1]->rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) != _feats[1]->feat_ind()))
{
_feats[1]->set_value();
std::copy_n(_feats[1]->value_ptr(), _n_samp, _feat_val_ptrs[1]);
node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) = _feats[1]->feat_ind();
}
......
......@@ -26,7 +26,6 @@ void DivNode::set_value()
if((_feats[1]->rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) != _feats[1]->feat_ind()))
{
_feats[1]->set_value();
std::copy_n(_feats[1]->value_ptr(), _n_samp, _feat_val_ptrs[1]);
node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) = _feats[1]->feat_ind();
}
......
......@@ -26,7 +26,6 @@ void MultNode::set_value()
if((_feats[1]->rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) != _feats[1]->feat_ind()))
{
_feats[1]->set_value();
std::copy_n(_feats[1]->value_ptr(), _n_samp, _feat_val_ptrs[1]);
node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) = _feats[1]->feat_ind();
}
......
......@@ -32,7 +32,6 @@ void SubNode::set_value()
if((_feats[1]->rung() > node_value_arrs::N_RUNGS_STORED) && (node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) != _feats[1]->feat_ind()))
{
_feats[1]->set_value();
std::copy_n(_feats[1]->value_ptr(), _n_samp, _feat_val_ptrs[1]);
node_value_arrs::temp_storage_reg(_feats[1]->feat_ind(), 1) = _feats[1]->feat_ind();
}
......
Supports Markdown
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