Engine (and parameters)

Contents

Engine (and parameters)#

struct Parameters#

Public Functions

inline Parameters()#
inline ~Parameters()#
inline void set_verbosity(int new_verbosity)#
inline int get_verbosity()#
inline void set_random_state(int new_random_state)#
inline int get_random_state()#
inline void set_pop_size(int new_pop_size)#
inline int get_pop_size()#
inline void set_max_gens(int new_max_gens)#
inline int get_max_gens()#
inline void set_max_stall(int new_max_stall)#
inline int get_max_stall()#
inline void set_max_time(int new_max_time)#
inline int get_max_time()#
inline void set_scorer_(string new_scorer_)#
inline string get_scorer_()#
inline void set_load_population(string new_load_population)#
inline string get_load_population()#
inline void set_save_population(string new_save_population)#
inline string get_save_population()#
inline string get_logfile()#
inline void set_logfile(string s)#
inline void set_current_gen(unsigned int gen)#
inline unsigned int get_current_gen()#
inline void set_num_islands(int new_num_islands)#
inline int get_num_islands()#
inline void set_max_depth(unsigned new_max_depth)#
inline unsigned get_max_depth() const#
inline void set_n_jobs(int new_n_jobs)#
inline int get_n_jobs()#
inline void set_max_size(unsigned new_max_size)#
inline unsigned get_max_size() const#
inline void set_objectives(vector<string> new_objectives)#
inline vector<string> get_objectives()#
inline void set_sel(string new_sel)#
inline string get_sel()#
inline void set_surv(string new_surv)#
inline string get_surv()#
inline void set_cx_prob(float new_cx_prob)#
inline float get_cx_prob()#
inline void set_mig_prob(float new_mig_prob)#
inline float get_mig_prob()#
inline void set_use_arch(bool new_use_arch)#
inline bool get_use_arch()#
inline void set_val_from_arch(bool new_val_from_arch)#
inline bool get_val_from_arch()#
inline void set_classification(bool c)#
inline bool get_classification()#
inline void set_shuffle_split(bool shuff)#
inline bool get_shuffle_split()#
inline void set_n_classes(unsigned int new_n_classes)#
inline unsigned int get_n_classes()#
inline void set_validation_size(float s)#
inline float get_validation_size()#
inline void set_feature_names(vector<string> vn)#
inline vector<string> get_feature_names()#
inline void set_batch_size(float c)#
inline float get_batch_size()#
inline void set_mutation_probs(std::map<std::string, float> new_mutation_probs)#
inline std::map<std::string, float> get_mutation_probs()#
inline void set_functions(std::unordered_map<std::string, float> new_functions)#
inline std::unordered_map<std::string, float> get_functions()#

Public Members

int random_state = 0#
int verbosity = 0#
string mode = "regression"#
unsigned int current_gen = 1#
int pop_size = 100#
int max_gens = 100#
int max_stall = 0#
int max_time = -1#
unsigned int max_depth = 6#
unsigned int max_size = 50#
vector<string> objectives = {"error", "complexity"}#
string sel = "lexicase"#
string surv = "nsga2"#
std::unordered_map<string, float> functions#
int num_islands = 5#
bool use_arch = false#
bool val_from_arch = true#
std::map<std::string, float> mutation_probs = {{"point", 0.167}, {"insert", 0.167}, {"delete", 0.167}, {"subtree", 0.167}, {"toggle_weight_on", 0.167}, {"toggle_weight_off", 0.167}}#
float cx_prob = 0.2#

cross rate for variation

float mig_prob = 0.05#
string scorer_ = "mse"#

actual loss function used, determined by error

vector<int> classes#

class labels

vector<float> class_weights#

weights for each class

vector<float> sample_weights#

weights for each sample

bool classification#
unsigned int n_classes#
bool shuffle_split = false#
float validation_size = 0.75#
vector<string> feature_names = {}#
float batch_size = 0.0#
string load_population = ""#
string save_population = ""#
string logfile = ""#
int n_jobs = 1#

number of parallel jobs -1 use all threads; 0 use same as number of islands; positive number specify the amouut of threads

template<ProgramType T>
class Engine#

The Engine class represents the core engine of the brush library.

It encapsulates the functionality for training and predicting with programs in a genetic programming framework. The Engine class manages the population of programs, selection algorithms, evaluation code, variation operators, and survival algorithms. It also provides methods for training the model, making predictions, and accessing runtime statistics.

The Engine class is parameterized by the program type T, which determines the type of programs that can be evolved and evaluated by the engine.

Public Functions

inline Engine(const Parameters &p = Parameters())#
inline ~Engine()#
void print_progress(float percentage)#
void calculate_stats()#
void print_stats(std::ofstream &log, float fraction)#
void log_stats(std::ofstream &log)#
inline Parameters &get_params()#
inline void set_params(Parameters &p)#
inline bool get_is_fitted()#
bool update_best(const Dataset &data, bool val = false)#

updates best score by searching in the population for the individual that best fits the given data

inline Individual<T> &get_best_ind()#
inline Engine<T> &fit(Dataset &data)#
inline Engine<T> &fit(const Ref<const ArrayXXf> &X, const Ref<const ArrayXf> &y)#
inline auto predict(const Dataset &data)#
inline auto predict(const Ref<const ArrayXXf> &X)#
template<ProgramType P = T>
inline auto predict_proba(const Dataset &d)#
template<ProgramType P = T>
inline auto predict_proba(const Ref<const ArrayXXf> &X)#
inline int get_archive_size()#

return archive size

vector<json> get_archive(bool front)#

return population as string

auto predict_archive(int id, const Dataset &data)#

predict on unseen data from the archive

auto predict_archive(int id, const Ref<const ArrayXXf> &X)#
template<ProgramType P = T>
auto predict_proba_archive(int id, const Dataset &data)#
template<ProgramType P = T>
auto predict_proba_archive(int id, const Ref<const ArrayXXf> &X)#
void run(Dataset &d)#

train the model

Public Members

float best_score#
int best_complexity#
Parameters params#

hyperparameters of brush, which the user can interact

Individual<T> best_ind#
Archive<T> archive#

pareto front archive