Feat C++ API
A feature engineering automation tool
params.cc
Go to the documentation of this file.
1 /* FEAT
2  *
3 copyright 2017 William La Cava
4 license: GNU/GPL v3
5 */
6 
7 #include "params.h"
8 #include "util/utils.h"
9 
10 namespace FT{
11 
12 using namespace Util;
13 using namespace Pop::Op;
14 
15 // Parameters::Parameters(int pop_size, int gens, string ml, bool classification,
16 // int max_stall, char ot, int verbosity, string fs, float cr,
17 // float root_xor, unsigned int max_depth,
18 // unsigned int max_dim, bool constant, string obj, bool sh, float sp,
19 // float fb, string sc, string fn, bool bckprp, int iters, float lr,
20 // int bs, bool hclimb, int maxt, bool res_xo, bool stg_xo,
21 // bool stg_xo_tol, bool sftmx, bool nrm, bool corr_mut, bool tune_init,
22 // bool tune_fin):
23 // pop_size(pop_size),
24 // gens(gens),
25 // ml(ml),
26 // classification(classification),
27 // max_stall(max_stall),
28 // cross_rate(cr),
29 // root_xo_rate(root_xor),
30 // max_depth(max_depth),
31 // max_dim(max_dim),
32 // erc(constant),
33 // shuffle(sh),
34 // split(sp),
35 // otype(ot),
36 // feedback(fb),
37 // backprop(bckprp),
38 // bp(iters, lr, bs),
39 // hillclimb(hclimb),
40 // hc(iters, lr),
41 // max_time(maxt),
42 // residual_xo(res_xo),
43 // stagewise_xo(stg_xo),
44 // stagewise_xo_tol(stg_xo),
45 // corr_delete_mutate(corr_mut),
46 // softmax_norm(sftmx),
47 // normalize(nrm),
48 // tune_initial(tune_init),
49 // tune_final(tune_fin),
50 // scorer(sc)
51 // {
52 // set_verbosity(verbosity);
53 
54 // set_functions(fs);
55 // set_objectives(obj);
56 // set_feature_names(fn);
57 // updateSize();
58 // set_otypes();
59 // n_classes = 2;
60 // set_scorer(sc);
61 // use_batch = bs>0;
62 // set_current_gen(0);
63 // }
64 
66 {
67  vector<string> default_fns {
68  "+","-","*","/","^2","^3","sqrt","sin","cos","exp","log","^",
69  "logit","tanh","gauss","relu",
70  "split","split_c",
71  "b2f","c2f","and","or","not","xor","=","<","<=",">",">=","if","ite"
72  };
73  set_functions(default_fns);
74 }
75 
76 
82 void Parameters::init(const MatrixXf& X, const VectorXf& y)
83 {
84  if (ml == "LinearRidgeRegression" && classification)
85  {
86  logger.log("Setting ML type to LR",2);
87  ml = "LR";
88  }
89  if (this->classification) // setup classification endpoint
90  {
91  this->set_classes(y);
92  }
93 
94  if (this->dtypes.size()==0) // set feature types if not set
95  this->dtypes = find_dtypes(X);
96  if (this->verbosity >= 2)
97  {
98  cout << "X data types: ";
99  for (auto dt : this->dtypes)
100  {
101  cout << dt << ", ";
102  }
103  cout << "\n";
104  }
105  this->set_scorer("", true);
106 }
107 
109 void Parameters::set_current_gen(int g) { current_gen = g; }
110 
112 void Parameters::set_scorer(string sc, bool initialized)
113 {
114  string tmp = this->scorer_;
115  if (sc.empty())
116  {
117  if (this->scorer.empty() && initialized)
118  {
119  if (classification && n_classes == 2)
120  {
121  if (ml.compare("LR") || ml.compare("SVM"))
122  scorer_ = "log";
123  else
124  scorer_ = "zero_one";
125  }
126  else if (classification){
127  if (ml.compare("LR") || ml.compare("SVM"))
128  scorer_ = "multi_log";
129  else
130  scorer_ = "bal_zero_one";
131  }
132  else
133  scorer_ = "mse";
134  }
135  }
136  else
137  scorer_ = sc;
138 
139  if (tmp != this->scorer_)
140  logger.log("scorer changed to " + scorer_,2);
141 }
142 
144 void Parameters::set_term_weights(const vector<float>& w)
145 {
146  float u = 1.0/float(terminals.size());
147  term_weights.clear();
148  if (w.empty()) // set all weights uniformly
149  {
150  for (unsigned i = 0; i < terminals.size(); ++i)
151  term_weights.push_back(u);
152  }
153  else
154  {
155  // take abs value of weights
156  vector<float> aw = w;
157  float weighted_proportion = float(w.size())/float(terminals.size());
158  float sum = 0;
159  for (unsigned i = 0; i < aw.size(); ++i)
160  {
161  aw[i] = fabs(aw[i]);
162  sum += aw[i];
163  }
164  // normalize weights to one
165  for (unsigned i = 0; i < aw.size(); ++i)
166  {
167  aw[i] = aw[i]/sum*weighted_proportion; // awesome!
168  }
169  int x = 0;
170  if (aw.size() != terminals.size())
171  THROW_LENGTH_ERROR("There are " + to_string(aw.size()) +
172  "weights and " + to_string(terminals.size()) +
173  "terminals");
174  // assign transformed weights as terminal weights
175  for (unsigned i = 0; i < terminals.size(); ++i)
176  {
177  /* if(terminals[i]->otype == 'z') */
178  /* term_weights.push_back(u); */
179  /* else */
180  /* { */
181  term_weights.push_back((1-feedback)*u + feedback*aw[x]);
182  ++x;
183  /* } */
184  }
185 
186  }
187  if (terminals.size() < 20)
188  {
189  string weights = "terminal weights: ";
190  for (unsigned i = 0; i < terminals.size(); ++i)
191  {
192  weights += ("["
193  + terminals.at(i)->variable_name
194  + " (" +
195  terminals.at(i)->otype + "): " +
196  std::to_string(term_weights.at(i))
197  + "], ");
198  }
199  weights += "\n";
200  logger.log(weights, 2);
201  }
202 }
203 
205 {
206  max_size = (pow(2,max_depth+1)-1)*max_dim;
207 }
208 
210 void Parameters::set_max_depth(unsigned int max_depth)
211 {
212  this->max_depth = max_depth;
213  updateSize();
214 }
215 
217 void Parameters::set_max_dim(unsigned int max_dim)
218 {
219  this->max_dim = max_dim;
220  updateSize();
221 }
222 
223 void Parameters::set_otype(char ot){ otype = ot; set_otypes();}
224 
226 {
227  ttypes.clear();
228  // set terminal types
229  for (const auto& t: terminals)
230  {
231  if (!in(ttypes,t->otype))
232  ttypes.push_back(t->otype);
233  }
234 }
235 
237 void Parameters::set_otypes(bool terminals_set)
238 {
239  otypes.clear();
240  // set output types
241  switch (otype)
242  {
243  case 'b': otypes.push_back('b'); break;
244  case 'f': otypes.push_back('f'); break;
245  //case 'c': otypes.push_back('c'); break;
246  default:
247  {
248  // if terminals are all boolean, remove floating point functions
249  if (ttypes.size()==1 && ttypes.at(0)=='b')
250  {
251  logger.log(string("otypes is size 1 and otypes[0]==b\n")
252  + string("setting otypes to boolean...\n"),
253  2);
254  /* size_t n = functions.size(); */
255  /* for (vector<int>::size_type i =n-1; */
256  /* i != (std::vector<int>::size_type) -1; i--){ */
257  /* if (functions.at(i)->arity['f'] >0){ */
258  /* logger.log("erasing function " + functions.at(i)->name + "\n", 2); */
259  /* functions.erase(functions.begin()+i); */
260  /* } */
261  /* } */
262 
263  otype = 'b';
264  otypes.push_back('b');
265  }
266  // if terminals are all floating, and functions are all floating,
267  // set otypes to f
268  else if (ttypes.size()==1 && ttypes.at(0)=='f')
269  {
270  int only_floating_ops=0;
271 
272  for (const auto& op : functions)
273  {
274  if (op->arity['f']==op->total_arity() && op->otype=='f')
275  ++only_floating_ops;
276  }
277  if (only_floating_ops == functions.size())
278  {
279  logger.log(string("all terminal and function types are float")
280  + string("setting otype='f'...\n"),
281  2);
282  otype='f';
283  otypes.push_back('f');
284  }
285  else
286  {
287  otypes.push_back('b');
288  otypes.push_back('f');
289  }
290  }
291  else
292  {
293  otypes.push_back('b');
294  otypes.push_back('f');
295  }
296 
297  //erasing categorical nodes if no categorical stack exists
298  /* if (terminals_set && !in(ttypes, 'c')) */
299  /* { */
300  /* size_t n = functions.size(); */
301  /* for (vector<int>::size_type i =n-1; */
302  /* i != (std::vector<int>::size_type) -1; i--){ */
303  /* if (functions.at(i)->arity['c'] >0){ */
304  /* logger.log("erasing function " + functions.at(i)->name + "\n", 2); */
305  /* functions.erase(functions.begin()+i); */
306  /* } */
307  /* } */
308  /* } */
309  break;
310  }
311  }
312 }
313 
314 std::unique_ptr<Node> Parameters::createNode(string str,
315  float d_val,
316  bool b_val,
317  size_t loc,
318  string name)
319 {
320  // variables and constants
321  if (str == "x")
322  {
323  if(dtypes.size() == 0)
324  {
325  if (feature_names.size() == 0)
326  return std::unique_ptr<Node>(new NodeVariable<float>(loc));
327  else
328  return std::unique_ptr<Node>(
329  new NodeVariable<float>(loc,'f',
330  feature_names.at(loc)));
331  }
332  else if (feature_names.size() == 0)
333  {
334  switch(dtypes[loc])
335  {
336  case 'b':
337  return std::unique_ptr<Node>(
338  new NodeVariable<bool>(loc, dtypes[loc]));
339  case 'c':
340  return std::unique_ptr<Node>(
341  new NodeVariable<int>(loc, dtypes[loc]));
342  case 'f':
343  return std::unique_ptr<Node>(
345  dtypes[loc]));
346  }
347  }
348  else
349  {
350  switch(dtypes[loc])
351  {
352  case 'b':
353  return std::unique_ptr<Node>(
354  new NodeVariable<bool>(loc, dtypes[loc],
355  feature_names.at(loc)));
356  case 'c':
357  return std::unique_ptr<Node>(
358  new NodeVariable<int>(loc, dtypes[loc],
359  feature_names.at(loc)));
360 
361  case 'f':
362  return std::unique_ptr<Node>(
363  new NodeVariable<float>(loc, dtypes[loc],
364  feature_names.at(loc)));
365  }
366  }
367  }
368  else if (str == "z")
369  return std::unique_ptr<Node>(new NodeLongitudinal(name));
370  else if (NM.node_map.find(str) != NM.node_map.end())
371  return NM.node_map[str]->clone();
372  else
373  {
374 
375  cout << "NM.node_map = \n";
376  for (auto it = NM.node_map.cbegin(); it != NM.node_map.cend(); )
377  {
378  cout << it->first << it->second->name << endl;
379  }
380  THROW_INVALID_ARGUMENT("Error: no node named '" + str + "' exists.");
381  }
382 
383  return std::unique_ptr<Node>();
384 }
385 
387 {
388  if (pg.empty())
389  protected_groups.clear();
390  else
391  {
392  pg += ','; // add delimiter to end
393  string delim=",";
394  size_t pos = 0;
395  string token;
396  while ((pos = pg.find(delim)) != string::npos)
397  {
398  token = pg.substr(0, pos);
399  protected_groups.push_back(token != "0");
400  pg.erase(0, pos + delim.length());
401  }
402  string msg = "protected_groups: ";
403  for (auto pg : protected_groups)
404  msg += pg + ",";
405  msg += "\n";
406  logger.log(msg,2);
407  }
408 }
410 {
411  string out = "";
412  for (int i = 0; i < protected_groups.size(); ++i)
413  {
414  out += protected_groups.at(i);
415  if (i < protected_groups.size() - 1)
416  out += ",";
417  }
418  return out;
419 }
420 
422 {
423  if (fn.empty())
424  feature_names.clear();
425  else
426  {
427  fn += ','; // add delimiter to end
428  string delim=",";
429  size_t pos = 0;
430  string token;
431  while ((pos = fn.find(delim)) != string::npos)
432  {
433  token = fn.substr(0, pos);
434  feature_names.push_back(token);
435  fn.erase(0, pos + delim.length());
436  }
437  }
438 }
440 {
441  return ravel(this->feature_names);
442 }
443 
444 // void Parameters::set_functions(const vector<string>& fns)
445 // {
446 // /*!
447 // * Input:
448 // *
449 // * fs: string of comma-separated Node names
450 // *
451 // * Output:
452 // *
453 // * modifies functions
454 // *
455 // */
456 // this->function_str = fs;
457 
458 // if (fs.empty())
459 // fs = "+,-,*,/,^2,^3,sqrt,sin,cos,exp,log,^,"
460 // "logit,tanh,gauss,relu,"
461 // "split,split_c,"
462 // "b2f,c2f,and,or,not,xor,=,<,<=,>,>=,if,ite";
463 // fs += ','; // add delimiter to end
464 // string delim = ",";
465 // size_t pos = 0;
466 // string token;
467 // this->functions.clear();
468 // while ((pos = fs.find(delim)) != string::npos)
469 // {
470 // token = fs.substr(0, pos);
471 
472 // functions.push_back(createNode(token));
473 
474 // fs.erase(0, pos + delim.length());
475 // }
476 
477 // string log_msg = "functions: [";
478 // for (int i =0; i < functions.size(); ++i)
479 // {
480 // log_msg += functions.at(i)->name ;
481 // if (i < functions.size()-1)
482 // log_msg += ", ";
483 // }
484 // log_msg += "]";
485 
486 // logger.log(log_msg, 3);
487 
488 // // reset output types
489 // set_otypes();
490 // }
491 
492 vector<string> Parameters::get_functions()
493 {
494  vector<string> fn_vec;
495  for (const auto& fn : this->functions)
496  fn_vec.push_back(fn->name);
497  return fn_vec;
498 }
499 
500 void Parameters::set_functions(const vector<string>& fns)
501 {
502  this->functions.clear();
503  for (const auto& f : fns)
504  functions.push_back(createNode(f));
505  // reset output types
506  set_otypes();
507 }
508 
510 {
517  //
518  // first, count up the instances of each type of terminal.
519  //
520  int b_count = 0;
521  int c_count = 0;
522  int f_count = 0;
523  int z_count = 0;
524  int total_terms = 0;
525 
526  for (const auto& term : terminals)
527  {
528  switch (term->otype)
529  {
530  case 'b':
531  ++b_count;
532  break;
533  case 'c':
534  ++c_count;
535  break;
536  case 'f':
537  ++f_count;
538  break;
539  case 'z':
540  ++z_count;
541  break;
542  }
543  ++total_terms;
544  }
545  //
546  // next, calculate the operator weights.
547  // an operators weight is defined as
548  // 1/total_args * sum ([arg_type]_count/total_terminals)
549  // summed over each arg the operator takes
550  //
551  op_weights.clear();
552  int i = 0;
553  for (const auto& op : functions)
554  {
555  op_weights.push_back(0.0);
556  int total_args = 0;
557  for (auto& kv : op->arity)
558  {
559  switch (kv.first) // kv.first is the arity type (character)
560  {
561  case 'b':
562  for (unsigned j = 0; j < kv.second; ++j)
563  op_weights.at(i) += float(b_count)/float(total_terms);
564  break;
565  case 'c':
566  for (unsigned j = 0; j < kv.second; ++j)
567  op_weights.at(i) += float(c_count)/float(total_terms);
568  break;
569  case 'f':
570  for (unsigned j = 0; j < kv.second; ++j)
571  op_weights.at(i) += float(f_count)/float(total_terms);
572  break;
573  case 'z':
574  for (unsigned j = 0; j < kv.second; ++j)
575  op_weights.at(i) += float(z_count)/float(total_terms);
576  break;
577  }
578  total_args += kv.second;
579  }
580  op_weights.at(i) /= float(total_args);
581  ++i;
582  }
583  // Now, we need to account for the output types of the operators that have non-zero
584  // weights, in addition to the terminals.
585  // So we now upweight the terminals according to the output types of the terminals that have
586  // non-zero weights.
587 
589  b_count = 0;
590  c_count = 0;
591  f_count = 0;
592  z_count = 0;
593  for (unsigned i = 0; i < functions.size(); ++i)
594  {
595  if (op_weights.at(i) > 0)
596  {
597  switch (functions.at(i)->otype)
598  {
599  case 'b':
600  ++b_count;
601  break;
602  case 'c':
603  ++c_count;
604  break;
605  case 'f':
606  ++f_count;
607  break;
608  case 'z':
609  ++z_count;
610  break;
611  }
612  }
613  ++total_ops_terms;
614  }
615  /* cout << "b_count: " << b_count << "\n" */
616  /* << "f_count: " << f_count << "\n" */
617  /* << "c_count: " << c_count << "\n" */
618  /* << "z_count: " << z_count << "\n" */
619  /* << "total_ops_terms: " << total_ops_terms << "\n"; */
620 
621  i = 0; // op_weights counter
622  for (const auto& op : functions)
623  {
624  int total_args = 0;
625  for (auto& kv : op->arity)
626  {
627  switch (kv.first) // kv.first is the arity type (character)
628  {
629  case 'b':
630  for (unsigned j = 0; j < kv.second; ++j)
631  op_weights.at(i) += float(b_count)/float(total_ops_terms);
632  break;
633  case 'c':
634  for (unsigned j = 0; j < kv.second; ++j)
635  op_weights.at(i) += float(c_count)/float(total_ops_terms);
636  break;
637  case 'f':
638  for (unsigned j = 0; j < kv.second; ++j)
639  op_weights.at(i) += float(f_count)/float(total_ops_terms);
640  break;
641  case 'z':
642  for (unsigned j = 0; j < kv.second; ++j)
643  op_weights.at(i) += float(z_count)/float(total_ops_terms);
644  break;
645  }
646  total_args += kv.second;
647  }
648  op_weights.at(i) /= float(total_args);
649  ++i;
650  }
651 
652  /* string ow = "op_weights: "; */
653  /* for (unsigned i = 0; i< functions.size(); ++i) */
654  /* ow += "(" + functions.at(i)->name + ", " + std::to_string(op_weights.at(i)) + "), "; */
655  /* ow += "\n"; */
656  /* logger.log(ow,2); */
657 }
658 
659 void Parameters::set_terminals(int nf, const LongData& Z)
660 {
661  terminals.clear();
662  num_features = nf;
663  for (size_t i = 0; i < nf; ++i)
664  terminals.push_back(createNode(string("x"), 0, 0, i));
665 
666  if(erc)
667  {
668  for (int i = 0; i < nf; ++i)
669  {
670  if(r() < 0.5)
671  terminals.push_back(createNode(string("kb"), 0, r(), 0));
672  else
673  terminals.push_back(createNode(string("kd"), r(), 0, 0));
674  }
675  }
676 
677  for (const auto &val : Z)
678  {
679  longitudinalMap.push_back(val.first);
680  terminals.push_back(createNode(string("z"), 0, 0, 0, val.first));
681  }
682  // reset output types
683  set_ttypes();
684 
685  set_otypes(true);
686  set_op_weights();
687  // set dummy term_weights to zero
688  this->set_term_weights(vector<float>());
689 }
690 
691 
692 void Parameters::set_objectives(const vector<string>& obj)
693 {
697  // obj += ','; // add delimiter to end
698  // string delim = ",";
699  // size_t pos = 0;
700  // string token;
701  // objectives.clear();
702  // while ((pos = obj.find(delim)) != string::npos)
703  // {
704  // token = obj.substr(0, pos);
705  // objectives.push_back(token);
706  // obj.erase(0, pos + delim.length());
707  // }
708  objectives=obj;
709 }
710 
711 
712 void Parameters::set_verbosity(int verbosity)
713 {
714  logger.set_log_level(verbosity);
715  this->verbosity = verbosity;
716 }
717 
718 void Parameters::set_classes(const VectorXf& y)
719 {
720  classes.clear();
721 
722  // set class labels
723  vector<float> uc = unique(y);
724 
725  string str_classes = "{";
726  for (auto c : uc)
727  str_classes += to_string(c) + ",";
728  str_classes = str_classes.substr(0,str_classes.size()-1);
729  str_classes += "}";
730 
731  // check that class labels are contiguous and start at 0
732  if (int(uc.at(0)) != 0)
733  THROW_INVALID_ARGUMENT("Class labels must start at 0 and be "
734  "contiguous. The input classes are " + str_classes);
735  vector<int> cont_classes(uc.size());
736  iota(cont_classes.begin(), cont_classes.end(), 0);
737  for (int i = 0; i < cont_classes.size(); ++i)
738  {
739  if ( int(uc.at(i)) != cont_classes.at(i))
740  THROW_INVALID_ARGUMENT("Class labels must start at 0 and be "
741  "contiguous. Passed labels = " + str_classes);
742  }
743  n_classes = uc.size();
744 
745  for (auto c : uc)
746  classes.push_back(int(c));
747 }
748 
750 {
751  // set class weights
752  class_weights.resize(n_classes);
753  sample_weights.clear();
754  for (unsigned i = 0; i < n_classes; ++i){
755  class_weights.at(i) = float(
756  (y.cast<int>().array() == int(classes.at(i))).count())/y.size();
757  class_weights.at(i) = (1 - class_weights.at(i))*float(n_classes);
758  }
759  for (unsigned i = 0; i < y.size(); ++i)
760  {
761  sample_weights.push_back(class_weights.at(int(y(i))));
762  }
763 }
764 /* void Parameters::initialize_node_map() */
765 /* { */
766 
767 /* this->node_map = { */
768 /* //arithmetic operators */
769 /* { "+", new NodeAdd({1.0,1.0})}, */
770 /* { "-", new NodeSubtract({1.0,1.0})}, */
771 /* { "*", new NodeMultiply({1.0,1.0})}, */
772 /* { "/", new NodeDivide({1.0,1.0})}, */
773 /* { "sqrt", new NodeSqrt({1.0})}, */
774 /* { "sin", new NodeSin({1.0})}, */
775 /* { "cos", new NodeCos({1.0})}, */
776 /* { "tanh", new NodeTanh({1.0})}, */
777 /* { "^2", new NodeSquare({1.0})}, */
778 /* { "^3", new NodeCube({1.0})}, */
779 /* { "^", new NodeExponent({1.0})}, */
780 /* { "exp", new NodeExponential({1.0})}, */
781 /* { "gauss", new NodeGaussian({1.0})}, */
782 /* { "gauss2d", new Node2dGaussian({1.0, 1.0})}, */
783 /* { "log", new NodeLog({1.0}) }, */
784 /* { "logit", new NodeLogit({1.0}) }, */
785 /* { "relu", new NodeRelu({1.0}) }, */
786 /* { "b2f", new NodeFloat<bool>() }, */
787 /* { "c2f", new NodeFloat<int>() }, */
788 
789 /* // logical operators */
790 /* { "and", new NodeAnd() }, */
791 /* { "or", new NodeOr() }, */
792 /* { "not", new NodeNot() }, */
793 /* { "xor", new NodeXor() }, */
794 /* { "=", new NodeEqual() }, */
795 /* { ">", new NodeGreaterThan() }, */
796 /* { ">=", new NodeGEQ() }, */
797 /* { "<", new NodeLessThan() }, */
798 /* { "<=", new NodeLEQ() }, */
799 /* { "split", new NodeSplit<float>() }, */
800 /* { "fuzzy_split", new NodeFuzzySplit<float>() }, */
801 /* { "fuzzy_fixed_split", new NodeFuzzyFixedSplit<float>() }, */
802 /* { "split_c", new NodeSplit<int>() }, */
803 /* { "fuzzy_split_c", new NodeFuzzySplit<int>() }, */
804 /* { "fuzzy_fixed_split_c", new NodeFuzzyFixedSplit<int>() }, */
805 /* { "if", new NodeIf() }, */
806 /* { "ite", new NodeIfThenElse() }, */
807 /* { "step", new NodeStep() }, */
808 /* { "sign", new NodeSign() }, */
809 
810 /* // longitudinal nodes */
811 /* { "mean", new NodeMean() }, */
812 /* { "median", new NodeMedian() }, */
813 /* { "max", new NodeMax() }, */
814 /* { "min", new NodeMin() }, */
815 /* { "variance", new NodeVar() }, */
816 /* { "skew", new NodeSkew() }, */
817 /* { "kurtosis", new NodeKurtosis() }, */
818 /* { "slope", new NodeSlope() }, */
819 /* { "count", new NodeCount() }, */
820 /* { "recent", new NodeRecent() }, */
821 /* // terminals */
822 /* { "variable_f", new NodeVariable<float>() }, */
823 /* { "variable_b", new NodeVariable<bool>() }, */
824 /* { "variable_c", new NodeVariable<int>() }, */
825 /* { "constant_b", new NodeConstant(false) }, */
826 /* { "constant_d", new NodeConstant(0.0) }, */
827 /* }; */
828 /* } */
829 }
void set_log_level(int &verbosity)
Definition: logger.cc:33
string log(string m, int v, string sep="\n") const
print message with verbosity control.
Definition: logger.cc:54
std::map< string, std::pair< vector< ArrayXf >, vector< ArrayXf > > > LongData
Definition: data.h:23
#define THROW_LENGTH_ERROR(err)
Definition: error.h:32
#define THROW_INVALID_ARGUMENT(err)
Definition: error.h:31
static NodeMap NM
Definition: nodemap.h:93
std::string ravel(const vector< string > &v, string sep)
takes a vector string and returns it as a delimited string.
Definition: utils.cc:297
vector< char > find_dtypes(const MatrixXf &X)
determines data types of columns of matrix X.
Definition: utils.cc:49
static Logger & logger
Definition: logger.h:46
bool in(const vector< T > v, const T &i)
check if element is in vector.
Definition: utils.h:47
vector< T > unique(vector< T > w)
returns unique elements in vector
Definition: utils.h:336
static Rnd & r
Definition: rnd.h:135
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
int f_count
Definition: params.cc:522
int b_count
Definition: params.cc:520
int total_ops_terms
Definition: params.cc:588
int z_count
Definition: params.cc:523
int total_terms
Definition: params.cc:524
int c_count
Definition: params.cc:521
string get_protected_groups()
Definition: params.cc:409
void set_terminals(int nf, const LongData &Z)
set the terminals with longitudinal data
Definition: params.cc:659
void set_sample_weights(VectorXf &y)
sets the weights of each sample (and class weights)
Definition: params.cc:749
vector< string > get_functions()
returns the set of functions to use determined at run-time.
void set_current_gen(int g)
sets current generation
Definition: params.cc:109
std::unique_ptr< Node > createNode(std::string str, float d_val=0, bool b_val=false, size_t loc=0, string name="")
return unique pointer to a node based on the string passed
Definition: params.cc:314
void set_op_weights()
sets weights for operators.
void set_feature_names(string fn)
Definition: params.cc:421
void set_functions(const vector< string > &fns)
sets available functions and verifies output types.
void init(const MatrixXf &X, const VectorXf &y)
Definition: params.cc:82
void set_otype(char ot)
Definition: params.cc:223
void set_max_dim(unsigned int max_dim)
set maximum dimensionality of programs
Definition: params.cc:217
string get_feature_names()
Definition: params.cc:439
void set_ttypes()
Definition: params.cc:225
void set_max_depth(unsigned int max_depth)
set max depth of programs
Definition: params.cc:210
void set_verbosity(int verbosity)
set level of debug info
Definition: params.cc:712
void set_otypes(bool terminals_set=false)
set the output types of programs
Definition: params.cc:237
void updateSize()
max_size is max_dim binary trees of max_depth
Definition: params.cc:204
void set_protected_groups(string fn)
Definition: params.cc:386
void set_term_weights(const vector< float > &w)
sets weights for terminals.
Definition: params.cc:144
void set_objectives(const vector< string > &obj)
set the objectives
Definition: params.cc:692
void set_scorer(string sc="", bool initialized=false)
sets scorer type
Definition: params.cc:112
void set_classes(const VectorXf &y)
sets the number of classes based on target vector y.
Definition: params.cc:718
std::map< std::string, Node * > node_map
Definition: nodemap.h:16