Feat C++ API
A feature engineering automation tool
node.cc
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 #include "node.h"
6 
7 namespace FT{
8 
9  namespace Pop{
10  namespace Op{
12  {
13  arity['f'] = 0;
14  arity['b'] = 0;
15  arity['c'] = 0;
16  arity['z'] = 0;
17  }
18 
19  unsigned int Node::total_arity()
20  {
21  if(arity.find('f') == arity.end())
22  arity['f'] = 0;
23 
24  if(arity.find('b') == arity.end())
25  arity['b'] = 0;
26 
27  if(arity.find('c') == arity.end())
28  arity['c'] = 0;
29 
30  if(arity.find('z') == arity.end())
31  arity['z'] = 0;
32 
33  return arity['f'] + arity['b'] + arity['c'] + arity['z'];
34  }
35 
37  ArrayXf Node::limited(ArrayXf x)
38  {
39  x = (isnan(x)).select(0,x);
40  x = (x < MIN_FLT).select(MIN_FLT,x);
41  x = (x > MAX_FLT).select(MAX_FLT,x);
42  return x;
43  };
44 
46  void Node::eval_complexity(map<char, vector<unsigned int>>& cstate)
47  {
54  int c_args=1; // sum complexity of the arguments
55  for (const auto& a: arity)
56  {
57  for (unsigned int i = 0; i< a.second; ++i)
58  {
59  c_args += cstate[a.first].back();
60  cstate[a.first].pop_back();
61 
62  }
63  }
64  cstate[otype].push_back(complexity*c_args);
65 
66  }
67 
69  void Node::eval_complexity_db(map<char, vector<string>>& cstate)
70  {
78  // sum complexity of the arguments
79 
80  string c_args="1";
81  if (total_arity() ==0)
82  cstate[otype].push_back(c_args);
83  else{
84  for (const auto& a: arity)
85  {
86  for (unsigned int i = 0; i< a.second; ++i)
87  {
88  c_args = "(" + c_args + "+"
89  + cstate[a.first].back() + ")";
90  cstate[a.first].pop_back();
91 
92  }
93  }
94  cstate[otype].push_back(std::to_string(complexity)
95  + "*" + c_args);
96  }
97  }
98 
100  std::unique_ptr<Node> Node::clone() const
101  { return std::unique_ptr<Node>(clone_impl()); }
102 
104  std::unique_ptr<Node> Node::rnd_clone() const
105  {return std::unique_ptr<Node>(rnd_clone_impl());}
106 
107  }
108  }
109 }
unsigned int total_arity()
Definition: node.cc:19
void eval_complexity(map< char, vector< unsigned int >> &cstate)
evaluates complexity of this node in the context of its child nodes.
Definition: node.cc:46
std::unique_ptr< Node > rnd_clone() const
makes a randomized unique copy ofnode
Definition: node.cc:104
virtual Node * clone_impl() const =0
std::map< char, unsigned int > arity
arity of the operator
Definition: node.h:59
ArrayXf limited(ArrayXf x)
limits node output to be between MIN_FLT and MAX_FLT
Definition: node.cc:37
virtual Node * rnd_clone_impl() const =0
std::unique_ptr< Node > clone() const
makes a unique copy of this node
Definition: node.cc:100
void eval_complexity_db(map< char, vector< string >> &cstate)
evaluates complexity of this node in the context of its child nodes.
Definition: node.cc:69
char otype
output type
Definition: node.h:58
int complexity
complexity of node
Definition: node.h:60
ArrayXb isnan(const ArrayXf &x)
returns true for elements of x that are NaN
Definition: utils.cc:226
std::string to_string(const T &value)
template function to convert objects to string for logging
Definition: utils.h:422
main Feat namespace
Definition: data.cc:13
int i
Definition: params.cc:552
static float MAX_FLT
Definition: init.h:47
static float MIN_FLT
Definition: init.h:48