Feat C++ API
A feature engineering automation tool
n_median.cc
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 #include "n_median.h"
6 #include "../../../util/utils.h"
7 
8 namespace FT{
9 
10  namespace Pop{
11  namespace Op{
13  {
14  name = "median";
15  otype = 'f';
16  arity['z'] = 1;
17  complexity = 1;
18  }
19 
20  #ifndef USE_CUDA
22  void NodeMedian::evaluate(const Data& data, State& state)
23  {
24  ArrayXf tmp(state.z.top().first.size());
25 
26  int x;
27 
28  for(x = 0; x < state.z.top().first.size(); x++)
29  tmp(x) = median(limited(state.z.top().first[x]));
30 
31  state.z.pop();
32 
33  state.push<float>(tmp);
34 
35  }
36  #else
37  void NodeMedian::evaluate(const Data& data, State& state)
38  {
39 
40  ArrayXf tmp(state.z.top().first.size());
41 
42  int x;
43 
44  for(x = 0; x < state.z.top().first.size(); x++)
45  tmp(x) = median(limited(state.z.top().first[x]));
46 
47  state.z.pop();
48 
49  GPU_Variable(state.dev_f, tmp.data(), state.idx[otype], state.N);
50 
51 
52  }
53  #endif
54 
57  {
58  state.push<float>("median(" + state.zs.pop() + ")");
59  }
60 
61  NodeMedian* NodeMedian::clone_impl() const { return new NodeMedian(*this); }
62 
63  NodeMedian* NodeMedian::rnd_clone_impl() const { return new NodeMedian(); }
64  }
65  }
66 }
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
NodeMedian * clone_impl() const override
Definition: n_median.cc:61
void evaluate(const Data &data, State &state)
Evaluates the node and updates the state states.
Definition: n_median.cc:22
void eval_eqn(State &state)
Evaluates the node symbolically.
Definition: n_median.cc:56
NodeMedian * rnd_clone_impl() const override
Definition: n_median.cc:63
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 median(const ArrayXf &v)
calculate median
Definition: utils.cc:89
main Feat namespace
Definition: data.cc:13
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