Skip to content

Commit

Permalink
This should be the "final" commit, in the sense that it is the first …
Browse files Browse the repository at this point in the history
…commit where the results obtained

are exactly the same as the one for the legacy code.
Before I forgot to implement the boundary handling method that were adding a penalty on the decision vector.
  • Loading branch information
FMGS666 committed Oct 17, 2023
1 parent 2450a63 commit 3254807
Show file tree
Hide file tree
Showing 17 changed files with 1,668 additions and 1,525 deletions.
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@ code-experiments/test/integration-test/test_bbob-mixint
code-experiments/test/integration-test/test_biobj
code-experiments/test/integration-test/test_coco
code-experiments/test/integration-test/test_instance_extraction
code-experiments/test/regression-test/data/
code-experiments/test/regression-test/regression-test-bbob-noisy/data/*.txt
code-experiments/test/regression-test/regression-test-bbob-noisy/data_legacy/*.json
code-experiments/test/regression-test/regression-test-bbob-noisy/results/

code-experiments/test/regression-test/data/*
code-experiments/test/regression-test/bbob_noisy_regression_test/data_legacy/

code-postprocessing/build/
code-postprocessing/dist/
Expand Down
2,577 changes: 1,284 additions & 1,293 deletions code-experiments/build/python/cython/interface.c

Large diffs are not rendered by default.

82 changes: 64 additions & 18 deletions code-experiments/src/coco.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,68 @@ typedef enum {
COCO_DEBUG /**< @brief error, warning, info and debug messages are output */
} coco_log_level_type_e;

/***********************************************************************************************************/
/**
* @name Structures representing the additional arguments to be passed to the functions
*/
/**{@*/

/**
* @brief The extra argument to be passed to the step ellipsoid function
* only penalty scale, because in the legacy code is different
* between the noisy and the noise free implementations
*/
typedef struct{
double penalty_scale;
} f_step_ellipsoid_args_t;

/**
* @brief The extra argument to be passed to the step ellipsoid function
* only conditioning, because in the legacy code is different
* between the noisy and the noise free implementations
*/
typedef struct{
double conditioning;
} f_ellipsoid_args_t;

/**
* @brief The extra argument to be passed to the step ellipsoid function
* conditioning and penalty scale, because in the legacy code were different
* between the noisy and the noise free implementations
*/
typedef struct{
double conditioning;
double penalty_scale;
} f_schaffers_args_t;

/**
* @brief The extra argument to be passed to the step ellipsoid function
* facftrue, because in the legacy code is different
* between the noisy and the noise free implementations
*/
typedef struct{
double facftrue;
}f_griewank_rosenbrock_args_t;

/**
* @brief The extra argument to be passed to the step ellipsoid function
* facftrue, because in the legacy code is different
* between the noisy and the noise free implementations
*/
typedef struct{
size_t number_of_peaks;
double penalty_scale;
}f_gallagher_args_t;

typedef struct {
f_step_ellipsoid_args_t *f_step_ellipsoid_args;
f_ellipsoid_args_t *f_ellipsoid_args;
f_schaffers_args_t *f_schaffers_args;
f_griewank_rosenbrock_args_t *f_griewank_rosenbrock_args;
f_gallagher_args_t *f_gallagher_args;
} f_args_t;
/**@}*/

/***********************************************************************************************************/

