Feat C++ API
A feature engineering automation tool
n_if.cc
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 
6 #include "n_if.h"
7 
8 namespace FT{
9 
10 
11  namespace Pop{
12  namespace Op{
13  NodeIf::NodeIf(vector<float> W0)
14  {
15  name = "if";
16  otype = 'f';
17  arity['f'] = 1;
18  arity['b'] = 1;
19  complexity = 5;
20  W.push_back(0);
21  }
22 
23 
24  #ifndef USE_CUDA
26  void NodeIf::evaluate(const Data& data, State& state)
27  {
28  state.push<float>(limited(state.pop<bool>().select(state.pop<float>(),0)));
29  }
30  #else
31  void NodeIf::evaluate(const Data& data, State& state)
32  {
33  GPU_If(state.dev_f, state.dev_b, state.idx['f'], state.idx['b'], state.N);
34  }
35  #endif
36 
38  void NodeIf::eval_eqn(State& state)
39  {
40  state.push<float>("if(" + state.popStr<bool>() + "," + state.popStr<float>() + "," + "0)");
41  }
42 
43  ArrayXf NodeIf::getDerivative(Trace& state, int loc)
44  {
45  ArrayXf& xf = state.get<float>()[state.size<float>()-1];
46  ArrayXb& xb = state.get<bool>()[state.size<bool>()-1];
47 
48  switch (loc) {
49  case 1: // d/dW[0]
50  return ArrayXf::Zero(xf.size());
51  case 0: // d/dx1
52  default:
53  return xb.cast<float>();
54  /* .select(ArrayXf::Ones(state.f[state.f.size()-1].size(), */
55  /* ArrayXf::Zero(state.f[state.f.size()-1].size()); */
56  }
57  }
58 
59  NodeIf* NodeIf::clone_impl() const { return new NodeIf(*this); }
60 
61  NodeIf* NodeIf::rnd_clone_impl() const { return new NodeIf(); }
62  }
63  }
64 }
data holding X, y, and Z data
Definition: data.h:42
std::vector< float > W
Definition: n_Dx.h:16
ArrayXf getDerivative(Trace &state, int loc)
Definition: n_if.cc:43
NodeIf * clone_impl() const override
Definition: n_if.cc:59
void eval_eqn(State &state)
Evaluates the node symbolically.
Definition: n_if.cc:38
NodeIf(vector< float > W0=vector< float >())
Definition: n_if.cc:13
NodeIf * rnd_clone_impl() const override
Definition: n_if.cc:61
void evaluate(const Data &data, State &state)
Evaluates the node and updates the state states.
Definition: n_if.cc:26
string name
node type
Definition: node.h:56
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
char otype
output type
Definition: node.h:58
int complexity
complexity of node
Definition: node.h:60
Eigen::Array< bool, Eigen::Dynamic, 1 > ArrayXb
Definition: data.h:21
void GPU_If(float *xf, bool *xb, size_t idxf, size_t idxb, size_t N)
main Feat namespace
Definition: data.cc:13
contains various types of State actually used by feat
Definition: state.h:102
string popStr()
Definition: state.h:143
Eigen::Array< T, Eigen::Dynamic, 1 > pop()
Definition: state.h:128
void push(Eigen::Array< T, Eigen::Dynamic, 1 > value)
Definition: state.h:123
used for tracing stack outputs for backprop algorithm.
Definition: state.h:232
unsigned int size()
Definition: state.h:242
vector< Eigen::Array< T, Eigen::Dynamic, 1 > > & get()
Definition: state.h:237