Commit 584509e6 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

SIS now uses reduce_all instead of broadcast

should be more effeient
parent be1c8947
......@@ -112,7 +112,14 @@ if(USE_PYTHON)
)
if(NOT PYTHON_LIBRARIES)
message(FATAL_ERROR "Python libraries not found!")
find_library(
PYTHON_LIBRARIES
NAMES python${PYTHON_VERSION}
PATHS ${PYTHON_LIBDIR}
)
if(NOT PYTHON_LIBRARIES)
message(FATAL_ERROR "Python libraries not found!")
endif(NOT PYTHON_LIBRARIES)
endif(NOT PYTHON_LIBRARIES)
message(STATUS "PYTHON_LIBRARIES = ${PYTHON_LIBRARIES}")
......@@ -178,7 +185,7 @@ else(EXTERNAL_BOOST)
message(FATAL_ERROR "Could not find correct build toolset for boost with system ${CMAKE_SYSTEM_NAME}")
endif()
elseif(MSVC_COMP)
set(Boost_TOOLSET "msvc-${CMAKE_CXX_COMPILER_VERSION")
set(Boost_TOOLSET "msvc-${CMAKE_CXX_COMPILER_VERSION}")
elseif(IBM_COMP)
set(Boost_TOOLSET vacpp)
elseif(PGI_COMP)
......@@ -261,7 +268,7 @@ else(EXTERNAL_BOOST)
endif()
# Check BLAS/LAPACK
set(BLA_VENDOR Intel10_64lp_seq)
set(BLA_VENDOR Intel10_64lp)
find_package(LAPACK)
if(NOT LAPACK_FOUND)
set(BLA_VENDOR All)
......
......@@ -12,7 +12,7 @@ std::vector<double> convex_hull::TASK_SCORES;
int convex_hull::N_CLASS = 0;
int convex_hull::N_TASK = 0;
void convex_hull::initialize_projection(std::vector<int>& sizes, double* prop)
void convex_hull::initialize_projection(const std::vector<int>& sizes, double* prop)
{
int n_samp = std::accumulate(sizes.begin(), sizes.end(), 0);
......
......@@ -36,7 +36,7 @@ namespace convex_hull
* @param sizes The size of the tasks
* @param prop The pointer to the property vector
*/
void initialize_projection(std::vector<int>& sizes, double* prop);
void initialize_projection(const std::vector<int>& sizes, double* prop);
/**
* @brief Calculate the projection scores of a set of features to a vector via Pearson correlation
......@@ -51,4 +51,4 @@ namespace convex_hull
}
#endif
\ No newline at end of file
#endif
......@@ -110,6 +110,8 @@ void FeatureSpace::initialize_fs(std::vector<double> prop, std::string project_t
_is_valid_feat_list = comp_feats::valid_feature_against_selected_max_corr_1_feat_list;
}
mpi_reduce_op::set_op(_cross_cor_max, _n_sis_select);
for(auto & op : _allowed_ops)
{
if((op.compare("add") == 0) || (op.compare("mult") == 0) || (op.compare("abs_diff") == 0) || (op.compare("sub") == 0))
......@@ -618,66 +620,99 @@ void FeatureSpace::sis(std::vector<double>& prop)
start = omp_get_wtime();
if(_mpi_comm->size() > 1)
{
scores_sel.resize(_n_sis_select, 0.0);
phi_sel.resize(_n_sis_select, nullptr);
if(_mpi_comm->rank() == 0)
{
std::vector<double> sent_scores(_n_sis_select * _mpi_comm->size(), 0.0);
std::vector<node_ptr> sent_phi(_n_sis_select * _mpi_comm->size());
std::copy_n(scores_sel.begin(), _n_sis_select, sent_scores.begin());
std::copy_n(phi_sel.begin(), _n_sis_select, sent_phi.begin());
std::vector<node_sc_pair> local_sel(_n_sis_select, std::make_tuple<node_ptr, double>(nullptr, std::numeric_limits<double>::max()));
for(int ff = 0; ff < phi_sel.size(); ++ff)
local_sel.push_back(mpi_reduce_op::make_node_sc_pair(phi_sel[ff], scores_sel[ff]));
for(int rr = 1; rr < _mpi_comm->size(); ++rr)
{
_mpi_comm->recv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 0), &sent_scores[rr * _n_sis_select], _n_sis_select);
_mpi_comm->recv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 1), &sent_phi[rr * _n_sis_select], _n_sis_select);
}
std::vector<node_sc_pair> selected(_n_sis_select);
inds = util_funcs::argsort(sent_scores);
// Clear out the previous D matrix values (from creation of each process' phi_sel)
std::fill_n(node_value_arrs::get_d_matrix_ptr(cur_feat), _n_sis_select * node_value_arrs::N_SAMPLES, 0.0);
mpi::all_reduce(
*_mpi_comm,
local_sel,
selected,
mpi_reduce_op::select_top_feats
);
cur_feat_local = 0;
int ii = 0;
scores_sel = std::vector<double>(_n_sis_select, 0.0);
for(auto& sel : selected)
{
_phi_selected.push_back(std::get<0>(sel));
_phi_selected.back()->set_selected(true);
_phi_selected.back()->set_d_mat_ind(cur_feat + cur_feat_local);
++cur_feat_local;
}
// Get the n_sis_select best features (compare against features sent from other processes)
while((cur_feat + cur_feat_local != node_value_arrs::N_SELECTED) && (ii < sent_scores.size()))
if(_mpi_comm->rank() == 0)
{
for(auto& sel : selected)
{
node_value_arrs::clear_temp_reg();
if(_is_valid(sent_phi[inds[ii]]->value_ptr(), _n_samp, _cross_cor_max, scores_sel_all, sent_scores[inds[ii]], cur_feat + cur_feat_local, cur_feat))
{
out_file_stream << std::setw(14) <<std::left << cur_feat + cur_feat_local << sent_phi[inds[ii]]->postfix_expr() << std::endl;
sum_file_stream << std::setw(14) <<std::left << cur_feat + cur_feat_local << std::setw(24) << std::setprecision(18) << std::left << -1 * sent_scores[inds[ii]] << sent_phi[inds[ii]]->expr() << std::endl;
_phi_selected.push_back(sent_phi[inds[ii]]);
_phi_selected.back()->set_selected(true);
_phi_selected.back()->set_d_mat_ind(cur_feat + cur_feat_local);
_phi_selected.back()->set_standardized_value();
out_file_stream << std::setw(14) <<std::left << cur_feat << std::get<0>(sel)->postfix_expr() << std::endl;
sum_file_stream << std::setw(14) <<std::left << cur_feat << std::setw(24) << std::setprecision(18) << std::left << -1 * std::get<1>(sel) << std::get<0>(sel)->expr() << std::endl;
scores_sel[cur_feat_local] = sent_scores[inds[ii]];
scores_sel_all[cur_feat_local + cur_feat] = sent_scores[inds[ii]];
++cur_feat_local;
}
++ii;
++cur_feat;
}
if(_phi_selected.size() != node_value_arrs::N_SELECTED)
throw std::logic_error("SIS went through all sent features and did not select enough (" + std::to_string(_phi_selected.size() - node_value_arrs::N_SELECTED + _n_sis_select) + " not " + std::to_string(_n_sis_select) + ").");
}
else
{
_mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 0), scores_sel.data(), _n_sis_select);
_mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 1), phi_sel.data(), _n_sis_select);
_phi_selected.resize(node_value_arrs::N_SELECTED);
cur_feat -= cur_feat_local;
}
for(int bb = 0; bb <= (_n_sis_select / 10000 - ((_n_sis_select % 10000) == 0)); ++bb)
mpi::broadcast(*_mpi_comm, &_phi_selected[_phi_selected.size() - _n_sis_select + bb * 10000], std::min(_n_sis_select - bb * 10000, 10000), 0);
// scores_sel.resize(_n_sis_select, 0.0);
// phi_sel.resize(_n_sis_select, nullptr);
// if(_mpi_comm->rank() == 0)
// {
// std::vector<double> sent_scores(_n_sis_select * _mpi_comm->size(), 0.0);
// std::vector<node_ptr> sent_phi(_n_sis_select * _mpi_comm->size());
// std::copy_n(scores_sel.begin(), _n_sis_select, sent_scores.begin());
// std::copy_n(phi_sel.begin(), _n_sis_select, sent_phi.begin());
// for(int rr = 1; rr < _mpi_comm->size(); ++rr)
// {
// _mpi_comm->recv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 0), &sent_scores[rr * _n_sis_select], _n_sis_select);
// _mpi_comm->recv(rr, _mpi_comm->cantorTagGen(rr, 0, 2, 1), &sent_phi[rr * _n_sis_select], _n_sis_select);
// }
// inds = util_funcs::argsort(sent_scores);
// // Clear out the previous D matrix values (from creation of each process' phi_sel)
// std::fill_n(node_value_arrs::get_d_matrix_ptr(cur_feat), _n_sis_select * node_value_arrs::N_SAMPLES, 0.0);
// cur_feat_local = 0;
// int ii = 0;
// scores_sel = std::vector<double>(_n_sis_select, 0.0);
// // Get the n_sis_select best features (compare against features sent from other processes)
// while((cur_feat + cur_feat_local != node_value_arrs::N_SELECTED) && (ii < sent_scores.size()))
// {
// node_value_arrs::clear_temp_reg();
// if(_is_valid(sent_phi[inds[ii]]->value_ptr(), _n_samp, _cross_cor_max, scores_sel_all, sent_scores[inds[ii]], cur_feat + cur_feat_local, cur_feat))
// {
// out_file_stream << std::setw(14) <<std::left << cur_feat + cur_feat_local << sent_phi[inds[ii]]->postfix_expr() << std::endl;
// sum_file_stream << std::setw(14) <<std::left << cur_feat + cur_feat_local << std::setw(24) << std::setprecision(18) << std::left << -1 * sent_scores[inds[ii]] << sent_phi[inds[ii]]->expr() << std::endl;
// _phi_selected.push_back(sent_phi[inds[ii]]);
// _phi_selected.back()->set_selected(true);
// _phi_selected.back()->set_d_mat_ind(cur_feat + cur_feat_local);
// _phi_selected.back()->set_standardized_value();
// scores_sel[cur_feat_local] = sent_scores[inds[ii]];
// scores_sel_all[cur_feat_local + cur_feat] = sent_scores[inds[ii]];
// ++cur_feat_local;
// }
// ++ii;
// }
// if(_phi_selected.size() != node_value_arrs::N_SELECTED)
// throw std::logic_error("SIS went through all sent features and did not select enough (" + std::to_string(_phi_selected.size() - node_value_arrs::N_SELECTED + _n_sis_select) + " not " + std::to_string(_n_sis_select) + ").");
// }
// else
// {
// _mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 0), scores_sel.data(), _n_sis_select);
// _mpi_comm->send(0, _mpi_comm->cantorTagGen(_mpi_comm->rank(), 0, 2, 1), phi_sel.data(), _n_sis_select);
// _phi_selected.resize(node_value_arrs::N_SELECTED);
// }
// for(int bb = 0; bb <= (_n_sis_select / 10000 - ((_n_sis_select % 10000) == 0)); ++bb)
// mpi::broadcast(*_mpi_comm, &_phi_selected[_phi_selected.size() - _n_sis_select + bb * 10000], std::min(_n_sis_select - bb * 10000, 10000), 0);
std::vector<int> rungs(_n_sis_select, 0);
std::transform(_phi_selected.end() - _n_sis_select, _phi_selected.end(), rungs.begin(), [](node_ptr feat){return feat->rung();});
......
......@@ -11,6 +11,8 @@
#define FEATURE_SPACE
#include <mpi_interface/MPI_Interface.hpp>
#include <mpi_interface/MPI_ops.hpp>
#include <mpi_interface/serialize_tuple.h>
#include <feature_creation/node/FeatureNode.hpp>
#include <feature_creation/node/ModelNode.hpp>
#include <feature_creation/node/operator_nodes/allowed_ops.hpp>
......@@ -40,7 +42,7 @@ class FeatureSpace
{
std::vector<node_ptr> _phi_selected; //!< selected features
std::vector<node_ptr> _phi; //!< all features
std::vector<node_ptr> _phi_0; //!< initial feature space
const std::vector<node_ptr> _phi_0; //!< initial feature space
std::vector<std::string> _allowed_ops; //!< list of all allowed operators strings
std::vector<un_op_node_gen> _un_operators; //!< list of all unary operators
......@@ -49,29 +51,28 @@ class FeatureSpace
std::vector<double> _scores; //!< projection scores for each feature
std::vector<int> _task_sizes; //!< The number of elements in each task (training data)
const std::vector<int> _task_sizes; //!< The number of elements in each task (training data)
std::vector<int> _start_gen; //!< list of the indexes where each generation starts in _phi
std::string _feature_space_file; //!< File to store information about the selected features
std::string _feature_space_summary_file; //!< File to store information about the selected features
const std::string _feature_space_file; //!< File to store information about the selected features
const std::string _feature_space_summary_file; //!< File to store information about the selected features
std::function<void(double*, double*, std::vector<node_ptr>&, std::vector<int>&, int)> _project; //!< Function used to calculate the scores for SIS
std::function<void(double*, double*, std::vector<node_ptr>&, std::vector<int>&, int)> _project_no_omp; //!< Function used to calculate the scores for SIS without changing omp environment
std::function<void(double*, double*, std::vector<node_ptr>&, const std::vector<int>&, int)> _project; //!< Function used to calculate the scores for SIS
std::function<void(double*, double*, std::vector<node_ptr>&, const std::vector<int>&, int)> _project_no_omp; //!< Function used to calculate the scores for SIS without changing omp environment
std::function<bool(double*, int, double, std::vector<double>&, double, int, int)> _is_valid; //!< Function used to calculate the scores for SIS
std::function<bool(double*, int, double, std::vector<node_ptr>&, std::vector<double>&, double)> _is_valid_feat_list; //!< Function used to calculate the scores for SIS without changing omp environment
std::shared_ptr<MPI_Interface> _mpi_comm; //!< MPI communicator
double _cross_cor_max; //!< Maximum cross-correlation used for selecting features
double _l_bound; //!< lower bound for absolute value of the features
double _u_bound; //!< upper bound for absolute value of the features
const double _cross_cor_max; //!< Maximum cross-correlation used for selecting features
const double _l_bound; //!< lower bound for absolute value of the features
const double _u_bound; //!< upper bound for absolute value of the features
int _max_phi; //!< Maximum rung for the feature creation
int _n_sis_select; //!< Number of features to select for each dimensions
int _n_samp; //!< Number of samples (training data)
int _n_feat; //!< Total number of features
int _n_rung_store; //!< Total rungs stored
int _n_rung_generate; //!< Total number of rungs to generate on the fly
int _n_feat; //!< Total number of features
int _max_phi; //!< Maximum rung for the feature creation
const int _n_sis_select; //!< Number of features to select for each dimensions
const int _n_samp; //!< Number of samples (training data)
const int _n_rung_generate; //!< Total number of rungs to generate on the fly
public:
/**
......@@ -424,4 +425,4 @@ public:
#endif
};
#endif
\ No newline at end of file
#endif
#include<mpi_interface/MPI_ops.hpp>
void mpi_reduce_op::set_op(double cross_cor_max)
{
_cross_cor_max = cross_cor_max;
if(_cross_cor_max < 0.99999)
_is_valid = comp_feats::valid_feature_against_selected_feat_sc_list;
// MPI_Op top_feats;
std::function<bool(double*, int, double, std::vector<node_sc_pair>&, double)> mpi_reduce_op::IS_VALID;
double mpi_reduce_op::CROSS_COR_MAX;
int mpi_reduce_op::N_SIS_SELECT;
void mpi_reduce_op::set_op(double cross_cor_max, int n_sis_select)
{
// MPI_Op_create(*select_top_feats, 1, &top_feats)
N_SIS_SELECT = n_sis_select;
CROSS_COR_MAX = cross_cor_max;
if(CROSS_COR_MAX < 0.99999)
IS_VALID = comp_feats::valid_feature_against_selected_feat_sc_list;
else
_is_valid = comp_feats::valid_feature_against_selected_max_corr_1_feat_sc_list;
}
\ No newline at end of file
IS_VALID = comp_feats::valid_feature_against_selected_max_corr_1_feat_sc_list;
}
std::vector<node_sc_pair> mpi_reduce_op::select_top_feats(std::vector<node_sc_pair> vec_1, std::vector<node_sc_pair> vec_2)
{
std::vector<node_sc_pair> out_vec;
out_vec.reserve(N_SIS_SELECT);
vec_1.insert(vec_1.end(), vec_2.begin(), vec_2.end());
std::sort(vec_1.begin(), vec_1.end(), my_sorter);
for(auto& feat_sc_pair : vec_1)
{
if(out_vec.size() >= N_SIS_SELECT)
break;
const node_ptr cur_node = std::get<0>(feat_sc_pair);
if(IS_VALID(cur_node->value_ptr(), cur_node->n_samp(), CROSS_COR_MAX, out_vec, std::get<1>(feat_sc_pair)))
out_vec.push_back(feat_sc_pair);
}
return out_vec;
}
......@@ -15,41 +15,18 @@
namespace mpi_reduce_op
{
std::function<bool(double*, int, double, node_sc_pair*, node_sc_pair*, double)> _is_valid; //!< Function used to calculate the scores for SIS without changing omp environment
double _cross_cor_max; //!< The maximum cross correlation between features
// extern MPI_Op top_feats;
extern std::function<bool(double*, int, double, std::vector<node_sc_pair>&, double)> IS_VALID; //!< Function used to calculate the scores for SIS without changing omp environment
extern double CROSS_COR_MAX; //!< The maximum cross correlation between features
extern int N_SIS_SELECT; //!< The number of features to select
inline bool my_sorter(node_sc_pair node_1, node_sc_pair node_2){ return (std::get<1>(node_1) < std::get<1>(node_2)); }
template <int N>
void select_top_N(void* input_list, void* output_list, int* length, MPI_Datatype* datatype)
{
std::vector<node_sc_pair> merged_list;
const int top_items_number = N;
inline node_sc_pair make_node_sc_pair(node_ptr feat, double sc){return std::make_tuple(feat, sc);}
for(int ii=0; ii < *length; ++ii)
{
const int index_first = ii * top_items_number;
const int index_last = index_first + top_items_number;
inline bool my_sorter(node_sc_pair node_1, node_sc_pair node_2){ return (std::get<1>(node_1) < std::get<1>(node_2)); }
merged_list.insert(merged_list.end(), static_cast<node_sc_pair*>(input_list)+index_first, static_cast<node_sc_pair*>(input_list)+index_last);
merged_list.insert(merged_list.end(), static_cast<node_sc_pair*>(output_list)+index_first, static_cast<node_sc_pair*>(output_list)+index_last);
std::sort(merged_list.begin(), merged_list.end(), my_sorter);
int ind = index_first;
int mi = 0;
while(ind != index_last)
{
const node_ptr cur_node = std::get<0>(merged_list[mi]);
if(_is_valid(cur_node->value_ptr(), cur_node->n_samp(), _cross_cor_max, static_cast<node_sc_pair*>(output_list) + index_first, static_cast<node_sc_pair*>(output_list) + ind, std::get<1>(merged_list[mi])))
{
static_cast<node_sc_pair*>(output_list)[ind] = merged_list[mi];
++ind;
}
++mi;
}
}
}
std::vector<node_sc_pair> select_top_feats(std::vector<node_sc_pair> input_list, std::vector<node_sc_pair> output_list);
void set_op(double cross_cor_max);
void set_op(double cross_cor_max, int n_sis_select);
}
#endif
\ No newline at end of file
#endif
......@@ -30,9 +30,9 @@ FeatureSpace::FeatureSpace(
_n_sis_select(n_sis_select),
_n_feat(py::len(phi_0)),
_n_rung_store(max_store_rung),
_n_rung_generate(n_rung_generate)
_n_rung_generate(n_rung_generate),
_n_samp(_phi[0]->n_samp())
{
_n_samp = _phi_0[0]->n_samp();
initialize_fs(python_conv_utils::from_list<double>(prop), project_type);
}
......@@ -66,9 +66,9 @@ FeatureSpace::FeatureSpace(
_n_sis_select(n_sis_select),
_n_feat(py::len(phi_0)),
_n_rung_store(max_store_rung),
_n_rung_generate(n_rung_generate)
_n_rung_generate(n_rung_generate),
_n_samp(_phi[0]->n_samp())
{
_n_samp = _phi_0[0]->n_samp();
initialize_fs(python_conv_utils::from_ndarray<double>(prop), project_type);
}
......@@ -92,9 +92,9 @@ FeatureSpace::FeatureSpace(
_n_sis_select(n_sis_select),
_n_feat(py::len(phi_0)),
_n_rung_store(0),
_n_rung_generate(0)
_n_rung_generate(0),
_n_samp(_phi[0]->n_samp())
{
_n_samp = _phi_0[0]->n_samp();
if(project_type.compare("regression") == 0)
_project = project_funcs::project_r2;
else if(project_type.compare("classification") == 0)
......
......@@ -11,16 +11,16 @@ bool comp_feats::valid_feature_against_selected_max_corr_1(double* val_ptr, int
double alpha = 1.0 / util_funcs::stand_dev(val_ptr, n_samp);
CORR_CHECK.resize(end_sel - start_sel);
dgemv_(
'T',
n_samp,
end_sel - start_sel,
alpha,
node_value_arrs::get_d_matrix_ptr(start_sel),
n_samp,
val_ptr,
1,
0.0,
comp_feats::CORR_CHECK.data(),
'T',
n_samp,
end_sel - start_sel,
alpha,
node_value_arrs::get_d_matrix_ptr(start_sel),
n_samp,
val_ptr,
1,
0.0,
comp_feats::CORR_CHECK.data(),
1
);
return (base_val - std::abs(comp_feats::CORR_CHECK[idamax_(end_sel - start_sel, comp_feats::CORR_CHECK.data(), 1) - 1]) > 1e-9);
......@@ -50,16 +50,16 @@ bool comp_feats::valid_feature_against_selected(double* val_ptr, int n_samp, dou
CORR_CHECK.resize(end_sel - start_sel);
dgemv_(
'T',
n_samp,
end_sel - start_sel,
alpha,
node_value_arrs::get_d_matrix_ptr(start_sel),
n_samp,
val_ptr,
1,
0.0,
comp_feats::CORR_CHECK.data(),
'T',
n_samp,
end_sel - start_sel,
alpha,
node_value_arrs::get_d_matrix_ptr(start_sel),
n_samp,
val_ptr,
1,
0.0,
comp_feats::CORR_CHECK.data(),
1
);
return (base_val - std::abs(comp_feats::CORR_CHECK[idamax_(end_sel - start_sel, comp_feats::CORR_CHECK.data(), 1)]) < (1.0 - cross_cor_max + 1e-10));
......@@ -77,29 +77,29 @@ bool comp_feats::valid_feature_against_selected_feat_list(double* val_ptr, int n
return true;
}
bool comp_feats::valid_feature_against_selected_max_corr_1_feat_sc_list(double* val_ptr, int n_samp, double cross_cor_max, node_sc_pair* start, node_sc_pair* end, double cur_score)
bool comp_feats::valid_feature_against_selected_max_corr_1_feat_sc_list(double* val_ptr, int n_samp, double cross_cor_max, std::vector<node_sc_pair>& out_vec, double cur_score)
{
double base_val = util_funcs::r(val_ptr, val_ptr, n_samp);
for(auto feat_sc = start; feat_sc < end; ++feat_sc)
for(auto& feat_sc : out_vec)
{
if(abs(cur_score - feat_sc->second) > 1e-5)
if(abs(cur_score - std::get<1>(feat_sc)) > 1e-5)
continue;
if((base_val - std::abs(util_funcs::r(feat_sc->first->value_ptr(1), val_ptr, n_samp))) < 1e-9)
if((base_val - std::abs(util_funcs::r(std::get<0>(feat_sc)->value_ptr(1), val_ptr, n_samp))) < 1e-9)
return false;
}
return true;
}
bool comp_feats::valid_feature_against_selected_feat_sc_list(double* val_ptr, int n_samp, double cross_cor_max, node_sc_pair* start, node_sc_pair* end, double cur_score)
bool comp_feats::valid_feature_against_selected_feat_sc_list(double* val_ptr, int n_samp, double cross_cor_max, std::vector<node_sc_pair>& out_vec, double cur_score)
{
double base_val = util_funcs::r(val_ptr, val_ptr, n_samp);
for(auto feat_sc = start; feat_sc < end; ++feat_sc)
for(auto& feat_sc : out_vec)
{
if((base_val - std::abs(util_funcs::r(feat_sc->first->value_ptr(1), val_ptr, n_samp))) < (1.0 - cross_cor_max + 1e-10))
if((base_val - std::abs(util_funcs::r(std::get<0>(feat_sc)->value_ptr(1), val_ptr, n_samp))) < (1.0 - cross_cor_max + 1e-10))
return false;
}
return true;
}
\ No newline at end of file
}
......@@ -7,12 +7,12 @@
#ifndef UTILS_FEAT_COMP
#define UTILS_FEAT_COMP
#include <utility>
#include <tuple>
#include <feature_creation/node/Node.hpp>
#include <classification/utils.hpp>
typedef std::pair<node_ptr, double> node_sc_pair;
typedef std::tuple<node_ptr, double> node_sc_pair;
namespace comp_feats
{
......@@ -66,7 +66,7 @@ namespace comp_feats
* @return True if the feature is still valid
*/
bool valid_feature_against_selected_feat_list(double* val_ptr, int n_samp, double cross_cor_max, std::vector<node_ptr>& selected, std::vector<double>& scores_sel, double cur_score);
/**
* @brief Checks the feature to see if it is still valid against previously selected features
*
......@@ -79,7 +79,7 @@ namespace comp_feats
*
* @return True if the feature is still valid
*/
bool valid_feature_against_selected_max_corr_1_feat_sc_list(double* val_ptr, int n_samp, double cross_cor_max, node_sc_pair* start, node_sc_pair* end, double cur_score);
bool valid_feature_against_selected_max_corr_1_feat_sc_list(double* val_ptr, int n_samp, double cross_cor_max, std::vector<node_sc_pair>& out_vec, double cur_score);
/**
* @brief Checks the feature to see if it is still valid against previously selected features
......@@ -93,9 +93,9 @@ namespace comp_feats
*
* @return True if the feature is still valid
*/
bool valid_feature_against_selected_feat_sc_list(double* val_ptr, int n_samp, double cross_cor_max, node_sc_pair* start, node_sc_pair* end, double cur_score);
bool valid_feature_against_selected_feat_sc_list(double* val_ptr, int n_samp, double cross_cor_max, std::vector<node_sc_pair>& out_vec, double cur_score);
}
#endif
\ No newline at end of file
#endif
......@@ -24,7 +24,7 @@ double util_funcs::log_r2(double* a, double* b, double* log_a, int size)
return r2(log_a, b, size);
}
double util_funcs::r(double* a, double* b, std::vector<int>& sizes)
double util_funcs::r(double* a, double* b, const std::vector<int>& sizes)
{
double result = 0.0;
int pos = 0;
......@@ -37,7 +37,7 @@ double util_funcs::r(double* a, double* b, std::vector<int>& sizes)
return std::sqrt(result / sizes.size());
}
double util_funcs::r2(double* a, double* b, std::vector<int>& sizes)
double util_funcs::r2(double* a, double* b, const std::vector<int>& sizes)
{
double result = 0.0;
int pos = 0;
......@@ -50,7 +50,7 @@ double util_funcs::r2(double* a, double* b, std::vector<int>& sizes)
return result / sizes.size();
}
double util_funcs::log_r2(double* a, double* b, double* log_a, std::vector<int>& sizes)
double util_funcs::log_r2(double* a, double* b, double* log_a, const std::vector<int>& sizes)
{
double result = 0.0;
int pos = 0;
......@@ -63,7 +63,7 @@ double util_funcs::log_r2(double* a, double* b, double* log_a, std::vector<int>&
return result / sizes.size();
}