32 const std::string KERNEL_NAME =
"kMaternARD5";
33 const double KERNEL_THETA = 1.0;
34 const double KERNEL_SIGMA = 10.0;
35 const std::string MEAN_NAME =
"mConst";
36 const double MEAN_MU = 1.0;
37 const double MEAN_SIGMA = 1000.0;
38 const double PRIOR_ALPHA = 1.0;
39 const double PRIOR_BETA = 1.0;
40 const double DEFAULT_SIGMA = 1.0;
41 const double DEFAULT_NOISE = 1e-6;
44 const size_t DEFAULT_ITERATIONS = 190;
45 const size_t DEFAULT_INIT_SAMPLES = 10;
46 const size_t DEFAULT_ITERATIONS_RELEARN = 50;
47 const size_t DEFAULT_INNER_EVALUATIONS = 500;
50 const size_t DEFAULT_VERBOSE = 1;
51 const std::string LOG_FILENAME =
"bayesopt.log";
52 const std::string SAVE_FILENAME =
"bayesopt.dat";
53 const std::string LOAD_FILENAME =
"bayesopt.dat";
55 const std::string SURR_NAME =
"sGaussianProcess";
56 const std::string CRIT_NAME =
"cEI";
58 learning_type str2learn(
const char* name)
60 if (!strcmp(name,
"L_FIXED") || !strcmp(name,
"fixed"))
return L_FIXED;
61 else if (!strcmp(name,
"L_EMPIRICAL") || !strcmp(name,
"empirical"))
return L_EMPIRICAL;
62 else if (!strcmp(name,
"L_DISCRETE") || !strcmp(name,
"discrete"))
return L_DISCRETE;
63 else if (!strcmp(name,
"L_MCMC") || !strcmp(name,
"mcmc"))
return L_MCMC;
67 const char* learn2str(learning_type name)
71 case L_FIXED:
return "L_FIXED";
72 case L_EMPIRICAL:
return "L_EMPIRICAL";
73 case L_DISCRETE:
return "L_DISCRETE";
74 case L_MCMC:
return "L_MCMC";
76 default:
return "ERROR!";
80 score_type str2score(
const char* name)
82 if (!strcmp(name,
"SC_MTL") || !strcmp(name,
"mtl"))
return SC_MTL;
83 else if (!strcmp(name,
"SC_ML") || !strcmp(name,
"ml"))
return SC_ML;
84 else if (!strcmp(name,
"SC_MAP") || !strcmp(name,
"map"))
return SC_MAP;
85 else if (!strcmp(name,
"SC_LOOCV") || !strcmp(name,
"loocv"))
return SC_LOOCV;
89 const char* score2str(score_type name)
93 case SC_MTL:
return "SC_MTL";
94 case SC_ML:
return "SC_ML";
95 case SC_MAP:
return "SC_MAP";
96 case SC_LOOCV:
return "SC_LOOCV";
98 default:
return "ERROR!";
102 void set_kernel(
bopt_params* params,
const char* name)
107 void set_mean(
bopt_params* params,
const char* name)
112 void set_criteria(
bopt_params* params,
const char* name)
117 void set_surrogate(
bopt_params* params,
const char* name)
122 void set_log_file(
bopt_params* params,
const char* name)
127 void set_load_file(
bopt_params* params,
const char* name)
132 void set_save_file(
bopt_params* params,
const char* name)
137 void set_learning(
bopt_params* params,
const char* name)
139 params->
l_type = str2learn(name);
142 void set_score(
bopt_params* params,
const char* name)
144 params->
sc_type = str2score(name);
152 kernel.
name =
new char[128];
153 strcpy(kernel.
name,KERNEL_NAME.c_str());
155 kernel.
hp_mean[0] = KERNEL_THETA;
156 kernel.
hp_std[0] = KERNEL_SIGMA;
160 mean.
name =
new char[128];
161 strcpy(mean.
name,MEAN_NAME.c_str());
190 strcpy(params.
surr_name,SURR_NAME.c_str());
192 params.
sigma_s = DEFAULT_SIGMA;
193 params.
noise = DEFAULT_NOISE;
194 params.
alpha = PRIOR_ALPHA;
195 params.
beta = PRIOR_BETA;
198 params.
l_type = L_EMPIRICAL;
205 strcpy(params.
crit_name,CRIT_NAME.c_str());
221 KernelParameters::KernelParameters():
222 hp_mean(1), hp_std(1){
225 hp_mean(0) = KERNEL_THETA;
226 hp_std(0) = KERNEL_SIGMA;
232 MeanParameters::MeanParameters():
233 coef_mean(1), coef_std(1){
236 coef_mean(0) = MEAN_MU;
237 coef_std(0) = MEAN_SIGMA;
243 Parameters::Parameters():
244 kernel(), mean(), crit_params(){
250 kernel(), mean(), crit_params(){
266 surr_name = std::string(c_params.
surr_name);
269 noise = c_params.
noise;
270 alpha = c_params.
alpha;
271 beta = c_params.
beta;
276 l_all = c_params.
l_all;
294 crit_params = bayesopt::utils::array2vector(c_params.
crit_params,
300 bopt_params c_params = initialize_parameters_to_default();
316 strcpy(c_params.
surr_name, surr_name.c_str());
319 c_params.
noise = noise;
320 c_params.
alpha = alpha;
321 c_params.
beta = beta;
327 c_params.
l_all = l_all;
334 for(
size_t i=0; i<kernel.
hp_mean.size(); i++){
337 for(
size_t i=0; i<kernel.
hp_std.size(); i++){
343 for(
size_t i=0; i<mean.
coef_mean.size(); i++){
346 for(
size_t i=0; i<mean.
coef_std.size(); i++){
351 strcpy(c_params.
crit_name, crit_name.c_str());
352 for(
size_t i=0; i<crit_params.size(); i++){
360 void Parameters::bostrdup (
char* d,
const char *s) {
362 d =
new char[strlen (s) + 1];
363 if (d == NULL) d = NULL;
367 void Parameters::set_learning(std::string name){
368 l_type = str2learn(name.c_str());
370 std::string Parameters::get_learning(){
371 return std::string(learn2str(l_type));
374 void Parameters::set_score(std::string name){
375 sc_type = str2score(name.c_str());
377 std::string Parameters::get_score(){
378 return std::string(score2str(sc_type));
381 void Parameters::init_default(){
382 n_iterations = DEFAULT_ITERATIONS;
383 n_inner_iterations = DEFAULT_INNER_EVALUATIONS;
384 n_init_samples = DEFAULT_INIT_SAMPLES;
385 n_iter_relearn = DEFAULT_ITERATIONS_RELEARN;
390 verbose_level = DEFAULT_VERBOSE;
391 log_filename = LOG_FILENAME;
394 load_filename = LOAD_FILENAME;
395 save_filename = SAVE_FILENAME;
397 surr_name = SURR_NAME;
399 sigma_s = DEFAULT_SIGMA;
400 noise = DEFAULT_NOISE;
405 l_type = L_EMPIRICAL;
411 crit_name = CRIT_NAME;
size_t n_inner_iterations
Maximum inner optimizer evaluations.
double noise
Variance of observation noise (and nugget)
mean_parameters mean
Mean (parametric function) parameters.
size_t force_jump
If >0, and the difference between two consecutive observations is pure noise, for n consecutive steps...
double coef_std[128]
Basis function coefficients (std)
double coef_mean[128]
Basis function coefficients (mean)
learning_type l_type
Type of learning for the kernel params.
size_t n_iterations
Maximum BayesOpt evaluations (budget)
size_t n_hp
Number of kernel hyperparameters.
Namespace of the library interface.
int verbose_level
Neg-Error,0-Warning,1-Info,2-Debug -> stdout 3-Error,4-Warning,5-Info,>5-Debug -> logfile...
score_type sc_type
Score type for kernel hyperparameters (ML,MAP,etc)
size_t load_save_flag
1-Load data,2-Save data, 3-Load and save data.
char * load_filename
Init data file path (if applicable)
size_t n_init_samples
Number of samples before optimization.
double hp_mean[128]
Kernel hyperparameters prior (mean, log space)
char * surr_name
Name of the surrogate function.
size_t n_coef
Number of mean funct.
double sigma_s
Signal variance (if known).
kernel_parameters kernel
Kernel parameters.
Configuration parameters.
size_t n_crit_params
Number of criterion hyperparameters.
char * name
Name of the kernel function.
double alpha
Inverse Gamma prior for signal var.
double hp_std[128]
Kernel hyperparameters prior (st dev, log space)
char * crit_name
Name of the criterion.
char * name
Name of the mean function.
char * log_filename
Log file path (if applicable)
double beta
Inverse Gamma prior for signal var.
size_t n_iter_relearn
Number of samples before relearn kernel.
int l_all
Learn all hyperparameters or only kernel.
int random_seed
>=0 -> Fixed seed, <0 -> Time based (variable).
double epsilon
For epsilon-greedy exploration.
size_t init_method
Sampling method for initial set 1-LHS, 2-Sobol (if available), other value-uniformly distributed...
Kernel configuration parameters.
char * save_filename
Sava data file path (if applicable)
double crit_params[128]
Criterion hyperparameters (if needed)