class documentation

class RoundIntegerVariables(object):

Constructor: RoundIntegerVariables(options, round_integer_variables)

View In Hierarchy

Round integer variables of solutions at the end of ask via

the round_population method and provide an archive to retrieve the unrounded solutions with unrounded_population at the beginning of tell.

Also catch possibly changed solutions, depending on the parameters passed to unrounded_population.

Method __init__ CMAOptions, bool, bool passed from cma.evolution_strategy module
Method round_population round integer variables of solutions in pop_pheno and store
Method unrounded_population revert round_population of solutions and return a new list
Instance Variable archive Undocumented
Instance Variable count Undocumented
Instance Variable params Undocumented
Method _catch_modified catch modified solutions to revert their rounding too and/or
Method _round_int_variables round integer variables in solution if self._active.
Property _active check 'round_integer_variables' parameter and
def __init__(self, options, round_integer_variables):

CMAOptions, bool, bool passed from cma.evolution_strategy module

def round_population(self, pop_pheno):

round integer variables of solutions in pop_pheno and store

the original solutions in self.archive. pop_pheno should be a list of arrays. When pop_pheno is an array, it is overwritten and its original values may be lost.

By design, fixed variables are never changed (they were removed from the _pheno_integer_variables index list too). Hence they are not rounded either.

def unrounded_population(self, solutions, revert_modified=True, warn=True, final_len=0):

revert round_population of solutions and return a new list

when integer variables and archived solutions are present, otherwise return solutions as is.

If revert_modfied, try to retrieve the nonrounded versions of solutions even when they were modified between ask and tell. This means that the modification is ignored in tell, while it might have been used to compute the fitness.

Truncate the archive if necessary.

Details: this method is entirely ignorant about whether or how solutions were rounded or transformed. However, it calls _catch_modified which uses round_integer_variables and _round_int_variables to compute a delta of an unexpected modification to avoid unnecessary warnings when the delta is zero.

archive =

Undocumented

count: int =

Undocumented

params =

Undocumented

def _catch_modified(self, popped_solutions, solutions, revert=True, warn=True):

catch modified solutions to revert their rounding too and/or

warn of inconcistencies. This should normally do nothing as the archive should be empty. Elements of popped_solutions are the nonrounded versions of solutions and may be reassigned (which changes the reference when it is a list, but the content when it is an ndarray).

Modifications between storing and retrieving a solution are found by comparing to the unhashed key which only reflects inplace modifications.

Uses round_integer_variables which is an argument of the class instance constructor and then ._round_int_variables to compute a delta to warn only when the delta is nonzero.

TODO: instead of using ._round_int_variables pass an optional transformation making this much more generic.

def _round_int_variables(self, solution, copy_when_changed=True):

round integer variables in solution if self._active.

See also CMAEvolutionStrategy._round_int_variables.

@property
_active =

check 'round_integer_variables' parameter and

'integer_variables' option. Return number of active integer variables or False.

Details: '_pheno_integer_variables' don't include indices of fixed variables either, hence the don't need to be checked here.