Skip to content

Commit

Permalink
WIP on feat-noisy-suite: 1942472 Fixing logger
Browse files Browse the repository at this point in the history
  • Loading branch information
FMGS666 committed Dec 11, 2023
2 parents 1942472 + f4461b0 commit c49b8e9
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 38 deletions.
2 changes: 2 additions & 0 deletions code-experiments/src/coco_suite.c
Expand Up @@ -861,7 +861,9 @@ coco_problem_t *coco_suite_get_next_problem(coco_suite_t *suite, coco_observer_t
dimension_idx = (size_t) suite->current_dimension_idx;
instance_idx = (size_t) suite->current_instance_idx;

coco_info("coco_suite_get_next_problem: getting problem, f%d, d%d, i%d", function_idx, dimension_idx, instance_idx);
problem = coco_suite_get_problem_from_indices(suite, function_idx, dimension_idx, instance_idx);
coco_info("problem allocated");
if (observer != NULL)
problem = coco_problem_add_observer(problem, observer);
suite->current_problem = problem;
Expand Down
15 changes: 12 additions & 3 deletions code-experiments/src/suite_bbob_noisy_utilities.c
Expand Up @@ -70,9 +70,18 @@ double coco_sample_uniform_noise(void){
*/
/**@{*/
double coco_boundary_handling(coco_problem_t * problem, const double * x){
double penalty = 0.0;
for(size_t dimension = 0; dimension < problem -> number_of_variables; dimension ++ ){
penalty += fabs(x[dimension]) - 5 > 0 ? pow(fabs(x[dimension]) - 5, 2) : 0;
double penalty, lower_bound, upper_bound;
penalty = 0.0;
size_t dimension;
for(dimension = 0; dimension < problem->number_of_variables; dimension ++ ){
lower_bound = problem->smallest_values_of_interest[dimension];
upper_bound = problem->largest_values_of_interest[dimension];
if(x[dimension] > upper_bound){
penalty += x[dimension] - upper_bound;
}
else if(x[dimension] < lower_bound){
penalty += fabs(x[dimension] - lower_bound);
}
}
return 100.0 * penalty;
}
Expand Down
6 changes: 4 additions & 2 deletions code-experiments/src/suite_cons_bbob.c
Expand Up @@ -59,9 +59,11 @@ static coco_problem_t *coco_get_cons_bbob_problem(const char *suite_name,

size_t number_of_linear_constraints;
coco_problem_t *problem = NULL;

double *feasible_direction = coco_allocate_vector(dimension);
coco_info("coco_get_cons_bbob_problem: allocating feasible_direction on dimension %d", dimension);
double *feasible_direction = coco_allocate_vector(dimension);
coco_info("coco_get_cons_bbob_problem: feasible_direction allocated, allocating x_opt on dimension %d", dimension);
double *xopt = coco_allocate_vector(dimension);
coco_info("coco_get_cons_bbob_problem: x_opt allocated");
long rseed = (long) (function + 10000 * instance);

const char *problem_id_template = "bbob-constrained_f%03lu_i%02lu_d%02lu";
Expand Down
24 changes: 13 additions & 11 deletions code-experiments/src/transform_obj_cauchy_noise.c
Expand Up @@ -24,22 +24,24 @@ static void transform_obj_cauchy_noise_evaluate_function(
double *y
){
coco_problem_t *inner_problem = coco_problem_transformed_get_inner_problem(problem);
double fopt = *(inner_problem -> best_value);
transform_obj_cauchy_noise_data_t *data;
double uniform_indicator, numerator_normal_variate, denominator_normal_variate,
fopt, cauchy_noise, tol;
size_t i;
fopt = *(inner_problem->best_value);
data = (transform_obj_cauchy_noise_data_t *) coco_problem_transformed_get_data(problem);
double uniform_indicator, numerator_normal_variate, denominator_normal_variate;
uniform_indicator = coco_sample_uniform_noise();
numerator_normal_variate = coco_sample_gaussian_noise();
denominator_normal_variate = coco_sample_gaussian_noise();
denominator_normal_variate = fabs(denominator_normal_variate + 1e-199);
double cauchy_noise = numerator_normal_variate / (denominator_normal_variate);
cauchy_noise = uniform_indicator < data -> p ? 1e3 + cauchy_noise : 1e3;
cauchy_noise = data -> alpha * cauchy_noise;
cauchy_noise = numerator_normal_variate / (denominator_normal_variate);
cauchy_noise = uniform_indicator < data->p ? 1e3 + cauchy_noise : 1e3;
cauchy_noise = data->alpha * cauchy_noise;
cauchy_noise = cauchy_noise > 0 ? cauchy_noise : 0.;
double tol = 1e-8;
inner_problem -> evaluate_function(inner_problem, x, y);
for(size_t i = 0; i < problem -> number_of_objectives; i++){
problem -> last_noise_free_values[i] = y[i];
tol = 1e-8;
inner_problem->evaluate_function(inner_problem, x, y);
for(i = 0; i < problem->number_of_objectives; i++){
problem->last_noise_free_values[i] = y[i];
}
*(y) = *(y) + cauchy_noise + 1.01 * tol + coco_boundary_handling(problem, x);
}
Expand All @@ -55,8 +57,8 @@ static coco_problem_t *transform_obj_cauchy_noise(
coco_problem_t *problem;
transform_obj_cauchy_noise_data_t *data;
data = (transform_obj_cauchy_noise_data_t *) coco_allocate_memory(sizeof(*data));
data -> alpha = alpha;
data -> p = p;
data->alpha = alpha;
data->p = p;
problem = coco_problem_transformed_allocate(inner_problem, data,
NULL, "cauchy_noise_model");
problem->evaluate_function = transform_obj_cauchy_noise_evaluate_function;
Expand Down
20 changes: 11 additions & 9 deletions code-experiments/src/transform_obj_gaussian_noise.c
Expand Up @@ -21,16 +21,18 @@ static void transform_obj_gaussian_noise_evaluate_function(
const double *x,
double *y
){
coco_problem_t *inner_problem = coco_problem_transformed_get_inner_problem(problem);
double fopt = *(inner_problem -> best_value);
double gaussian_noise, fopt, tol;
coco_problem_t *inner_problem = coco_problem_transformed_get_inner_problem(problem);
transform_obj_gaussian_noise_data_t *data;
size_t i;
fopt = *(inner_problem->best_value);
data = (transform_obj_gaussian_noise_data_t *) coco_problem_transformed_get_data(problem);
double gaussian_noise = coco_sample_gaussian_noise();
gaussian_noise = exp(data -> beta * gaussian_noise);
double tol = 1e-8;
inner_problem -> evaluate_function(inner_problem, x, y);
for(size_t i = 0; i < problem -> number_of_objectives; i++){
problem -> last_noise_free_values[i] = y[i];
gaussian_noise = coco_sample_gaussian_noise();
gaussian_noise = exp(data->beta * gaussian_noise);
tol = 1e-8;
inner_problem->evaluate_function(inner_problem, x, y);
for(i = 0; i < problem->number_of_objectives; i++){
problem->last_noise_free_values[i] = y[i];
}
*(y) = *(y) - fopt;
*(y) = *(y) * gaussian_noise + 1.01 * tol;
Expand All @@ -48,7 +50,7 @@ static coco_problem_t *transform_obj_gaussian_noise(
coco_problem_t *problem;
transform_obj_gaussian_noise_data_t *data;
data = (transform_obj_gaussian_noise_data_t *) coco_allocate_memory(sizeof(*data));
data -> beta = beta;
data->beta = beta;
problem = coco_problem_transformed_allocate(inner_problem, data,
NULL, "gaussian_noise_model");
problem->evaluate_function = transform_obj_gaussian_noise_evaluate_function;
Expand Down
26 changes: 14 additions & 12 deletions code-experiments/src/transform_obj_uniform_noise.c
Expand Up @@ -23,24 +23,26 @@ static void transform_obj_uniform_noise_evaluate_function(
const double *x,
double *y
){
double uniform_noise_term1, uniform_noise_term2;
coco_problem_t *inner_problem = coco_problem_transformed_get_inner_problem(problem);
double fopt = *(inner_problem -> best_value);
double uniform_noise_term1, uniform_noise_term2, fopt, uniform_noise_factor,
scaling_factor, uniform_noise, tol;
coco_problem_t *inner_problem = coco_problem_transformed_get_inner_problem(problem);
size_t i;
fopt = *(inner_problem->best_value);
transform_obj_uniform_noise_data_t *data;
data = (transform_obj_uniform_noise_data_t *) coco_problem_transformed_get_data(problem);
uniform_noise_term1 = coco_sample_uniform_noise();
uniform_noise_term2 = coco_sample_uniform_noise();
double uniform_noise_factor = pow(uniform_noise_term1, data -> beta);
inner_problem -> evaluate_function(inner_problem, x, y);
for(size_t i = 0; i < problem -> number_of_objectives; i++){
problem -> last_noise_free_values[i] = y[i];
uniform_noise_factor = pow(uniform_noise_term1, data->beta);
inner_problem->evaluate_function(inner_problem, x, y);
for(i = 0; i < problem->number_of_objectives; i++){
problem->last_noise_free_values[i] = y[i];
}
*(y) = *(y) - fopt;
double scaling_factor = 1e9/(*(y) + 1e-99);
scaling_factor = 1e9/(*(y) + 1e-99);
scaling_factor = pow(scaling_factor, data -> alpha * uniform_noise_term2);
scaling_factor = scaling_factor > 1 ? scaling_factor : 1;
double uniform_noise = uniform_noise_factor * scaling_factor;
double tol = 1e-8;
uniform_noise = uniform_noise_factor * scaling_factor;
tol = 1e-8;
*(y) = *(y) * uniform_noise + 1.01 * tol;
*(y) = *(y) + fopt + coco_boundary_handling(problem, x);
}
Expand All @@ -56,8 +58,8 @@ static coco_problem_t *transform_obj_uniform_noise(
coco_problem_t *problem;
transform_obj_uniform_noise_data_t *data;
data = (transform_obj_uniform_noise_data_t *) coco_allocate_memory(sizeof(*data));
data -> alpha = alpha;
data -> beta = beta;
data->alpha = alpha;
data->beta = beta;
problem = coco_problem_transformed_allocate(inner_problem, data,
NULL, "uniform_noise_model");
problem->evaluate_function = transform_obj_uniform_noise_evaluate_function;
Expand Down
11 changes: 10 additions & 1 deletion code-experiments/test/unit-test/test_coco_problem.c
Expand Up @@ -13,6 +13,7 @@ MU_TEST(test_coco_evaluate_function) {
double *x;
double *y;

coco_info("testing bbob");
suite = coco_suite("bbob", NULL, "dimensions: 2 instance_indices: 1");
x = coco_allocate_vector(2);
y = coco_allocate_vector(1);
Expand All @@ -26,6 +27,7 @@ MU_TEST(test_coco_evaluate_function) {
coco_free_memory(x);
coco_free_memory(y);

coco_info("testing bbob-noisy");
suite = coco_suite("bbob-noisy", NULL, "dimensions: 2 instance_indices: 1");
x = coco_allocate_vector(2);
y = coco_allocate_vector(1);
Expand All @@ -39,6 +41,7 @@ MU_TEST(test_coco_evaluate_function) {
coco_free_memory(x);
coco_free_memory(y);

coco_info("testing bbob-biobj");
suite = coco_suite("bbob-biobj", NULL, "dimensions: 2 instance_indices: 1");
x = coco_allocate_vector(2);
y = coco_allocate_vector(2);
Expand All @@ -52,11 +55,17 @@ MU_TEST(test_coco_evaluate_function) {
coco_free_memory(x);
coco_free_memory(y);

coco_info("testing bbob-constrained");
coco_info("Allocating suite");
suite = coco_suite("bbob-constrained", NULL, "dimensions: 2 instance_indices: 1");
coco_info("Suite allocated. Allocating x");
x = coco_allocate_vector(2);
coco_info("x allocated. Allocating y");
y = coco_allocate_vector(1);
coco_info("y allocated. Iterating over the suite");
while ((problem = coco_suite_get_next_problem(suite, NULL)) != NULL) {
x[0] = 0;
coco_info("getting problem %d", problem->suite_dep_index);
x[0] = 0;
x[1] = NAN;
coco_evaluate_function(problem, x, y);
mu_check(coco_vector_contains_nan(y, 1));
Expand Down

0 comments on commit c49b8e9

Please sign in to comment.