Commit 9b06b7ee authored by Thomas Purcell's avatar Thomas Purcell
Browse files

Bug fixes for generation on the fly behavior

Division/multiplcation nodes cant have division features/inverse

empyt unit check
parent bbac673f
#include <descriptor_identifier/Model/Model.hpp>
Model::Model(std::vector<double> prop_train, std::vector<double> prop_test, std::vector<std::shared_ptr<Node>> feats) :
Model::Model(std::vector<double> prop_train, std::vector<double> prop_test, std::vector<std::shared_ptr<FeatureNode>> feats) :
_n_samp_train(feats[0]->n_samp()),
_n_samp_test(feats[0]->n_test_samp()),
_n_dim(feats.size() + 1),
......
......@@ -7,7 +7,7 @@
#include<fstream>
#include<iostream>
#include <feature_creation/node/Node.hpp>
#include <feature_creation/node/FeatureNode.hpp>
/**
* @brief Class to store the models found from SISSO
......@@ -19,7 +19,7 @@ class Model
int _n_samp_test; //!< The number of test samples per feature
int _n_dim; //!< Dimension of the model
std::vector<std::shared_ptr<Node>> _feats; //!< List of features in the model
std::vector<std::shared_ptr<FeatureNode>> _feats; //!< List of features in the model
std::vector<double> _coefs; //!< Coefficients for teh features
std::vector<double> _prop_train; //!< The property to be modeled
......@@ -39,7 +39,7 @@ public:
* @param prop The property
* @param feats The features for the model
*/
Model(std::vector<double> prop_train, std::vector<double> prop_test, std::vector<std::shared_ptr<Node>> feats);
Model(std::vector<double> prop_train, std::vector<double> prop_test, std::vector<std::shared_ptr<FeatureNode>> feats);
/**
......
......@@ -189,7 +189,7 @@ void SISSORegressor::l0_norm(std::vector<double>& prop, int n_dim)
inds = util_funcs::argsort(all_min_error);
std::vector<node_ptr> min_nodes(n_dim);
std::vector<std::shared_ptr<FeatureNode>> min_nodes(n_dim);
std::vector<Model> models;
for(int rr = 0; rr < _n_residual; ++rr)
......
......@@ -19,8 +19,8 @@
*/
class FeatureSpace
{
std::vector<std::shared_ptr<FeatureNode>> _phi_selected; //!< selected features
std::vector<node_ptr> _phi; //!< all features
std::vector<node_ptr> _phi_selected; //!< selected features
std::vector<node_ptr> _phi_0; //!< initial feature space
std::vector<std::string> _allowed_ops; //!< list of all allowed operators strings
......@@ -43,6 +43,7 @@ class FeatureSpace
int _n_samp; //!< Number of samples
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
public:
/**
......@@ -62,6 +63,7 @@ public:
int max_phi=1,
int n_sis_select=1,
int max_store_rung=2,
int n_rung_generate=0,
double min_abs_feat_val=1e-50,
double max_abs_feat_val=1e50
);
......@@ -75,7 +77,7 @@ public:
/**
* @brief Accessor function for _phi_selected
*/
inline std::vector<node_ptr> phi_selected(){return _phi_selected;};
inline std::vector<std::shared_ptr<FeatureNode>> phi_selected(){return _phi_selected;};
/**
* @brief Accessor function for _phi
......@@ -105,6 +107,15 @@ public:
*/
void project_r(double* prop, int size);
std::vector<double> project_r(double* prop, int size, std::vector<node_ptr>& phi);
void generate_new_feats(std::vector<node_ptr>::iterator& feat, std::vector<node_ptr>& feat_set, int& feat_ind, double l_bound=1e-50, double u_bound=1e50);
void project_generated(double* prop, int size, std::vector<std::shared_ptr<FeatureNode>>& phi_selected, std::vector<double>& scores_selected, std::vector<double>& scores_comp);
bool valid_score_against_past(double* val_ptr, std::vector<double>& scores_comp);
bool valid_score_against_current(int end_check, double* val_ptr, double cur_score, std::vector<double>& scores_selected, std::vector<double>& scores_comp);
/**
* @brief Perform SIS on a feature set with a specified property
* @details Perform sure-independence screening with either the correct property
......
......@@ -5,11 +5,11 @@ FeatureNode::FeatureNode()
FeatureNode::FeatureNode(int feat_ind, std::string expr, std::vector<double> value, std::vector<double> test_value, Unit unit, bool selected) :
Node(feat_ind, value.size(), test_value.size()),
_selected(selected),
_expr(expr),
_unit(unit),
_value(value),
_test_value(test_value)
_test_value(test_value),
_unit(unit),
_expr(expr),
_selected(selected)
{
set_value();
set_test_value();
......
......@@ -34,11 +34,11 @@ class FeatureNode: public Node
}
protected:
bool _selected; //!< True if the features was selected
std::string _expr; //!< Expression of the feature
Unit _unit; //!< Unit for the feature
std::vector<double> _value; //!< values for the feature
std::vector<double> _test_value; //!< test values for the feature
Unit _unit; //!< Unit for the feature
std::string _expr; //!< Expression of the feature
bool _selected; //!< True if the features was selected
public:
/**
* @brief Base Constructor
......@@ -57,12 +57,19 @@ public:
*/
FeatureNode(int feat_ind, std::string expr, std::vector<double> value, std::vector<double> test_value, Unit unit, bool selected=false);
FeatureNode(const FeatureNode&) = default;
FeatureNode(FeatureNode&&) = default;
FeatureNode& operator=(const FeatureNode&) = default;
FeatureNode& operator=(FeatureNode&&) = default;
~FeatureNode();
/**
* @brief Get the expression for the overall descriptor (From head node down)
*/
inline std::string expr(){return _expr;}
inline std::string expr()const{return _expr;}
/**
* @brief Get the unit for the overall descriptor (From head node down)
......
......@@ -59,6 +59,12 @@ public:
*/
Node(int feat_ind, int n_samp, int n_test_samp);
Node(const Node& o) = default;
Node(Node&& o) = default;
Node& operator= (const Node& o) = default;
Node& operator= (Node&& o) = default;
virtual ~Node();
/**
......
......@@ -48,11 +48,17 @@ public:
* @param rung run the feature is on (depth of the tree)
* @param feat_ind index of the feature
*/
OperatorNode(std::array<node_ptr, N> feats, int rung, int feat_ind) :
OperatorNode(std::array<node_ptr, N> feats, int feat_ind) :
Node(feat_ind, feats[0]->n_samp(), feats[0]->n_test_samp()),
_feats(feats)
{}
OperatorNode(const OperatorNode& o) = default;
OperatorNode(OperatorNode&& o) = default;
OperatorNode& operator=(const OperatorNode& o) = default;
OperatorNode& operator=(OperatorNode&& o) = default;
virtual ~OperatorNode()
{}
......
......@@ -5,8 +5,8 @@
AbsDiffNode::AbsDiffNode()
{}
AbsDiffNode::AbsDiffNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, rung, feat_ind)
AbsDiffNode::AbsDiffNode(std::array<node_ptr, 2> feats, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, feat_ind)
{
if(feats[0]->unit() != feats[1]->unit())
throw InvalidFeatureException();
......@@ -33,8 +33,8 @@ AbsDiffNode::AbsDiffNode(std::array<node_ptr, 2> feats, int rung, int feat_ind,
set_test_value();
}
AbsDiffNode::AbsDiffNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat_1, feat_2}, rung, feat_ind)
AbsDiffNode::AbsDiffNode(node_ptr feat_1, node_ptr feat_2, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat_1, feat_2}, feat_ind)
{
if(feat_1->unit() != feat_2->unit())
throw InvalidFeatureException();
......
......@@ -16,9 +16,9 @@ class AbsDiffNode: public OperatorNode<2>
public:
AbsDiffNode();
AbsDiffNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound);
AbsDiffNode(std::array<node_ptr, 2> feats, int feat_ind, double l_bound, double u_bound);
AbsDiffNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound);
AbsDiffNode(node_ptr feat_1, node_ptr feat_2, int feat_ind, double l_bound, double u_bound);
inline Unit unit(){return _feats[0]->unit();}
......
......@@ -5,8 +5,8 @@
AbsNode::AbsNode()
{}
AbsNode::AbsNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, rung, feat_ind)
AbsNode::AbsNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, feat_ind)
{
set_value();
if(is_nan() || is_const() || (util_funcs::max_abs_val<double>(value_ptr(), _n_samp) > u_bound) || (util_funcs::max_abs_val<double>(value_ptr(), _n_samp) < l_bound))
......@@ -15,8 +15,8 @@ AbsNode::AbsNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l
set_test_value();
}
AbsNode::AbsNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat}, rung, feat_ind)
AbsNode::AbsNode(node_ptr feat, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat}, feat_ind)
{
set_value();
if(is_nan() || is_const() || (util_funcs::max_abs_val<double>(value_ptr(), _n_samp) > u_bound) || (util_funcs::max_abs_val<double>(value_ptr(), _n_samp) < l_bound))
......
......@@ -15,9 +15,9 @@ class AbsNode: public OperatorNode<1>
public:
AbsNode();
AbsNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound);
AbsNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, double u_bound);
AbsNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound);
AbsNode(node_ptr feat, int feat_ind, double l_bound, double u_bound);
inline Unit unit(){return _feats[0]->unit();}
......
......@@ -3,8 +3,8 @@
AddNode::AddNode()
{}
AddNode::AddNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, rung, feat_ind)
AddNode::AddNode(std::array<node_ptr, 2> feats, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, feat_ind)
{
if(feats[0]->unit() != feats[1]->unit())
throw InvalidFeatureException();
......@@ -31,8 +31,8 @@ AddNode::AddNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l
set_test_value();
}
AddNode::AddNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat_1, feat_2}, rung, feat_ind)
AddNode::AddNode(node_ptr feat_1, node_ptr feat_2, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat_1, feat_2}, feat_ind)
{
if(feat_1->unit() != feat_2->unit())
throw InvalidFeatureException();
......
......@@ -15,9 +15,9 @@ class AddNode: public OperatorNode<2>
public:
AddNode();
AddNode(std::array<node_ptr, 2> feats, int rung, int feat_ind, double l_bound, double u_bound);
AddNode(std::array<node_ptr, 2> feats, int feat_ind, double l_bound, double u_bound);
AddNode(node_ptr feat_1, node_ptr feat_2, int rung, int feat_ind, double l_bound, double u_bound);
AddNode(node_ptr feat_1, node_ptr feat_2, int feat_ind, double l_bound, double u_bound);
inline Unit unit(){return _feats[0]->unit();}
......
......@@ -3,8 +3,8 @@
CosNode::CosNode()
{}
CosNode::CosNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, rung, feat_ind)
CosNode::CosNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, feat_ind)
{
if(feats[0]->unit() != Unit())
throw InvalidFeatureException();
......@@ -19,8 +19,8 @@ CosNode::CosNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l
set_test_value();
}
CosNode::CosNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat}, rung, feat_ind)
CosNode::CosNode(node_ptr feat, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat}, feat_ind)
{
if(feat->unit() != Unit())
throw InvalidFeatureException();
......
......@@ -15,9 +15,9 @@ class CosNode: public OperatorNode<1>
public:
CosNode();
CosNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound);
CosNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, double u_bound);
CosNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound);
CosNode(node_ptr feat, int feat_ind, double l_bound, double u_bound);
inline Unit unit(){return Unit();}
......
......@@ -3,8 +3,8 @@
CbNode::CbNode()
{}
CbNode::CbNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, rung, feat_ind)
CbNode::CbNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, feat_ind)
{
if(feats[0]->type() == NODE_TYPE::CBRT)
throw InvalidFeatureException();
......@@ -16,8 +16,8 @@ CbNode::CbNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_b
set_test_value();
}
CbNode::CbNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat}, rung, feat_ind)
CbNode::CbNode(node_ptr feat, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat}, feat_ind)
{
if(feat->type() == NODE_TYPE::CBRT)
throw InvalidFeatureException();
......
......@@ -15,9 +15,9 @@ class CbNode: public OperatorNode<1>
public:
CbNode();
CbNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound);
CbNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, double u_bound);
CbNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound);
CbNode(node_ptr feat, int feat_ind, double l_bound, double u_bound);
inline Unit unit(){return _feats[0]->unit()^(3.0);}
......
......@@ -3,8 +3,8 @@
CbrtNode::CbrtNode()
{}
CbrtNode::CbrtNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, rung, feat_ind)
CbrtNode::CbrtNode(std::array<node_ptr, 1> feats, int feat_ind, double l_bound, double u_bound):
OperatorNode(feats, feat_ind)
{
if(feats[0]->type() == NODE_TYPE::CB)
throw InvalidFeatureException();
......@@ -16,8 +16,8 @@ CbrtNode::CbrtNode(std::array<node_ptr, 1> feats, int rung, int feat_ind, double
set_test_value();
}
CbrtNode::CbrtNode(node_ptr feat, int rung, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat}, rung, feat_ind)
CbrtNode::CbrtNode(node_ptr feat, int feat_ind, double l_bound, double u_bound):
OperatorNode({feat}, feat_ind)
{
if(feat->type() == NODE_TYPE::CB)
throw InvalidFeatureException();
......
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