Commit 8fdde640 authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Further coverage updates

parent 3617c4e5
......@@ -415,6 +415,8 @@ build-gnu-gcov:
name: ${CI_JOB_NAME}-${CI_COMMIT_REF_NAME}-${CI_COMMIT_SHA}
reports:
cobertura: build_gcov/coverage_xml.xml
paths:
- build_gcov/Testing
pages:
stage: doc_builds
......
......@@ -51,6 +51,18 @@ add_test(
NAME Classification
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/classification/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Classification_Max_Correlation_NE_One
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/classification_max_corr/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Classification_Generate_Project
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/classification_gen_proj/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Classification_Max_Correlation_NE_One_Generate_Project
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/classification_max_corr_gen_proj/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Regression
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/default/sisso.json" ${MPIEXEC_POSTFLAGS}
......@@ -59,14 +71,18 @@ add_test(
NAME Generate_Project
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/gen_proj/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Log_Regression
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/log_reg/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Maximum_Correlation_NE_One
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/max_corr/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Maximum_Correlation_NE_One_Generate_Project
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/max_corr_gen_proj/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Log_Regression
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/log_reg/sisso.json" ${MPIEXEC_POSTFLAGS}
)
add_test(
NAME Train_Only
COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} 2 ${MPIEXEC_PREFLAGS} "${CMAKE_BINARY_DIR}/bin/sisso++" "${CMAKE_SOURCE_DIR}/tests/exec_test/no_test_data/sisso.json" ${MPIEXEC_POSTFLAGS}
......
......@@ -531,6 +531,7 @@ void Model::populate_model(const std::string train_filename, const std::string t
feat_vals[nf][ns] = std::stod(split_line[2 + nf + with_samp_id]);
}
}
for(int ns = 0; ns < _n_samp_test; ++ns)
{
std::getline(test_file_stream, test_line);
......
......@@ -243,7 +243,7 @@ public:
{
std::vector<double> p = prop_train();
std::vector<double> p_est = prop_train_est();
return util_funcs::r2(p.data(), p_est.data(), _n_samp_test);
return util_funcs::r2(p.data(), p_est.data(), _n_samp_train);
}
// DocString: model_reg_test_r2
......
......@@ -121,7 +121,12 @@ public:
/**
* @brief Populate _phi using _phi_0 and the allowed operators up to (_max_rung - _n_rung_generate)^th rung
*/
void generate_feature_space();
void generate_feature_space(
std::vector<node_ptr>& feat_set,
std::vector<int>& start_rung,
const std::vector<double>& prop,
bool reparam = false
);
/**
* @brief A vector containing all of the selected features
......@@ -274,13 +279,6 @@ public:
const double l_bound=1e-50,
const double u_bound=1e50
);
/**
* @brief Generate reparameterized feature set
*
* @param prop The property to optimize against
*/
void generate_reparam_feature_set(const std::vector<double>& prop);
#endif
/**
......
......@@ -108,22 +108,15 @@ void FeatureNode::update_div_mult_leaves(std::map<std::string, double>& div_mult
expected_abs_tot += std::abs(fact);
}
std::map<int, int> FeatureNode::primary_feature_decomp() const
void FeatureNode::update_primary_feature_decomp(std::map<std::string, int>& pf_decomp) const
{
std::map<int, int> pf_decomp;
pf_decomp[_arr_ind] = 1;
return pf_decomp;
}
void FeatureNode::update_primary_feature_decomp(std::map<int, int>& pf_decomp) const
{
if(pf_decomp.count(_arr_ind) > 0)
if(pf_decomp.count(_expr) > 0)
{
pf_decomp[_arr_ind] += 1;
pf_decomp[_expr] += 1;
}
else
{
pf_decomp[_arr_ind] = 1;
pf_decomp[_expr] = 1;
}
}
......
......@@ -170,7 +170,7 @@ public:
/**
* @brief Get the number of primary features (non-unique) this feature contains (The number of leaves of the Binary Expression Tree)
*/
virtual inline int n_leaves(int cur_n_leaves = 0) const {return cur_n_leaves + 1;}
inline int n_leaves(int cur_n_leaves) const {return cur_n_leaves + 1;}
/**
* @brief Get the score used to sort the features in the feature space (Based on the type of node and _feat_ind)
......@@ -288,19 +288,12 @@ public:
*/
inline int rung(int cur_rung = 0) const {return cur_rung;}
/**
* @brief Get the primary feature decomposition of a feature
*
* @return A map representing the primary feature comprising a feature
*/
std::map<int, int> primary_feature_decomp() const;
/**
* @brief Update the primary feature decomposition of a feature
*
* @param pf_decomp The primary feature decomposition of the feature calling this function.
*/
void update_primary_feature_decomp(std::map<int, int>& pf_decomp) const;
virtual void update_primary_feature_decomp(std::map<std::string, int>& pf_decomp) const;
/**
* @brief Converts a feature into a postfix expression (reverse polish notation)
......@@ -347,9 +340,9 @@ public:
*/
inline node_ptr feat(const int ind) const
{
if(ind > 0)
if(ind > -1)
{
throw std::logic_error("Index not found in _feats");
throw std::logic_error("Can't get a child node from a FeatureNode.");
}
return nullptr;
}
......
......@@ -1010,79 +1010,22 @@ ModelNode::~ModelNode()
{}
void ModelNode::update_add_sub_leaves(std::map<std::string, int>& add_sub_leaves, const int pl_mn, int& expected_abs_tot) const
{
if(add_sub_leaves.count(_expr) > 0)
{
add_sub_leaves[_expr] += pl_mn;
}
else
{
add_sub_leaves[_expr] = pl_mn;
}
++expected_abs_tot;
}
{}
void ModelNode::update_div_mult_leaves(std::map<std::string, double>& div_mult_leaves, const double fact, double& expected_abs_tot) const
{
if(div_mult_leaves.count(_expr) > 0)
{
div_mult_leaves[_expr] += fact;
}
else
{
div_mult_leaves[_expr] = fact;
}
expected_abs_tot += std::abs(fact);
}
std::map<int, int> ModelNode::primary_feature_decomp() const
{
std::map<int, int> pf_decomp;
std::vector<std::string> split_postfix = str_utils::split_string_trim(_postfix_expr, "|");
for(auto& part : split_postfix)
{
try
{
if(pf_decomp.count(std::stoi(part)))
{
++pf_decomp[std::stoi(part)];
}
else
{
pf_decomp[std::stoi(part)] = 1;
}
}
catch(const std::invalid_argument e)
{
// Do Nothing
}
}
return pf_decomp;
}
{}
void ModelNode::update_primary_feature_decomp(std::map<int, int>& pf_decomp) const
void ModelNode::update_primary_feature_decomp(std::map<std::string, int>& pf_decomp) const
{
pf_decomp.clear();
std::vector<std::string> split_postfix = str_utils::split_string_trim(_postfix_expr, "|");
for(auto& part : split_postfix)
for(auto& leaf : _x_in_expr_list)
{
try
if(pf_decomp.count(leaf))
{
if(pf_decomp.count(std::stoi(part)))
{
++pf_decomp[std::stoi(part)];
}
else
{
pf_decomp[std::stoi(part)] = 1;
}
++pf_decomp[leaf];
}
catch(const std::invalid_argument e)
else
{
// Do Nothing
pf_decomp[leaf] = 1;
}
}
}
......@@ -76,6 +76,7 @@ protected:
int _rung; //!< The rung of the feature (Height of the binary expression tree - 1)
int _n_leaves; //!< The number of primary features (non-unique) this feature contains (The number of leaves of the Binary Expression Tree)
public:
using Node::n_leaves;
/**
* @brief Base Constructor
* @details This is only used for serialization
......@@ -219,7 +220,7 @@ public:
* @brief The number of primary features (non-unique) this feature contains (The number of leaves of the Binary Expression Tree)
*
*/
inline int n_leaves(int n_cur_leaves = 0) const {return _n_leaves;}
inline int n_leaves(int n_cur_leaves) const {return _n_leaves;}
/**
* @return Value of the feature converted to a range of -1.0 to 1.0
......@@ -341,14 +342,7 @@ public:
*
* @param pf_decomp The primary feature decomposition of the feature calling this function.
*/
void update_primary_feature_decomp(std::map<int, int>& pf_decomp) const;
/**
* @brief Get the primary feature decomposition of a feature
*
* @return A map representing the primary feature comprising a feature
*/
std::map<int, int> primary_feature_decomp() const;
void update_primary_feature_decomp(std::map<std::string, int>& pf_decomp) const;
/**
* @brief Get the term used in the postfix expression for this Node
......
......@@ -40,5 +40,11 @@ Node::Node(const unsigned long int feat_ind, const int n_samp, const int n_samp_
Node::~Node()
{}
std::map<std::string, int> Node::primary_feature_decomp() const
{
std::map<std::string, int> pf_decomp;
update_primary_feature_decomp(pf_decomp);
return pf_decomp;
}
BOOST_SERIALIZATION_ASSUME_ABSTRACT(Node)
......@@ -144,14 +144,23 @@ public:
*/
virtual std::vector<std::string> get_x_in_expr_list() const = 0;
// DocString: node_n_leaves
/**
* @brief The number of primary features (non-unique) this feature contains (The number of leaves of the Binary Expression Tree)
*
* @param cur_n_leaves (int) A recurisve counting variable
* @return The number of leaves of the Binary Expression Tree
*/
virtual int n_leaves(const int cur_n_leaves = 0) const = 0;
virtual int n_leaves(const int cur_n_leaves) const = 0;
// DocString: node_n_leaves
/**
* @brief The number of primary features (non-unique) this feature contains (The number of leaves of the Binary Expression Tree)
*
*/
inline int n_leaves() const
{
return n_leaves(0);
}
// DocString: node_reindex_1
/**
......@@ -333,14 +342,14 @@ public:
*
* @return A map representing the primary feature comprising a feature
*/
virtual std::map<int, int> primary_feature_decomp() const = 0;
std::map<std::string, int> primary_feature_decomp() const;
/**
* @brief Update the primary feature decomposition of a feature
*
* @param pf_decomp The primary feature decomposition of the feature calling this function.
*/
virtual void update_primary_feature_decomp(std::map<int, int>& pf_decomp) const = 0;
virtual void update_primary_feature_decomp(std::map<std::string, int>& pf_decomp) const = 0;
/**
* @brief Converts a feature into a postfix expression
......@@ -396,6 +405,15 @@ public:
*/
virtual std::vector<double> parameters() const = 0;
/**
* @brief The pointer to the head of the parameters used for including individual scale and bias terms to each operator in the Node
*/
virtual inline const double* param_pointer() const
{
throw std::logic_error("Trying to access the parameter pointer to a node with no parameters.");
return nullptr;
}
/**
* @brief Set the non-linear parameters
* @param params The new scale and bias terms of this node
......@@ -591,7 +609,7 @@ public:
/**
* @brief The decomposition of the primary features and how often they appear in the feature
*/
inline py::dict primary_feature_decomp_py(){return python_conv_utils::to_dict<int, int>(primary_feature_decomp());}
inline py::dict primary_feature_decomp_py(){return python_conv_utils::to_dict<std::string, int>(primary_feature_decomp());}
#endif
};
......
......@@ -71,6 +71,7 @@ protected:
std::array<node_ptr, N> _feats; //!< The features for the operator nodes to act on (This Node's children)
public:
using Node::n_leaves;
/**
* @brief Base Constructor
* @details This is only used for serialization
......@@ -95,27 +96,27 @@ public:
*
* @param o OperatorNode to be copied
*/
OperatorNode(const OperatorNode&) = default;
// OperatorNode(const OperatorNode&) = default;
/**
* @brief Move Constructor
*
* @param o OperatorNode to be moved
*/
OperatorNode(OperatorNode&&) = default;
// OperatorNode(OperatorNode&&) = default;
/**
* @brief Copy Assignment operator
*
* @param o OperatorNode to be copied
*/
OperatorNode& operator=(const OperatorNode&) = default;
// OperatorNode& operator=(const OperatorNode&) = default;
/**
* @brief Move Assignment operator
*
* @param o OperatorNode to be moved
*/
OperatorNode& operator=(OperatorNode&&) = default;
// OperatorNode& operator=(OperatorNode&&) = default;
/**
* @brief Destructor
......@@ -156,12 +157,12 @@ public:
return x_in_expr;
}
// DocString: op_node_n_leaves
/**
* @brief The number of primary features (non-unique) this feature contains (The number of leaves of the Binary Expression Tree)
*
* @param cur_n_leaves The current count of the number of leaves
*/
int n_leaves(int cur_n_leaves = 0) const
int n_leaves(int cur_n_leaves) const
{
return std::accumulate(_feats.begin(), _feats.end(), cur_n_leaves, [](int tot, node_ptr feat){return tot + feat->n_leaves();});
}
......@@ -337,24 +338,12 @@ public:
*/
virtual NODE_TYPE type() const = 0;
/**
* @brief Get the primary feature decomposition of a feature
*
* @return A map representing the primary feature comprising a feature
*/
std::map<int, int> primary_feature_decomp() const
{
std::map<int, int> pf_decomp;
update_primary_feature_decomp(pf_decomp);
return pf_decomp;
}
/**
* @brief Update the primary feature decomposition of a feature
*
* @param pf_decomp The primary feature decomposition of the feature calling this function.
*/
void update_primary_feature_decomp(std::map<int, int>& pf_decomp) const
void update_primary_feature_decomp(std::map<std::string, int>& pf_decomp) const
{
for(auto& feat : _feats)
{
......@@ -410,7 +399,7 @@ public:
*/
inline node_ptr feat(const int ind) const
{
if(ind > N)
if(ind >= N)
{
throw std::logic_error("Index not found in _feats");
}
......@@ -603,7 +592,8 @@ public:
{
throw std::logic_error("Asking for the gradient of non-parameterized feature");
}
gradient(grad, dfdp, parameters().data());
gradient(grad, dfdp, param_pointer());
}
/**
......
......@@ -47,6 +47,7 @@ class AbsNode: public OperatorNode<1>
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
/**
* @brief Base Constructor
* @details This is only used for serialization
......
......@@ -60,6 +60,7 @@ protected:
std::vector<double> _params; //!< The vector containing the scale and bias terms for the Node
public:
/**
* @brief Base Constructor
* @details This is only used for serialization
......@@ -179,6 +180,11 @@ public:
*/
inline std::vector<double> parameters() const {return _params;}
/**
* @brief The pointer to the head of the parameters used for including individual scale and bias terms to each operator in the Node
*/
virtual const double* param_pointer() const {return _params.data();}
/**
* @brief Optimize the scale and bias terms for each operation in the Node.
* @details Use optimizer to find the scale and bias terms that minimizes the associated loss function
......
......@@ -48,6 +48,7 @@ class AbsDiffNode: public OperatorNode<2>
}
public:
/**
* @brief Base Constructor
* @details This is only used for serialization
......
......@@ -58,6 +58,7 @@ protected:
std::vector<double> _params;
public:
/**
* @brief Base Constructor
* @details This is only used for serialization
......@@ -181,6 +182,11 @@ public:
*/
inline std::vector<double> parameters() const {return _params;}
/**
* @brief The pointer to the head of the parameters used for including individual scale and bias terms to each operator in the Node
*/
virtual const double* param_pointer() const {return _params.data();}
/**
* @brief Optimize the scale and bias terms for each operation in the Node.
* @details Use optimizer to find the scale and bias terms that minimizes the associated loss function
......
......@@ -47,6 +47,7 @@ class AddNode: public OperatorNode<2>
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
/**
* @brief Base Constructor
* @details This is only used for serialization
......
......@@ -60,6 +60,7 @@ protected:
std::vector<double> _params;
public:
/**
* @brief Base Constructor
* @details This is only used for serialization
......@@ -182,6 +183,11 @@ public:
*/
inline std::vector<double> parameters() const {return _params;}
/**
* @brief The pointer to the head of the parameters used for including individual scale and bias terms to each operator in the Node
*/
virtual const double* param_pointer() const {return _params.data();}
/**
* @brief Optimize the scale and bias terms for each operation in the Node.
* @details Use optimizer to find the scale and bias terms that minimizes the associated loss function
......
......@@ -47,6 +47,7 @@ class CbNode: public OperatorNode<1>
ar & boost::serialization::base_object<OperatorNode>(*this);
}
public:
/**
* @brief Base Constructor
* @details This is only used for serialization
......
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