Skip to content

Commit

Permalink
Changing the allocation of the noisy problems
Browse files Browse the repository at this point in the history
  • Loading branch information
FMGS666 committed Oct 24, 2023
1 parent a215a0a commit c694887
Show file tree
Hide file tree
Showing 11 changed files with 1,930 additions and 2,062 deletions.
3,033 changes: 1,552 additions & 1,481 deletions code-experiments/build/python/cython/interface.c

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions code-experiments/build/python/cython/interface.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ cdef extern from "coco.h":
coco_problem_t* coco_suite_get_next_problem(coco_suite_t*, coco_observer_t*)
coco_problem_t* coco_suite_get_problem(coco_suite_t *, const size_t)

double coco_problem_get_last_noise_value(coco_problem_t *problem)
size_t coco_problem_get_suite_dep_index(const coco_problem_t* problem)
size_t coco_problem_get_dimension(const coco_problem_t *problem)
size_t coco_problem_get_number_of_objectives(const coco_problem_t *problem)
Expand Down Expand Up @@ -707,6 +708,10 @@ cdef class Problem:
return self.lower_bounds + rv_triangular * (
self.upper_bounds - self.lower_bounds) / 2
@property
def last_noise_value(self):
"""return last ftrue value"""
return coco_problem_get_last_noise_value(self.problem)
@property
def initial_solution(self):
"""return feasible initial solution"""
coco_problem_get_initial_solution(self.problem,
Expand Down
60 changes: 3 additions & 57 deletions code-experiments/src/coco.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,43 +218,6 @@ struct coco_random_state_s;
*/
typedef struct coco_random_state_s coco_random_state_t;


/** @brief Structure containing the noise model*/
struct coco_noise_model_s;

/**
* @brief The noisy COCO noise model type
* Wraps a noisy problem around a inner one
*/
typedef struct coco_noise_model_s coco_noise_model_t;

/**
* @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_allocator_t)(
const size_t function,
const size_t dimension,
const size_t instance,
const long rseed,
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_allocator_args_t)(
const size_t function,
const size_t dimension,
const size_t instance,
const long rseed,
const void *args,
const char *problem_id_template,
const char *problem_name_template);

/***********************************************************************************************************/
/**
* @name Methods regarding COCO suite
Expand Down Expand Up @@ -590,26 +553,6 @@ double coco_random_normal(coco_random_state_t *state);
*/
void reset_seeds(void);

/**
* @brief Samples gaussian variate for noisy function
*/
void coco_problem_gaussian_noise_model(coco_problem_t * problem, double * y);

/**
* @brief Samples gaussian variate for noisy function
*/
void coco_problem_uniform_noise_model(coco_problem_t * problem, double * y);

/**
* @brief Samples Cauchy variate for noisy function
*/
void coco_problem_cauchy_noise_model(coco_problem_t * problem, double * y);

/**
* @brief Evaluates the coco problem noisy function
* works as a wrapper around the function type coco_problem_f_evaluate
*/
void coco_problem_f_evaluate_wrap_noisy(coco_problem_t *problem, const double *x, double *y);
/**@}*/

/***********************************************************************************************************/
Expand Down Expand Up @@ -746,6 +689,9 @@ char *coco_strdupf(const char *str, ...);
void bbob_problem_best_parameter_print(const coco_problem_t *problem);
void bbob_biobj_problem_best_parameter_print(const coco_problem_t *problem);


double coco_problem_get_last_noise_value(coco_problem_t *problem);

#ifdef __cplusplus
}
#endif
Expand Down
30 changes: 2 additions & 28 deletions code-experiments/src/coco_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,14 @@ struct coco_problem_s {
coco_evaluate_function_t evaluate_gradient; /**< @brief The function for evaluating the constraints. */
coco_recommend_function_t recommend_solution; /**< @brief The function for recommending a solution. */
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; /** Lorenzo: < @brief The noise model for noisy problems*/

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. */
size_t number_of_constraints; /**< @brief Number of constraints. */

double last_noise_value;

double *smallest_values_of_interest; /**< @brief The lower bounds of the ROI in the decision space. */
double *largest_values_of_interest; /**< @brief The upper bounds of the ROI in the decision space. */
size_t number_of_integer_variables; /**< @brief Number of integer variables (if > 0, all integer variables come
Expand Down Expand Up @@ -239,31 +238,6 @@ struct coco_suite_s {

static void bbob_evaluate_gradient(coco_problem_t *problem, const double *x, double *y);

/***********************************************************************************************************/
/**
* @name The structures and type definitions needed for performing experiments on noisy problems
*/
/**{@*/

/**
* @brief The COCO problem noise sampler function type
*/
typedef void (*coco_problem_evaluate_noise_model_t)(coco_problem_t *problem, double *y);

/**
* @brief The COCO noise model structure
* The structure containing information about the noise model applied to the problem
*/
struct coco_noise_model_s{

coco_problem_evaluate_noise_model_t noise_sampler; /**< @brief The function defining the noise model*/

double *distribution_theta; /**< @brief Parameters of the distribution from which the noise is drawn*/

};

/**@}*/

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

#ifdef __cplusplus
Expand Down
18 changes: 6 additions & 12 deletions code-experiments/src/coco_problem.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,18 +153,14 @@ static coco_problem_t *coco_problem_allocate(const size_t number_of_variables,
const size_t number_of_objectives,
const size_t number_of_constraints) {
coco_problem_t *problem;
coco_noise_model_t *noise_model;
problem = (coco_problem_t *) coco_allocate_memory(sizeof(*problem));
noise_model = (coco_noise_model_t *) coco_allocate_memory(sizeof(*noise_model));
/* Initialize fields to sane/safe defaults */
problem->initial_solution = NULL;
problem->evaluate_function = NULL;
problem->evaluate_constraint = NULL;
problem->evaluate_gradient = NULL;
problem->recommend_solution = NULL;
problem->problem_free_function = NULL;
problem -> noise_model = noise_model;
problem -> placeholder_evaluate_function = NULL;

problem->number_of_variables = number_of_variables;
problem->number_of_objectives = number_of_objectives;
Expand Down Expand Up @@ -313,8 +309,6 @@ void coco_problem_free(coco_problem_t *problem) {
coco_free_memory(problem->data);
if (problem->initial_solution != NULL)
coco_free_memory(problem->initial_solution);
if (problem -> noise_model != NULL)
coco_free_memory(problem -> noise_model);
problem->smallest_values_of_interest = NULL;
problem->largest_values_of_interest = NULL;
problem->best_parameter = NULL;
Expand Down Expand Up @@ -417,12 +411,6 @@ size_t coco_problem_get_evaluations_constraints(const coco_problem_t *problem) {
return problem->evaluations_constraints;
}

double *coco_problem_get_distribution_theta(const coco_problem_t *problem){
assert(problem != NULL);
assert(problem -> noise_model -> distribution_theta != NULL);
return problem -> noise_model -> distribution_theta;
}

/**
* @brief Returns 1 if the best parameter is not (close to) zero and 0 otherwise.
*/
Expand Down Expand Up @@ -986,3 +974,9 @@ static coco_problem_t *coco_problem_stacked_allocate(coco_problem_t *problem1,
/**@}*/

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

double coco_problem_get_last_noise_value(coco_problem_t *problem){
assert(problem != NULL);
assert(problem -> last_noise_value != NAN);
return problem -> last_noise_value;
}

0 comments on commit c694887

Please sign in to comment.