Feat C++ API
A feature engineering automation tool
nsga2.h
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 #ifndef PARETO_H
6 #define PARETO_H
7 
8 #include "selection_operator.h"
9 
10 namespace FT{
11 
12  namespace Sel{
14 
18  {
21  NSGA2(bool surv);
22 
23  ~NSGA2();
24 
26  vector<size_t> select(Population& pop,
27  const Parameters& p, const Data& d);
28 
30  vector<size_t> survive(Population& pop,
31  const Parameters& p, const Data& d);
32 
33  //< the Pareto fronts
34  vector<vector<int>> front;
35 
36  //< Fast non-dominated sorting
37  void fast_nds(vector<Individual>&);
38 
39  //< crowding distance of a front i
40  void crowding_distance(Population&, int);
41 
42  private:
43 
45  struct sort_n
46  {
47  const Population& pop;
48  sort_n(const Population& population) : pop(population) {};
49  bool operator() (int i, int j) {
50  const Individual& ind1 = pop.individuals[i];
51  const Individual& ind2 = pop.individuals[j];
52  if (ind1.rank < ind2.rank)
53  return true;
54  else if (ind1.rank == ind2.rank &&
55  ind1.crowd_dist > ind2.crowd_dist)
56  return true;
57  return false;
58  };
59  };
60 
63  {
64  const Population& pop;
65  int m;
66  comparator_obj(const Population& population, int index)
67  : pop(population), m(index) {};
68  bool operator() (int i, int j) { return pop[i].obj[m] < pop[j].obj[m]; };
69  };
70 
71  size_t tournament(vector<Individual>& pop, size_t i, size_t j) const;
72  };
73 
74  }
75 
76 }
77 #endif
data holding X, y, and Z data
Definition: data.h:42
individual programs in the population
Definition: individual.h:31
float crowd_dist
crowding distance on the Pareto front
Definition: individual.h:49
unsigned int rank
pareto front rank
Definition: individual.h:48
T pop(vector< T > *v)
Definition: auto_backprop.h:49
main Feat namespace
Definition: data.cc:13
int i
Definition: params.cc:552
holds the hyperparameters for Feat.
Definition: params.h:25
Defines a population of programs and functions for constructing them.
Definition: population.h:28
vector< Individual > individuals
individual programs
Definition: population.h:29
sort based on objective m
Definition: nsga2.h:63
comparator_obj(const Population &population, int index)
Definition: nsga2.h:66
int m
objective index
Definition: nsga2.h:65
const Population & pop
population address
Definition: nsga2.h:64
bool operator()(int i, int j)
Definition: nsga2.h:68
sort based on rank, breaking ties with crowding distance
Definition: nsga2.h:46
sort_n(const Population &population)
Definition: nsga2.h:48
bool operator()(int i, int j)
Definition: nsga2.h:49
const Population & pop
population address
Definition: nsga2.h:47
NSGA2(bool surv)
Definition: nsga2.cc:16
void fast_nds(vector< Individual > &)
Definition: nsga2.cc:121
vector< size_t > survive(Population &pop, const Parameters &p, const Data &d)
survival according to the survival scheme of NSGA-II
Definition: nsga2.cc:72
vector< size_t > select(Population &pop, const Parameters &p, const Data &d)
selection according to the survival scheme of NSGA-II
Definition: nsga2.cc:39
size_t tournament(vector< Individual > &pop, size_t i, size_t j) const
Definition: nsga2.cc:20
vector< vector< int > > front
Definition: nsga2.h:34
void crowding_distance(Population &, int)
Definition: nsga2.cc:197
base class for selection operators.