Feat C++ API
A feature engineering automation tool
population.h
Go to the documentation of this file.
1 /* FEAT
2 copyright 2017 William La Cava
3 license: GNU/GPL v3
4 */
5 #ifndef POPULATION_H
6 #define POPULATION_H
7 
8 //#include "node.h" // including node.h since definition of node is in the header
9 #include "individual.h"
10 using std::vector;
11 using std::string;
12 using Eigen::Map;
13 
14 namespace FT{
15 
20 namespace Pop{
22 extern int last;
27 struct Population
28 {
29  vector<Individual> individuals;
30 
31  Population(int p = 0);
32 
33  ~Population();
34 
36  void init(const Individual& starting_model,
37  const Parameters& params,
38  bool random = false,
39  string filename=""
40  );
41 
43  void resize(int pop_size);
44 
46  void update(vector<size_t> survivors);
47 
49  int size();
50 
52  void add(Individual&);
53 
55  const Individual operator [](size_t i) const;
56 
57  const Individual & operator [](size_t i);
58 
60  string print_eqns(bool just_offspring=false, string sep="\n");
61 
63  vector<size_t> sorted_front(unsigned);
64 
67  {
70  bool operator()(size_t i, size_t j)
71  {
72  return pop.individuals[i].set_complexity() < pop.individuals[j].set_complexity();
73  }
74  };
75 
78  {
81  bool operator()(size_t i, size_t j)
82  {
83  return (pop.individuals[i].fitness == pop.individuals[j].fitness &&
84  pop.individuals[i].set_complexity() == pop.individuals[j].set_complexity());
85  }
86  };
87 
88  // save serialized population
89  void save(string filename);
90  // load serialized population
91  void load(string filename);
92 
93 };
94 //TODO
95 /* void from_json(const json& j, Population& p); */
96 /* void to_json(json& j, const Population& p); */
98 }//Pop
99 }//FT
100 #endif
individual programs in the population
Definition: individual.h:31
int last
Definition: population.cc:11
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Archive, individuals)
main Feat namespace
Definition: data.cc:13
int i
Definition: params.cc:552
holds the hyperparameters for Feat.
Definition: params.h:25
check for same fitness and complexity to filter uniqueness.
Definition: population.h:78
bool operator()(size_t i, size_t j)
Definition: population.h:81
Sort population in increasing complexity.
Definition: population.h:67
bool operator()(size_t i, size_t j)
Definition: population.h:70
Defines a population of programs and functions for constructing them.
Definition: population.h:28
void load(string filename)
Definition: population.cc:165
void add(Individual &)
adds a program to the population.
Definition: population.cc:112
const Individual operator[](size_t i) const
setting and getting from individuals vector
Definition: population.cc:33
void update(vector< size_t > survivors)
reduce programs to the indices in survivors.
Definition: population.cc:97
string print_eqns(bool just_offspring=false, string sep="\n")
return population equations.
Definition: population.cc:121
int size()
returns population size
Definition: population.cc:31
vector< size_t > sorted_front(unsigned)
return complexity-sorted Pareto front indices.
Definition: population.cc:135
void resize(int pop_size)
update individual vector size
Definition: population.cc:25
void init(const Individual &starting_model, const Parameters &params, bool random=false, string filename="")
initialize population of programs with a starting model and/or from file
Definition: population.cc:38
vector< Individual > individuals
individual programs
Definition: population.h:29
void save(string filename)
Definition: population.cc:150