/** @brief Structure containing a COCO problem. */
Expand Down Expand Up @@ -192,32 +254,16 @@ typedef coco_problem_t *(*coco_problem_bbob_allocator_t)(
* This is a template for functions that perform the allocation of the objective function
* given the number of dimensions of the problem
*/
typedef coco_problem_t *(*coco_problem_bbob_conditioned_allocator_t)(
typedef coco_problem_t *(*coco_problem_bbob_allocator_args_t)(
const size_t function,
const size_t dimension,
const size_t instance,
const long rseed,
const double conditioning,
const f_args_t *args,
const char *problem_id_template,
const char *problem_name_template);

/**
* @brief The allocate objective function type
* This is a template for functions that perform the allocation of the objective function
* given the number of dimensions of the problem
*/
typedef coco_problem_t *(*coco_problem_bbob_gallagher_allocator_t)(
const size_t function,
const size_t dimension,
const size_t instance,
const long rseed,
const size_t n_peaks,
const char *problem_id_template,
const char *problem_name_template);
/**@}*/

/***********************************************************************************************************/

/**
* @name Methods regarding COCO suite
*/
Expand Down
6 changes: 1 addition & 5 deletions code-experiments/src/coco_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,8 @@ struct coco_problem_s {
coco_problem_free_function_t problem_free_function; /**< @brief The function for freeing this problem. */
coco_evaluate_function_t placeholder_evaluate_function; /**< @brief The function for evaluating noisy objectives*/

coco_noise_model_t *noise_model; /**< @brief The noise model for noisy problems*/
coco_noise_model_t *noise_model; /** Lorenzo: < @brief The noise model for noisy problems*/

double last_noise_value; /**< @brief For noisy problems, the last value sampled according to the noise model */

double condition; /**< @brief Condition of the problem*/

size_t number_of_variables; /**< @brief Number of variables expected by the function, i.e.
problem dimension */
size_t number_of_objectives; /**< @brief Number of objectives. */
Expand Down
19 changes: 16 additions & 3 deletions code-experiments/src/coco_problem.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ static coco_problem_t *coco_problem_allocate(const size_t number_of_variables,
problem->problem_free_function = NULL;
problem -> noise_model = noise_model;
problem -> placeholder_evaluate_function = NULL;
problem -> last_noise_value = 0.0;
problem -> condition = 0.0;

problem->number_of_variables = number_of_variables;
problem->number_of_objectives = number_of_objectives;
problem->number_of_constraints = number_of_constraints;
Expand Down Expand Up @@ -322,12 +321,26 @@ void coco_problem_free(coco_problem_t *problem) {
problem->best_value = NULL;
problem->nadir_value = NULL;
problem->suite = NULL;
problem->data = NULL;
problem->initial_solution = NULL;
coco_free_memory(problem);
}
}

/**
* @brief Allocates function arguments structure
*/
static f_args_t *coco_problem_allocate_f_args(
f_args_t * args
){
args = (f_args_t *) coco_allocate_memory(sizeof(*args));
args->f_ellipsoid_args = (f_ellipsoid_args_t *) coco_allocate_memory(sizeof(*(args->f_ellipsoid_args)));
args->f_step_ellipsoid_args = (f_step_ellipsoid_args_t *) coco_allocate_memory(sizeof(*(args->f_step_ellipsoid_args)));
args->f_schaffers_args = (f_schaffers_args_t *) coco_allocate_memory(sizeof(*(args->f_schaffers_args)));
args->f_griewank_rosenbrock_args = (f_griewank_rosenbrock_args_t *) coco_allocate_memory(sizeof(*(args->f_griewank_rosenbrock_args)));
args->f_gallagher_args = (f_gallagher_args_t *) coco_allocate_memory(sizeof(*(args->f_gallagher_args)));
return args;
}

/***********************************************************************************************************/

/**
Expand Down
49 changes: 24 additions & 25 deletions code-experiments/src/f_ellipsoid.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
#include "transform_vars_blockrotation.c"
#include "transform_obj_norm_by_dim.c"

/**
* @brief Data type for the ellipsoid problem.
*/
typedef struct {
double conditioning;
}f_ellipsoid_data_t;

/**
* @brief Implements the ellipsoid function without connections to any COCO structures.
*/
static double f_ellipsoid_raw(const double *x, const size_t number_of_variables, double condition) {
static double f_ellipsoid_raw(const double *x, const size_t number_of_variables, f_ellipsoid_data_t *data) {

size_t i = 0;
double result;
Expand All @@ -31,7 +38,7 @@ static double f_ellipsoid_raw(const double *x, const size_t number_of_variables,
result = x[i] * x[i];
for (i = 1; i < number_of_variables; ++i) {
const double exponent = 1.0 * (double) (long) i / ((double) (long) number_of_variables - 1.0);
result += pow(condition, exponent) * x[i] * x[i];
result += pow(data->conditioning, exponent) * x[i] * x[i];
}

return result;
Expand All @@ -42,7 +49,7 @@ static double f_ellipsoid_raw(const double *x, const size_t number_of_variables,
*/
static void f_ellipsoid_evaluate(coco_problem_t *problem, const double *x, double *y) {
assert(problem->number_of_objectives == 1);
y[0] = f_ellipsoid_raw(x, problem->number_of_variables, problem -> condition);
y[0] = f_ellipsoid_raw(x, problem->number_of_variables, (f_ellipsoid_data_t *) problem->data);
assert(y[0] + 1e-13 >= problem->best_value[0]);
}

Expand All @@ -55,24 +62,26 @@ static void f_ellipsoid_evaluate_gradient(coco_problem_t *problem,

double exponent;
size_t i = 0;

for (i = 0; i < problem->number_of_variables; ++i) {
exponent = 1.0 * (double) (long) i / ((double) (long) problem->number_of_variables - 1.0);
y[i] = 2.0*pow(problem -> condition, exponent) * x[i];
y[i] = 2.0*pow( ((f_ellipsoid_data_t *) problem->data) -> conditioning, exponent) * x[i];
}

}

/**
* @brief Allocates the basic ellipsoid problem.
*/
static coco_problem_t *f_ellipsoid_allocate(const size_t number_of_variables) {
static coco_problem_t *f_ellipsoid_allocate(const size_t number_of_variables, const double conditioning) {

coco_problem_t *problem = coco_problem_allocate_from_scalars("ellipsoid function",
f_ellipsoid_evaluate, NULL, number_of_variables, -5.0, 5.0, 0.0);
problem->evaluate_gradient = f_ellipsoid_evaluate_gradient;
coco_problem_set_id(problem, "%s_d%02lu", "ellipsoid", number_of_variables);

f_ellipsoid_data_t *data;
data = (f_ellipsoid_data_t *) coco_allocate_memory(sizeof(*data));
data->conditioning = conditioning;
problem->data = data;
/* Compute best solution */
f_ellipsoid_evaluate(problem, problem->best_parameter, problem->best_value);
return problem;
Expand All @@ -85,7 +94,6 @@ static coco_problem_t *f_ellipsoid_bbob_problem_allocate(const size_t function,
const size_t dimension,
const size_t instance,
const long rseed,
const double conditioning,
const char *problem_id_template,
const char *problem_name_template) {
double *xopt, fopt;
Expand All @@ -95,8 +103,7 @@ static coco_problem_t *f_ellipsoid_bbob_problem_allocate(const size_t function,
fopt = bbob2009_compute_fopt(function, instance);
bbob2009_compute_xopt(xopt, rseed, dimension);

problem = f_ellipsoid_allocate(dimension);
problem -> condition = conditioning;
problem = f_ellipsoid_allocate(dimension, 1.0e6);
problem = transform_vars_oscillate(problem);
problem = transform_vars_shift(problem, xopt, 0);

Expand All @@ -121,7 +128,7 @@ static coco_problem_t *f_ellipsoid_rotated_bbob_problem_allocate(const size_t fu
const size_t dimension,
const size_t instance,
const long rseed,
const double conditioning,
const f_args_t *args,
const char *problem_id_template,
const char *problem_name_template) {
double *xopt, fopt;
Expand All @@ -139,14 +146,11 @@ static coco_problem_t *f_ellipsoid_rotated_bbob_problem_allocate(const size_t fu
bbob2009_compute_rotation(rot1, rseed + 1000000, dimension);
bbob2009_copy_rotation_matrix(rot1, M, b, dimension);
bbob2009_free_matrix(rot1, dimension);

problem = f_ellipsoid_allocate(dimension);
problem -> condition = conditioning;
problem = f_ellipsoid_allocate(dimension, args -> f_ellipsoid_args -> conditioning);
problem = transform_vars_oscillate(problem);
problem = transform_vars_affine(problem, M, b, dimension);
problem = transform_vars_shift(problem, xopt, 0);
problem = transform_obj_shift(problem, fopt);

coco_problem_set_id(problem, problem_id_template, function, instance, dimension);
coco_problem_set_name(problem, problem_name_template, function, instance, dimension);
coco_problem_set_type(problem, "3-ill-conditioned");
Expand All @@ -164,7 +168,6 @@ static coco_problem_t *f_ellipsoid_permblockdiag_bbob_problem_allocate(const siz
const size_t dimension,
const size_t instance,
const long rseed,
const double conditioning,
const char *problem_id_template,
const char *problem_name_template) {
double *xopt, fopt;
Expand Down Expand Up @@ -195,15 +198,14 @@ static coco_problem_t *f_ellipsoid_permblockdiag_bbob_problem_allocate(const siz
coco_compute_truncated_uniform_swap_permutation(P1, rseed + 2000000, dimension, nb_swaps, swap_range);
coco_compute_truncated_uniform_swap_permutation(P2, rseed + 3000000, dimension, nb_swaps, swap_range);

problem = f_ellipsoid_allocate(dimension);
problem -> condition = conditioning;
problem = f_ellipsoid_allocate(dimension, 1.0e6);
problem = transform_vars_oscillate(problem);
problem = transform_vars_permutation(problem, P2, dimension);
problem = transform_vars_blockrotation(problem, B_copy, dimension, block_sizes, nb_blocks);
problem = transform_vars_permutation(problem, P1, dimension);
problem = transform_vars_shift(problem, xopt, 0);


problem = transform_obj_norm_by_dim(problem);
problem = transform_obj_shift(problem, fopt);

Expand All @@ -226,7 +228,6 @@ static coco_problem_t *f_ellipsoid_cons_bbob_problem_allocate(const size_t funct
const size_t dimension,
const size_t instance,
const long rseed,
const double conditioning,
const char *problem_id_template,
const char *problem_name_template) {
double *xopt, fopt;
Expand All @@ -236,8 +237,8 @@ static coco_problem_t *f_ellipsoid_cons_bbob_problem_allocate(const size_t funct
fopt = bbob2009_compute_fopt(function, instance);
bbob2009_compute_xopt(xopt, rseed, dimension);

problem = f_ellipsoid_allocate(dimension);
problem -> condition = conditioning;
problem = f_ellipsoid_allocate(dimension, 1.0e6);

/* TODO (NH): fopt -= problem->evaluate(all_zeros(dimension)) */
problem = transform_vars_shift(problem, xopt, 0);
problem = transform_obj_shift(problem, fopt);
Expand All @@ -258,7 +259,6 @@ static coco_problem_t *f_ellipsoid_rotated_cons_bbob_problem_allocate(const size
const size_t dimension,
const size_t instance,
const long rseed,
const double conditioning,
const char *problem_id_template,
const char *problem_name_template) {
double *xopt, fopt;
Expand All @@ -277,8 +277,7 @@ static coco_problem_t *f_ellipsoid_rotated_cons_bbob_problem_allocate(const size
bbob2009_copy_rotation_matrix(rot1, M, b, dimension);
bbob2009_free_matrix(rot1, dimension);

problem = f_ellipsoid_allocate(dimension);
problem -> condition = conditioning;
problem = f_ellipsoid_allocate(dimension, 1.0e6);
problem = transform_vars_affine(problem, M, b, dimension);
problem = transform_vars_shift(problem, xopt, 0);
problem = transform_obj_shift(problem, fopt);
Expand Down

0 comments on commit 3254807

Please sign in to comment.