Commit 2010025f authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Clean up feature space printing

don't print as much out to the console
parent b0162a2b
......@@ -37,6 +37,7 @@ FeatureSpace::FeatureSpace(
_scores(phi_0.size(), 0.0),
_task_sizes(task_sizes),
_start_gen(1, 0),
_feature_space_file("feature_space/selected_features.txt"),
_mpi_comm(mpi_comm),
_l_bound(min_abs_feat_val),
_u_bound(max_abs_feat_val),
......@@ -423,22 +424,17 @@ bool FeatureSpace::valid_score_against_current(int end_check, double* val_ptr, d
int dd = std::min_element(scores_comp.begin(), scores_comp.begin() + end_check) - scores_comp.begin();
if(std::abs(util_funcs::r(val_ptr, val_ptr, _n_samp) - util_funcs::r(node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd), val_ptr, _n_samp)) < 1e-10)
return false;
else
{
std::vector<double> test(_n_samp);
std::transform(val_ptr, val_ptr + _n_samp, node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd), test.data(), std::minus<double>());
std::cout << std::setw(24) << std::setprecision(20) << *std::min_element(test.begin(), test.end()) << '\t' << *std::max_element(test.begin(), test.end()) << std::endl;
std::cout << std::setw(24) << std::setprecision(20) << *val_ptr << *node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd) << std::endl;
std::cout << std::setw(24) << std::setprecision(20) << std::abs(util_funcs::r(val_ptr, val_ptr, _n_samp) - util_funcs::r(node_value_arrs::get_d_matrix_ptr(node_value_arrs::N_SELECTED - _n_sis_select + dd), val_ptr, _n_samp)) << std::endl;
}
}
return true;
}
void FeatureSpace::sis(std::vector<double>& prop)
{
// std::fill_n(node_value_arrs::TEMP_STORAGE_REG.data(), node_value_arrs::TEMP_STORAGE_REG.size(), -1);
// std::fill_n(node_value_arrs::TEMP_STORAGE_TEST_REG.data(), node_value_arrs::TEMP_STORAGE_TEST_REG.size(), -1);
boost::filesystem::path p(_feature_space_file.c_str());
boost::filesystem::create_directories(p.remove_filename());
std::ofstream out_file_stream = std::ofstream();
out_file_stream.open(_feature_space_file, std::ios::app);
std::vector<double> scores_comp(std::max(node_value_arrs::N_SELECTED, _n_sis_select), 1.0);
std::vector<double> scores_sel(_n_sis_select, 0.0);
......@@ -493,7 +489,8 @@ void FeatureSpace::sis(std::vector<double>& prop)
phi_sel.resize(cur_feat_local);
scores_sel.resize(cur_feat_local);
project_generated(prop.data(), prop.size(), phi_sel, scores_sel, scores_comp);
// std::fill_n(node_value_arrs::TEMP_STORAGE_TEST_REG.data(), node_value_arrs::TEMP_STORAGE_TEST_REG.size(), -1);
node_value_arrs::clear_temp_reg();
node_value_arrs::clear_temp_test_reg();
}
......@@ -583,7 +580,7 @@ void FeatureSpace::sis(std::vector<double>& prop)
inds = util_funcs::argsort(sent_scores);
for(int ii = 0; ii < _n_sis_select; ++ii)
{
std::cout << std::setw(feat_num_width) <<std::left << cur_feat << std::setw(24) << std::setprecision(18) << std::left << sent_scores[inds[ii]] << sent_phi[inds[ii]]->expr() << std::endl;
out_file_stream << std::setw(feat_num_width) <<std::left << cur_feat << std::setw(24) << std::setprecision(18) << std::left << sent_scores[inds[ii]] << sent_phi[inds[ii]]->expr() << std::endl;
_phi_selected.push_back(sent_phi[inds[ii]]);
_phi_selected.back()->selected() = true;
_phi_selected.back()->set_dmat_ind(cur_feat);
......@@ -606,7 +603,7 @@ void FeatureSpace::sis(std::vector<double>& prop)
{
if(valid_score_against_current(cur_feat_local, sent_phi[inds[ii]]->value().data(), sent_scores[inds[ii]], scores_sel, scores_comp))
{
std::cout << std::setw(feat_num_width) <<std::left << cur_feat << std::setw(24) << std::setprecision(18) << std::left << sent_scores[inds[ii]] << sent_phi[inds[ii]]->expr() << std::endl;
out_file_stream << std::setw(feat_num_width) <<std::left << cur_feat << std::setw(24) << std::setprecision(18) << std::left << sent_scores[inds[ii]] << sent_phi[inds[ii]]->expr() << std::endl;
_phi_selected.push_back(sent_phi[inds[ii]]);
......@@ -649,7 +646,7 @@ void FeatureSpace::sis(std::vector<double>& prop)
inds = util_funcs::argsort(scores_sel);
for(auto& ind : inds)
{
std::cout << std::setw(feat_num_width) <<std::left << cur_feat << std::setw(24) << std::setprecision(18) << std::left << scores_sel[ind] << phi_sel[ind]->expr() << std::endl;
out_file_stream << std::setw(feat_num_width) <<std::left << cur_feat << std::setw(24) << std::setprecision(18) << std::left << scores_sel[ind] << phi_sel[ind]->expr() << std::endl;
_phi_selected.push_back(phi_sel[ind]);
_phi_selected.back()->set_dmat_ind(cur_feat);
_phi_selected.back()->set_value();
......@@ -660,5 +657,10 @@ void FeatureSpace::sis(std::vector<double>& prop)
if(cur_feat != node_value_arrs::N_SELECTED)
throw std::logic_error("SIS went through all features and did not select enough.");
if(_mpi_comm->rank() == 0)
{
for(int dd = 0; dd < feat_num_width + 48; ++dd)
out_file_stream << "-";
out_file_stream << std::endl;
}
}
......@@ -8,6 +8,7 @@
#include <utils/project.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/filesystem.hpp>
#include <iostream>
#include <iomanip>
......@@ -33,9 +34,9 @@ class FeatureSpace
std::vector<int> _task_sizes; //!< The number of elements in each task
std::vector<int> _start_gen; //!< list of starting index for each generation
std::string _feature_space_file; //!< File to store infromation on the feature space
std::function<void(double*, double*, std::vector<node_ptr>&, std::vector<int>&, int)> _project; //!< Function used for projection onto SIS
std::shared_ptr<MPI_Interface> _mpi_comm; //!< MPi communicator
double _l_bound; //!< lower bound for absolute value of the features
......
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