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_bandit(string new_bandit)#
inline string get_bandit()#
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() const#
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_constants_simplification(bool cs)#
inline bool get_constants_simplification()#
inline void set_inexact_simplification(bool is)#
inline bool get_inexact_simplification()#
inline void set_weights_init(bool init)#
inline bool get_weights_init()#
inline void set_n_classes(const ArrayXf &y)#
inline void set_class_weights(const ArrayXf &y)#
inline void set_sample_weights(const ArrayXf &y)#
inline unsigned int get_n_classes()#
inline vector<float> get_class_weights()#
inline vector<float> get_sample_weights()#
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_feature_types(vector<string> ft)#
inline vector<string> get_feature_types()#
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 = 5#
unsigned int max_size = 50#
vector<string> objectives = {"scorer", "linear_complexity"}#
string bandit = "thompson"#
string sel = "lexicase"#
string surv = "nsga2"#
std::unordered_map<string, float> functions#
int num_islands = 1#
bool use_arch = false#
bool val_from_arch = true#
bool constants_simplification = true#
bool inexact_simplification = 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 = vector<int>()#

class labels

vector<float> class_weights = vector<float>()#

weights for each class

vector<float> sample_weights = vector<float>()#

weights for each sample

bool classification = false#
unsigned int n_classes = 0#
bool shuffle_split = false#
float validation_size = 0.75#
vector<string> feature_names = {}#
vector<string> feature_types = {}#
float batch_size = 0.0#
bool weights_init = true#
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()#
inline Engine(Parameters &p, SearchSpace &s)#
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 SearchSpace &get_search_space()#
inline void set_search_space(SearchSpace &space)#
inline bool get_is_fitted()#
bool update_best()#

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 archive/population as string

vector<json> get_population()#
void set_population(vector<json> pop_vector)#
void lock_nodes(int end_depth = 0, bool skip_leaves = true)#
void unlock_nodes(int start_depth = 0)#
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

Parameters params#

hyperparameters of brush, which the user can interact

SearchSpace ss#
Individual<T> best_ind#

best individual found during training

Archive<T> archive#

pareto front archive

Population<T> pop#

population of programs

bool is_fitted = false#

keeps track of whether fit was called