48 int starting_size = 1;
50 if (!filename.empty())
55 cout <<
"individuals.size(): " << this->
individuals.size() << endl;
56 cout <<
"params.pop_size: " << params.
pop_size << endl;
64 else if (starting_size == params.
pop_size)
66 WARN(
"The first model provided in the startup file is going "
67 "to get overwritten by the initial (linear) model. "
68 "To avoid this, increase pop_size by 1."
74 WARN(
"Too many models provided in the startup file ("
75 +
to_string(starting_size) +
"); pop_size is set to "
77 "to get overwritten by the initial (linear) model.");
90 #pragma omp parallel for
104 std::iota(pop_idx.begin(),pop_idx.end(),0);
105 std::reverse(pop_idx.begin(),pop_idx.end());
106 for (
const auto&
i : pop_idx)
107 if (!
in(survivors,
i))
146 pf.resize(std::distance(pf.begin(),it));
153 if (!filename.empty())
156 out.open(
"pop.json");
162 logger.
log(
"Saved population to file " + filename, 1);
168 std::ifstream indata;
169 indata.open(filename);
176 json j = json::parse(line);
179 logger.
log(
"Loaded population from " + filename +
" of size = "
individual programs in the population
string log(string m, int v, string sep="\n") const
print message with verbosity control.
#define THROW_INVALID_ARGUMENT(err)
void from_json(const json &j, NodeVector &nv)
void to_json(json &j, const NodeVector &nv)
bool in(const vector< T > v, const T &i)
check if element is in vector.
vector< T > unique(vector< T > w)
returns unique elements in vector
std::string to_string(const T &value)
template function to convert objects to string for logging
holds the hyperparameters for Feat.
int pop_size
population size
check for same fitness and complexity to filter uniqueness.
Sort population in increasing complexity.
void load(string filename)
void add(Individual &)
adds a program to the population.
const Individual operator[](size_t i) const
setting and getting from individuals vector
void update(vector< size_t > survivors)
reduce programs to the indices in survivors.
string print_eqns(bool just_offspring=false, string sep="\n")
return population equations.
int size()
returns population size
vector< size_t > sorted_front(unsigned)
return complexity-sorted Pareto front indices.
void resize(int pop_size)
update individual vector size
void init(const Individual &starting_model, const Parameters ¶ms, bool random=false, string filename="")
initialize population of programs with a starting model and/or from file
vector< Individual > individuals
individual programs
void save(string filename)