Skip to content

Commit

Permalink
Return numpy arrays for individuals / results
Browse files Browse the repository at this point in the history
  • Loading branch information
schmoelder committed Mar 26, 2024
1 parent e832ac0 commit cd4c8ee
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions CADETProcess/optimization/optimizationProblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def variables_dict(self):
@property
def variable_values(self):
"""list: Values of optimization variables."""
return [var.value for var in self.variables]
return np.array([var.value for var in self.variables])

def add_variable(
self, name, evaluation_objects=-1, parameter_path=None,
Expand Down Expand Up @@ -561,7 +561,7 @@ def get_dependent_values(self, x):
Parameters
----------
x : list
x : array_like
Value of the optimization variables in untransformed space.
Raises
Expand All @@ -571,7 +571,7 @@ def get_dependent_values(self, x):
Returns
-------
x : list
x : np.ndarray
Value of all optimization variables in untransformed space.
"""
Expand All @@ -596,7 +596,7 @@ def get_independent_values(self, x):
Parameters
----------
x : list
x : array_like
Value of all optimization variables.
Works for transformed and untransformed space.
Expand All @@ -607,7 +607,7 @@ def get_independent_values(self, x):
Returns
-------
x_independent : list
x_independent : np.ndarray
Values of all independent optimization variables.
"""
Expand All @@ -622,7 +622,7 @@ def get_independent_values(self, x):
if variable.is_independent:
x_independent.append(value)

return x_independent
return np.array(x_independent)

@untransforms
def set_variables(self, x, evaluation_objects=-1):
Expand Down Expand Up @@ -678,7 +678,7 @@ def _evaluate_individual(self, eval_funs, x, force=False):
Returns
-------
results : list
results : np.ndarray
Values of the evaluation functions at point x.
See Also
Expand Down Expand Up @@ -721,12 +721,12 @@ def _evaluate_population(self, eval_fun, population, force=False, parallelizatio
Raises
------
CADETProcessError
DESCRIPTION.
If dictcache is used for parallelized evaluation.
Returns
-------
results : list
DESCRIPTION.
results : np.ndarray
Results of the evaluation functions.
"""
if parallelization_backend is None:
Expand Down Expand Up @@ -765,8 +765,8 @@ def _evaluate(self, x, func, force=False):
Returns
-------
results : TYPE
DESCRIPTION.
results : np.ndarray
Results of the evaluation functions.
"""
self.logger.debug(f'evaluate {str(func)} at {x}')
Expand Down Expand Up @@ -1043,7 +1043,7 @@ def evaluate_objectives(self, x, force=False):
Returns
-------
f : list
f : np.ndarray
Values of the objective functions at point x.
See Also
Expand Down Expand Up @@ -1083,7 +1083,7 @@ def evaluate_objectives_population(
Returns
-------
results : list
results : np.ndarray
Objective function values.
See Also
Expand Down Expand Up @@ -1112,7 +1112,7 @@ def objective_jacobian(self, x, ensure_minimization=False, dx=1e-3):
Returns
-------
jacobian: list
jacobian: np.array
Value of the partial derivatives at point x.
See Also
Expand Down Expand Up @@ -1298,7 +1298,7 @@ def evaluate_nonlinear_constraints(self, x, force=False):
Returns
-------
g : list
g : np.ndarray
Nonlinear constraint function values.
See Also
Expand Down Expand Up @@ -1334,7 +1334,7 @@ def evaluate_nonlinear_constraints_population(self, population, force=False, par
Returns
-------
results : list
results : np.ndarray
Nonlinear constraints.
See Also
Expand Down Expand Up @@ -1417,7 +1417,7 @@ def evaluate_nonlinear_constraints_violation_population(
Returns
-------
results : list
results : np.ndarray
Nonlinear constraints violation.
See Also
Expand Down Expand Up @@ -1651,11 +1651,6 @@ def evaluate_callbacks_population(
Runner to use for the evaluation of the population in
sequential or parallel mode.
Returns
-------
results : list
Nonlinear constraint function values.
See Also
--------
add_callback
Expand Down Expand Up @@ -1802,7 +1797,7 @@ def evaluate_meta_scores(self, x, force=False):
Returns
-------
m : list
m : np.ndarray
Meta scores.
See Also
Expand Down Expand Up @@ -1835,7 +1830,7 @@ def evaluate_meta_scores_population(self, population, force=False, parallelizati
sequential or parallel mode.
Returns
-------
results : list
results : np.ndarray
Meta scores.
See Also
Expand Down Expand Up @@ -1917,7 +1912,7 @@ def evaluate_multi_criteria_decision_functions(self, pareto_population):
Returns
-------
x_pareto : list
x_pareto : np.ndarray
Value of the optimization variables.
See Also
Expand Down Expand Up @@ -2281,7 +2276,7 @@ def evaluate_linear_constraints(self, x):
Returns
-------
constraints: np.array
constraints: np.ndarray
Value of the linear constraints at point x
See Also
Expand Down Expand Up @@ -2618,7 +2613,7 @@ def transform(self, x_independent):
Returns
-------
list
np.ndarray
Optimization variables in transformed parameter space.
"""
x_independent = np.array(x_independent)
Expand All @@ -2631,7 +2626,7 @@ def transform(self, x_independent):
for value, var in zip(ind, self.independent_variables)
]

return transform.reshape(x_independent.shape).tolist()
return transform.reshape(x_independent.shape)

def untransform(self, x_transformed):
"""Untransform the optimization variables from transformed parameter space.
Expand All @@ -2643,7 +2638,7 @@ def untransform(self, x_transformed):
Returns
-------
list
np.ndarray
Optimization variables in untransformed parameter space.
"""
x_transformed = np.array(x_transformed)
Expand All @@ -2656,7 +2651,7 @@ def untransform(self, x_transformed):
for value, var in zip(ind, self.independent_variables)
]

return untransform.reshape(x_transformed.shape).tolist()
return untransform.reshape(x_transformed.shape)

@property
def cached_steps(self):
Expand Down Expand Up @@ -3081,7 +3076,7 @@ def check_individual(self, x, silent=False):
Parameters
----------
x : list
x : array_like
Value of the optimization variables in untransformed space.
Returns
Expand Down

0 comments on commit cd4c8ee

Please sign in to comment.