Feat C++ API
A feature engineering automation tool
n_slope.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_slope.h"
7 #include "../../../util/utils.h"
8 
9 namespace FT{
10 
11  namespace Pop{
12  namespace Op{
14  {
15  name = "slope";
16  otype = 'f';
17  arity['z'] = 1;
18  complexity = 4;
19  }
20 
21  #ifndef USE_CUDA
23  void NodeSlope::evaluate(const Data& data, State& state)
24  {
25  ArrayXf tmp(state.z.top().first.size());
26 
27  for(int x = 0; x < state.z.top().first.size(); x++)
28  {
29  /* cout << "x: " << x << "\n"; */
30  /* cout << "value: " << state.z.top().first[x].transpose() << "\n"; */
31  /* cout << "date: " << state.z.top().second[x].transpose() << "\n"; */
32  tmp(x) = slope(limited(state.z.top().second[x]),
33  limited(state.z.top().first[x]));
34  /* cout << "slope: " << tmp(x) << "\n"; */
35  }
36 
37  state.z.pop();
38 
39  state.push<float>(tmp);
40 
41  }
42  #else
43  void NodeSlope::evaluate(const Data& data, State& state)
44  {
45 
46  ArrayXf tmp(state.z.top().first.size());
47 
48  for(int x = 0; x < state.z.top().first.size(); x++)
49  tmp(x) = slope(limited(state.z.top().first[x]), limited(state.z.top().second[x]));
50 
51  state.z.pop();
52 
53  GPU_Variable(state.dev_f, tmp.data(), state.idx[otype], state.N);
54 
55 
56  }
57  #endif
58 
61  {
62  state.push<float>("slope(" + state.zs.pop() + ")");
63  }
64 
65  float NodeSlope::slope(const ArrayXf& x, const ArrayXf& y)
66  {
67  float varx = variance(x);
68  if (varx > NEAR_ZERO)
69  return covariance(x, y)/varx;
70  else
71  return 0;
72  }
73 
74  NodeSlope* NodeSlope::clone_impl() const { return new NodeSlope(*this); }
75 
76  NodeSlope* NodeSlope::rnd_clone_impl() const { return new NodeSlope(); }
77  }
78  }
79 }
data holding X, y, and Z data
Definition: data.h:42
type pop()
returns true or false depending on stack is empty or not
Definition: state.h:55
type & top()
returns element at particular location in stack
Definition: state.h:69
NodeSlope * clone_impl() const override
Definition: n_slope.cc:74
float slope(const ArrayXf &x, const ArrayXf &y)
Definition: n_slope.cc:65
void evaluate(const Data &data, State &state)
Evaluates the node and updates the state states.
Definition: n_slope.cc:23
NodeSlope * rnd_clone_impl() const override
Definition: n_slope.cc:76
void eval_eqn(State &state)
Evaluates the node symbolically.
Definition: n_slope.cc:60
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
void GPU_Variable(float *dev_x, float *host_x, size_t idx, size_t N)
float covariance(const ArrayXf &x, const ArrayXf &y)
covariance of x and y
Definition: utils.cc:164
float variance(const ArrayXf &v, float mean)
calculate variance when mean provided
Definition: utils.cc:127
main Feat namespace
Definition: data.cc:13
static float NEAR_ZERO
Definition: init.h:46
contains various types of State actually used by feat
Definition: state.h:102
Stack< string > zs
longitudinal node string stack
Definition: state.h:110
Stack< std::pair< vector< ArrayXf >, vector< ArrayXf > > > z
longitudinal node stack
Definition: state.h:106
void push(Eigen::Array< T, Eigen::Dynamic, 1 > value)
Definition: state.h:123