Feat C++ API
A feature engineering automation tool
node.h
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 #ifndef NODE_H
6 #define NODE_H
7 
8 #include <map>
9 #include <memory>
10 #include <vector>
11 #include <iostream>
12 #include <Eigen/Dense>
13 #include "../../init.h"
14 #include "../../dat/state.h"
15 #include "../../dat/data.h"
16 #include "../../util/rnd.h"
17 #include "../../util/error.h"
18 #include "../../util/utils.h"
19 using std::vector;
20 using std::string;
21 using std::map;
22 using Eigen::MatrixXf;
23 using Eigen::VectorXf;
24 using Eigen::ArrayXf;
25 typedef Eigen::Array<bool,Eigen::Dynamic,1> ArrayXb;
26 #define MAX_FLT std::numeric_limits<float>::max()
27 #define MIN_FLT std::numeric_limits<float>::lowest()
28 
29 #define MAX_INT std::numeric_limits<int>::max()
30 #define MIN_INT std::numeric_limits<int>::lowest()
31 
32 #ifdef USE_CUDA
33  #include "../cuda-op/kernels.h"
34 #endif
35 
36 
37 namespace FT{
38 
39  using namespace Util;
40  using namespace Dat;
41 
42 namespace Pop{
47 namespace Op{
49 
53  class Node
54  {
55  public:
56  string name;
57  string variable_name;
58  char otype;
59  std::map<char, unsigned int> arity;
60  int complexity;
61  int visits = 0;
62 
63  Node();
64 
65  virtual ~Node(){}
66 
68  virtual void evaluate(const Data& data, State& state) = 0;
69 
71  virtual void eval_eqn(State& state) = 0;
72 
73  // total arity
74  unsigned int total_arity();
75 
77  ArrayXf limited(ArrayXf x);
78 
80  void eval_complexity(map<char, vector<unsigned int>>& cstate);
81 
83  void eval_complexity_db(map<char, vector<string>>& cstate);
84 
86  virtual bool isNodeDx() {return false;};
87  virtual bool isNodeTrain() {return false;};
88 
90  std::unique_ptr<Node> clone() const;
91 
93  std::unique_ptr<Node> rnd_clone() const;
94 
95  protected:
96  virtual Node* clone_impl() const = 0;
97  virtual Node* rnd_clone_impl() const = 0;
98  };
99 
100  // macro to define from_json and to_json
102 }
103 }
104 }
105 #endif
data holding X, y, and Z data
Definition: data.h:42
Represents nodes in a program.
Definition: node.h:54
string name
node type
Definition: node.h:56
virtual Node * clone_impl() const =0
virtual void eval_eqn(State &state)=0
evaluates the node symbolically
std::map< char, unsigned int > arity
arity of the operator
Definition: node.h:59
virtual void evaluate(const Data &data, State &state)=0
Evaluates the node and updates the state states.
virtual Node * rnd_clone_impl() const =0
virtual bool isNodeTrain()
Definition: node.h:87
virtual bool isNodeDx()
check of node type
Definition: node.h:86
string variable_name
variable name, if any
Definition: node.h:57
char otype
output type
Definition: node.h:58
int complexity
complexity of node
Definition: node.h:60
virtual ~Node()
Definition: node.h:65
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Log_Stats, generation, time, min_loss, min_loss_v, med_loss, med_loss_v, med_size, med_complexity, med_num_params, med_dim)
main Feat namespace
Definition: data.cc:13
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
Definition: node.h:25
contains various types of State actually used by feat
Definition: state.h:102