Skip to content

Commit

Permalink
Adding best_decision_vector to the python interface
Browse files Browse the repository at this point in the history
  • Loading branch information
FMGS666 committed Oct 3, 2023
1 parent 79ab40b commit 24cc517
Show file tree
Hide file tree
Showing 6 changed files with 1,846 additions and 1,744 deletions.
3,287 changes: 1,810 additions & 1,477 deletions code-experiments/build/python/cython/interface.c

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions code-experiments/build/python/cython/interface.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ cdef extern from "coco.h":
const double *coco_problem_get_largest_values_of_interest(const coco_problem_t *problem)
const double *coco_problem_get_largest_fvalues_of_interest(const coco_problem_t *problem)
# double coco_problem_get_final_target_fvalue1(const coco_problem_t *problem)
double coco_problem_get_best_value(const coco_problem_t *problem)
double * coco_problem_get_best_parameter(const coco_problem_t *problem)
size_t coco_problem_get_evaluations(const coco_problem_t *problem)
size_t coco_problem_get_evaluations_constraints(const coco_problem_t *problem)
void reset_seeds()
Expand Down Expand Up @@ -570,6 +572,14 @@ cdef class Problem:
self._largest_fvalues_of_interest = None
self.initialized = True
return self

cdef get_best_decision_vector(self):
cdef double * best_decision_vector = coco_problem_get_best_parameter(self.problem)
vector_list = []
for i in range(self.dimension):
vector_list.append(best_decision_vector[i])
return np.array(vector_list)

def constraint(self, x):
"""see __init__.py"""
if self.number_of_constraints <= 0:
Expand Down Expand Up @@ -752,6 +762,12 @@ cdef class Problem:
def evaluations_constraints(self):
return coco_problem_get_evaluations_constraints(self.problem)
@property
def best_value(self):
return coco_problem_get_best_value(self.problem)
@property
def best_decision_vector(self):
return self.get_best_decision_vector()
@property
def final_target_hit(self):
"""return 1 if the final target is known and has been hit, 0 otherwise
"""
Expand Down
267 changes: 0 additions & 267 deletions code-experiments/examples/bbob-noisy-python-cmaes/cmaes_experiment.py

This file was deleted.

Empty file.
11 changes: 11 additions & 0 deletions code-experiments/src/coco.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,17 @@ size_t coco_problem_get_number_of_constraints(const coco_problem_t *problem);
*/
size_t coco_problem_get_evaluations(const coco_problem_t *problem);


/**
* @brief Returns the optimal function value of the problem
*/
double coco_problem_get_best_value(const coco_problem_t *problem);

/**
* @brief Returns the optimal decision vector of the problem
*/
double * coco_problem_get_best_parameter(const coco_problem_t *problem);

/**
* @brief Returns the number of constraint function evaluations done on the problem.
*/
Expand Down
9 changes: 9 additions & 0 deletions code-experiments/src/coco_problem.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,15 @@ double coco_problem_get_best_value(const coco_problem_t *problem) {
return problem->best_value[0];
}

/**
* @brief Returns the optimal decision vector of the problem
*/
double * coco_problem_get_best_parameter(const coco_problem_t *problem){
assert(problem != NULL);
assert(problem->best_value != NULL);
return problem->best_parameter;
}

/**
* @note This function breaks the black-box property: the returned value is not
* meant to be used by the optimization algorithm.
Expand Down

0 comments on commit 24cc517

Please sign in to comment.