Brush C++ API
A flexible interpretable machine learning framework
Loading...
Searching...
No Matches
params.h
Go to the documentation of this file.
1/* Brush
2copyright 2020 William La Cava
3license: GNU/GPL v3
4*/
5
6#ifndef PARAMS_H
7#define PARAMS_H
8
9#include "init.h"
10#include "util/logger.h"
11
12namespace ns = nlohmann;
13
14namespace Brush
15{
16
18{
19public:
20 // by default, the rng generator will use any random seed if random_state is zero
21 int random_state = 0;
22 int verbosity = 0;
23
24 // Evolutionary algorithm settings
25 string mode="regression";
26
27 unsigned int current_gen = 1;
28
29 // termination criteria
30 int pop_size = 100;
31 int max_gens = 100;
32 int max_stall = 0;
33 int max_time = -1;
34
35 unsigned int max_depth = 6;
36 unsigned int max_size = 50;
37
38 vector<string> objectives{"error","complexity"}; // error should be generic and deducted based on mode
39
40 string sel = "lexicase"; //selection method
41 string surv = "nsga2"; //survival method
42 std::unordered_map<string, float> functions;
44
45 // if we should save pareto front of the entire evolution (use_arch=true)
46 // or just the final population (use_arch=false)
47 bool use_arch=false;
48 bool val_from_arch=true;
49
50 // variation
51 std::map<std::string, float> mutation_probs = {
52 {"point", 0.167},
53 {"insert", 0.167},
54 {"delete", 0.167},
55 {"subtree", 0.167},
56 {"toggle_weight_on", 0.167},
57 {"toggle_weight_off", 0.167}
58 };
59
60 float cx_prob=0.2;
61 float mig_prob = 0.05;
62
63 string scorer_="mse";
64
65 vector<int> classes;
66 vector<float> class_weights;
67 vector<float> sample_weights;
68
69 // for creating dataset from X and y in Engine<T>::fit. Ignored if
70 // the uses uses an dataset
72 unsigned int n_classes;
73
74 // validation partition
75 bool shuffle_split = false;
76 float validation_size = 0.75;
77 vector<string> feature_names = {};
78 float batch_size = 0.0;
79
80 string load_population = "";
81 string save_population = "";
82
83 string logfile = "";
84
85 int n_jobs = 1;
86
89
90 // TODO: use logger to log information. Make getters const
93 int get_verbosity(){ return verbosity; };
94
97
99 int get_pop_size(){ return pop_size; };
100
102 int get_max_gens(){ return max_gens; };
103
105 int get_max_stall(){ return max_stall; };
106
108 int get_max_time(){ return max_time; };
109
111 string get_scorer_(){ return scorer_; };
112
115
118
119 string get_logfile(){ return logfile; };
120 void set_logfile(string s){ logfile=s; };
121
122 void set_current_gen(unsigned int gen){ current_gen = gen; };
123 unsigned int get_current_gen(){ return current_gen; };
124
126 int get_num_islands(){ return num_islands; };
127
129 unsigned get_max_depth() const { return max_depth; };
130
132 int get_n_jobs(){ return n_jobs; };
133
135 unsigned get_max_size() const { return max_size; };
136
138 vector<string> get_objectives(){ return objectives; };
139
140 void set_sel(string new_sel){ sel = new_sel; };
141 string get_sel(){ return sel; };
142
143 void set_surv(string new_surv){ surv = new_surv; };
144 string get_surv(){ return surv; };
145
147 float get_cx_prob(){ return cx_prob; };
148
150 float get_mig_prob(){ return mig_prob; };
151
153 bool get_use_arch(){ return use_arch; };
154
157
160
163
165 unsigned int get_n_classes(){ return n_classes; };
166
169
170 void set_feature_names(vector<string> vn){ feature_names = vn; };
171 vector<string> get_feature_names(){ return feature_names; };
172
173 void set_batch_size(float c){ batch_size = c; };
174 float get_batch_size(){ return batch_size; };
175
177 std::map<std::string, float> get_mutation_probs(){ return mutation_probs; };
178
179 void set_functions(std::unordered_map<std::string, float> new_functions){ functions = new_functions; };
180 std::unordered_map<std::string, float> get_functions(){ return functions; };
181};
182
184 verbosity,
185 random_state,
186 pop_size,
187 max_gens,
188 max_stall,
189 max_time,
190 scorer_,
191 load_population,
192 save_population,
193 logfile,
194 current_gen,
195 num_islands,
196 max_depth,
197 n_jobs,
198 max_size,
199 objectives,
200 sel,
201 surv,
202 cx_prob,
203 mig_prob,
204 classification,
205 n_classes,
206 validation_size,
207 feature_names,
208 batch_size,
209 mutation_probs,
210 functions
211);
212
213} // Brush
214
215#endif
void bind_engine(py::module &m, string name)
void set_log_level(int &verbosity)
Sets the log level.
Definition logger.cpp:31
static Logger & logger
Definition logger.h:60
< nsga2 selection operator for getting the front
Definition data.cpp:12
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Engine< PT::Regressor >, params, best_ind, archive)
void set_save_population(string new_save_population)
Definition params.h:116
bool get_classification()
Definition params.h:159
void set_max_depth(unsigned new_max_depth)
Definition params.h:128
int get_verbosity()
Definition params.h:93
vector< float > sample_weights
weights for each sample
Definition params.h:67
void set_max_stall(int new_max_stall)
Definition params.h:104
void set_n_classes(unsigned int new_n_classes)
Definition params.h:164
vector< string > objectives
Definition params.h:38
void set_max_gens(int new_max_gens)
Definition params.h:101
unsigned get_max_size() const
Definition params.h:135
void set_shuffle_split(bool shuff)
Definition params.h:161
bool get_use_arch()
Definition params.h:153
void set_max_time(int new_max_time)
Definition params.h:107
vector< string > get_objectives()
Definition params.h:138
float cx_prob
cross rate for variation
Definition params.h:60
void set_functions(std::unordered_map< std::string, float > new_functions)
Definition params.h:179
void set_mutation_probs(std::map< std::string, float > new_mutation_probs)
Definition params.h:176
unsigned int max_depth
Definition params.h:35
bool get_val_from_arch()
Definition params.h:156
int get_max_time()
Definition params.h:108
float batch_size
Definition params.h:78
int get_max_gens()
Definition params.h:102
void set_batch_size(float c)
Definition params.h:173
bool shuffle_split
Definition params.h:75
void set_val_from_arch(bool new_val_from_arch)
Definition params.h:155
std::map< std::string, float > mutation_probs
Definition params.h:51
void set_num_islands(int new_num_islands)
Definition params.h:125
void set_pop_size(int new_pop_size)
Definition params.h:98
vector< string > get_feature_names()
Definition params.h:171
void set_random_state(int new_random_state)
Definition params.h:95
void set_logfile(string s)
Definition params.h:120
string get_save_population()
Definition params.h:117
float get_batch_size()
Definition params.h:174
float validation_size
Definition params.h:76
unsigned int get_n_classes()
Definition params.h:165
int get_max_stall()
Definition params.h:105
float get_mig_prob()
Definition params.h:150
int get_random_state()
Definition params.h:96
std::unordered_map< string, float > functions
Definition params.h:42
string get_scorer_()
Definition params.h:111
string get_load_population()
Definition params.h:114
bool classification
Definition params.h:71
string scorer_
actual loss function used, determined by error
Definition params.h:63
unsigned get_max_depth() const
Definition params.h:129
void set_load_population(string new_load_population)
Definition params.h:113
int get_pop_size()
Definition params.h:99
vector< int > classes
class labels
Definition params.h:65
int n_jobs
number of parallel jobs -1 use all threads; 0 use same as number of islands; positive number specify ...
Definition params.h:85
void set_current_gen(unsigned int gen)
Definition params.h:122
vector< float > class_weights
weights for each class
Definition params.h:66
int get_num_islands()
Definition params.h:126
void set_sel(string new_sel)
Definition params.h:140
vector< string > feature_names
Definition params.h:77
bool val_from_arch
Definition params.h:48
string get_logfile()
Definition params.h:119
void set_surv(string new_surv)
Definition params.h:143
void set_use_arch(bool new_use_arch)
Definition params.h:152
void set_classification(bool c)
Definition params.h:158
string logfile
Definition params.h:83
void set_objectives(vector< string > new_objectives)
Definition params.h:137
string get_surv()
Definition params.h:144
bool get_shuffle_split()
Definition params.h:162
unsigned int current_gen
Definition params.h:27
string load_population
Definition params.h:80
float get_cx_prob()
Definition params.h:147
string save_population
Definition params.h:81
void set_max_size(unsigned new_max_size)
Definition params.h:134
void set_n_jobs(int new_n_jobs)
Definition params.h:131
void set_feature_names(vector< string > vn)
Definition params.h:170
void set_validation_size(float s)
Definition params.h:167
void set_cx_prob(float new_cx_prob)
Definition params.h:146
unsigned int get_current_gen()
Definition params.h:123
void set_scorer_(string new_scorer_)
Definition params.h:110
std::map< std::string, float > get_mutation_probs()
Definition params.h:177
float get_validation_size()
Definition params.h:168
std::unordered_map< std::string, float > get_functions()
Definition params.h:180
unsigned int max_size
Definition params.h:36
void set_verbosity(int new_verbosity)
Definition params.h:91
unsigned int n_classes
Definition params.h:72
void set_mig_prob(float new_mig_prob)
Definition params.h:149
string get_sel()
Definition params.h:141