iwopy.core.function.OptFunction
- class iwopy.core.function.OptFunction[source]
Bases:
Base
Abstract base class for functions that calculate scalars based on a problem.
- Parameters:
problem (iwopy.Problem) – The underlying optimization problem
name (str) – The function name
n_vars_int (int, optional) – The number of integer variables. If not specified it is assumed that the function depends on all problem int variables
n_vars_float (int, optional) – The number of float variables. If not specified it is assumed that the function depends on all problem float variables
vnames_int (list of str, optional) – The integer variable names. Useful for mapping function variables to problem variables, otherwise map by integer or default name
vnames_float (list of str, optional) – The float variable names. Useful for mapping function variables to problem variables, otherwise map by integer or default name
cnames (list of str, optional) – The names of the components
- problem
The underlying optimization problem
- Type:
iwopy.Problem
- __init__(problem, name, n_vars_int=None, n_vars_float=None, vnames_int=None, vnames_float=None, cnames=None)[source]
Methods
__init__
(problem, name[, n_vars_int, ...])ana_deriv
(vars_int, vars_float, var[, ...])Calculates the analytic derivative, if possible.
calc_individual
(vars_int, vars_float, ...[, ...])Calculate values for a single individual of the underlying problem.
calc_population
(vars_int, vars_float, ...[, ...])Calculate values for all individuals of a population.
finalize
([verbosity])Finalize the object.
finalize_individual
(vars_int, vars_float, ...)Finalization, given the champion data.
finalize_population
(vars_int, vars_float, ...)Finalization, given the final population data.
initialize
([verbosity])Initialize the object.
Returns the number of components of the function.
rename_vars_float
(varmap)Rename float variables.
rename_vars_int
(varmap)Rename integer variables.
Gets the dependencies of all components on the function float variables
Gets the dependencies of all components on the function int variables
Attributes
The names of the components
Flag for finished initialization
The number of float variables
The number of int variables
The names of the float variables
The names of the integer variables
- __init__(problem, name, n_vars_int=None, n_vars_float=None, vnames_int=None, vnames_float=None, cnames=None)[source]
- ana_deriv(vars_int, vars_float, var, components=None)[source]
Calculates the analytic derivative, if possible.
Use numpy.nan if analytic derivatives cannot be calculated.
- Parameters:
- Returns:
deriv – The derivative values, shape: (n_sel_components,)
- Return type:
- calc_individual(vars_int, vars_float, problem_results, components=None)[source]
Calculate values for a single individual of the underlying problem.
- Parameters:
vars_int (np.array) – The integer variable values, shape: (n_vars_int,)
vars_float (np.array) – The float variable values, shape: (n_vars_float,)
problem_results (Any) – The results of the variable application to the problem
components (list of int, optional) – The selected components or None for all
- Returns:
values – The component values, shape: (n_sel_components,)
- Return type:
np.array
- calc_population(vars_int, vars_float, problem_results, components=None)[source]
Calculate values for all individuals of a population.
- Parameters:
vars_int (np.array) – The integer variable values, shape: (n_pop, n_vars_int)
vars_float (np.array) – The float variable values, shape: (n_pop, n_vars_float)
problem_results (Any) – The results of the variable application to the problem
components (list of int, optional) – The selected components or None for all
- Returns:
values – The component values, shape: (n_pop, n_sel_components)
- Return type:
np.array
- property component_names
The names of the components
- finalize(verbosity=0)
Finalize the object.
- Parameters:
verbosity (int) – The verbosity level, 0 = silent
- finalize_individual(vars_int, vars_float, problem_results, verbosity=1)[source]
Finalization, given the champion data.
- Parameters:
vars_int (np.array) – The optimal integer variable values, shape: (n_vars_int,)
vars_float (np.array) – The optimal float variable values, shape: (n_vars_float,)
problem_results (Any) – The results of the variable application to the problem
verbosity (int) – The verbosity level, 0 = silent
- Returns:
values – The component values, shape: (n_components,)
- Return type:
np.array
- finalize_population(vars_int, vars_float, problem_results, verbosity=1)[source]
Finalization, given the final population data.
- Parameters:
vars_int (np.array) – The integer variable values of the final generation, shape: (n_pop, n_vars_int)
vars_float (np.array) – The float variable values of the final generation, shape: (n_pop, n_vars_float)
problem_results (Any) – The results of the variable application to the problem
verbosity (int) – The verbosity level, 0 = silent
- Returns:
values – The component values, shape: (n_pop, n_components)
- Return type:
np.array
- initialize(verbosity=0)[source]
Initialize the object.
- Parameters:
verbosity (int) – The verbosity level, 0 = silent
- property initialized
Flag for finished initialization
- Returns:
True if initialization has been done
- Return type:
- abstract n_components()[source]
Returns the number of components of the function.
- Returns:
The number of components.
- Return type:
- property n_vars_float
The number of float variables
- Returns:
n – The number of float variables
- Return type:
- property n_vars_int
The number of int variables
- Returns:
n – The number of int variables
- Return type:
- rename_vars_float(varmap)[source]
Rename float variables.
- Parameters:
varmap (dict) – The name mapping. Key: old name str, Value: new name str
- rename_vars_int(varmap)[source]
Rename integer variables.
- Parameters:
varmap (dict) – The name mapping. Key: old name str, Value: new name str
- property var_names_float
The names of the float variables
- property var_names_int
The names of the integer variables
- vardeps_float()[source]
Gets the dependencies of all components on the function float variables
- Returns:
deps – The dependencies of components on function variables, shape: (n_components, n_vars_float)
- Return type: