class documentation

Compute a bound penalty and update coordinate-wise penalty weights.

An instance must be updated each iteration using the update method.

Details:

  • The penalty computes like sum(w[i] * (x[i]-xfeas[i])**2), where xfeas is the closest feasible (in-bounds) solution from x. The weight w[i] should be updated during each iteration using the update method.

Example how this boundary handler is used with cma.fmin via the options (CMAOptions) of the class cma.CMAEvolutionStrategy:

>>> import cma
>>> res = cma.fmin(cma.ff.elli, 6 * [0.9], 0.1,
...     {'BoundaryHandler': cma.BoundPenalty,
...      'bounds': [-1, 1],
...      'tolflatfitness': 10,
...      'fixed_variables': {0: 0.012, 2:0.234}
...     })  # doctest: +ELLIPSIS
(4_w,8)-aCMA-ES (mu_w=2.6,w_1=52%) in dimension 4 (seed=...
>>> if res[1] >= 13.76: print(res)  # should never happen

Reference: Hansen et al 2009, A Method for Handling Uncertainty... IEEE TEC, with addendum, see https://ieeexplore.ieee.org/abstract/document/4634579 https://hal.inria.fr/inria-00276216/file/TEC2008.pdf

todo: implement a more generic interface, where this becomes a fitness wrapper which adds the desired penalty and the update method is used as callback argument for fmin like:

f = cma.BoundPenalty(cma.ff.elli, bounds=[-1, 1])
res = cma.fmin(f, 6 * [1], callback=f.update)

where callback functions should receive the same arguments as tell, namely an CMAEvolutionStrategy instance, an array of the current solutions and their respective f-values. Such change is relatively involved. Consider also that bounds are related with the geno- to phenotype transformation.

Method __call__ returns the boundary violation penalty for x, where x is a single solution or a list or np.array of solutions.
Method __init__ Argument bounds can be None or bounds[0] and bounds[1] are lower and upper domain boundaries, each is either None or a scalar or a list or np.array of appropriate size.
Method feasible_ratio counts for each coordinate the number of feasible values in solutions and returns an np.array of length len(solutions[0]) with the ratios.
Method repair sets out-of-bounds components of x on the bounds.
Method update updates the weights for computing a boundary penalty.
Instance Variable gamma Undocumented
Instance Variable hist Undocumented
Instance Variable weights_initialized Undocumented

Inherited from BoundaryHandlerBase:

Method amend_bounds_for_integer_variables set bounds away from at=0.5 such that
Method get_bound return lower and upper bound of variable with index index
Method get_bounds get_bounds('lower', 8) returns the lower bounds in 8-D
Method has_bounds return True if any variable is bounded
Method idx_out_of_bounds return index list of out-of-bound values in x.
Method inverse inverse of repair if it exists, at least it should hold repair == repair o inverse o repair
Method is_in_bounds not yet tested
Method to_dim_times_two return boundaries in format [[lb0, ub0], [lb1, ub1], ...], as used by BoxConstraints... class.
Instance Variable bounds Undocumented
Method _get_bounds ib == 0/1 means lower/upper bound, return a vector of length dimension
def __call__(self, x, archive, gp):

returns the boundary violation penalty for x, where x is a single solution or a list or np.array of solutions.

def __init__(self, bounds=None):

Argument bounds can be None or bounds[0] and bounds[1] are lower and upper domain boundaries, each is either None or a scalar or a list or np.array of appropriate size.

def feasible_ratio(self, solutions):

counts for each coordinate the number of feasible values in solutions and returns an np.array of length len(solutions[0]) with the ratios.

def repair(self, x, copy_if_changed=True):

sets out-of-bounds components of x on the bounds.

def update(self, function_values, es):

updates the weights for computing a boundary penalty.

Arguments

function_values:
all function values of recent population of solutions
es:
CMAEvolutionStrategy object instance, in particular mean and variances and the methods from the attribute gp of type GenoPheno are used.
gamma =

Undocumented

hist: list =

Undocumented

weights_initialized: bool =

Undocumented