iwopy.benchmarks.branin.BraninObjective

class iwopy.benchmarks.branin.BraninObjective[source]

Bases: SimpleObjective

The objective function for the Branin problem.

The Branin (or Branin-Hoo) function is defined as

f(x,y) = a(y-bx^2+cx-r)^2 + s(1-t)cos(x)+s

Recommended values for the parameters are: a = 1 b = 5.1/(4*pi^2) c = 5/pi r = 6 s = 10 t = 1/(8*pi)

Domain: x = [-5, 10] y = [0, 15]

The Branin function has three global minima at

(x,y) = (-pi, 12.275), (pi, 2.275), (9.42478, 2.475)

with a function value of

f(x,y) = 0.397887

Parameters:
  • problem (iwopy.Problem) – The underlying optimization problem

  • ana_deriv (bool) – Switch for analytical derivatives

  • name (str) – The function name

__init__(problem, ana_deriv=False, name='f')[source]

Methods

__init__(problem[, ana_deriv, name])

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.

f(x, y)

The Branin function f(x, y)

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.

g(var, x, y[, components])

The derivative of the Branin function

initialize([verbosity])

Initialize the object.

maximize()

Returns flag for maximization of each component.

n_components()

Returns the number of components of the function.

rename_vars_float(varmap)

Rename float variables.

rename_vars_int(varmap)

Rename integer variables.

vardeps_float()

Gets the dependencies of all components on the function float variables

vardeps_int()

Gets the dependencies of all components on the function int variables

Attributes

component_names

The names of the components

has_ana_derivs

Returns analyical derivatives flag

initialized

Flag for finished initialization

n_vars_float

The number of float variables

n_vars_int

The number of int variables

var_names_float

The names of the float variables

var_names_int

The names of the integer variables

__init__(problem, ana_deriv=False, name='f')[source]
ana_deriv(vars_int, vars_float, var, components=None)

Calculates the analytic derivative, if possible.

Use numpy.nan if analytic derivatives cannot be calculated.

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,)

  • var (int) – The index of the differentiation float variable

  • components (list of int) – The selected components, or None for all

Returns:

deriv – The derivative values, shape: (n_sel_components,)

Return type:

numpy.ndarray

calc_individual(vars_int, vars_float, problem_results, components=None)

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)

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

Returns:

names – The component names

Return type:

list of str

f(x, y)[source]

The Branin function f(x, y)

finalize(verbosity=0)

Finalize the object.

Parameters:

verbosity (int) – The verbosity level, 0 = silent

finalize_individual(vars_int, vars_float, problem_results, verbosity=1)

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)

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

g(var, x, y, components=None)[source]

The derivative of the Branin function

property has_ana_derivs

Returns analyical derivatives flag

Returns:

Analitical derivatives flag

Return type:

bool

initialize(verbosity=0)

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:

bool

maximize()

Returns flag for maximization of each component.

Returns:

flags – Bool array for component maximization, shape: (n_components,)

Return type:

np.array

n_components()

Returns the number of components of the function.

Returns:

The number of components.

Return type:

int

property n_vars_float

The number of float variables

Returns:

n – The number of float variables

Return type:

int

property n_vars_int

The number of int variables

Returns:

n – The number of int variables

Return type:

int

rename_vars_float(varmap)

Rename float variables.

Parameters:

varmap (dict) – The name mapping. Key: old name str, Value: new name str

rename_vars_int(varmap)

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

Returns:

names – The float variable names

Return type:

list of str

property var_names_int

The names of the integer variables

Returns:

names – The integer variable names

Return type:

list of str

vardeps_float()

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:

numpy.ndarray of bool

vardeps_int()

Gets the dependencies of all components on the function int variables

Returns:

deps – The dependencies of components on function variables, shape: (n_components, n_vars_int)

Return type:

numpy.ndarray of bool