modea.Utils module¶
A collection of utilities for internal use by this package. Besides some trivial functions, this mainly includes
the ESFitness
class definition.
-
class
modea.Utils.
ESFitness
(fitnesses=None, target=1e-08, min_fitnesses=None, min_indices=None, num_successful=None, ERT=None, FCE=inf, std_dev_ERT=None, std_dev_FCE=None)¶ Bases:
object
Object to calculate and store the fitness measure for an ES and allow easy comparison. This measure consists of both the always available Fixed Cost Error (FCE) and the less available but more rigorous Expected Running Time (ERT).
All parameters are listed as optional, but at least one of the following combinations have to be given to obtain FCE/ERT values.
>>> ESFitness(fitnesses=fitnesses) >>> ESFitness(min_fitnesses=min_fitnesses, min_indices=min_indices, num_successful=num_successful) >>> ESFitness(ERT=ERT, FCE=FCE)
If
fitnesses
is specified, all other parameters other thantarget
are ignored and everything is calculated from that. Otherwise, ERT and FCE are calculated frommin_fitnesses
,min_indices
andnum_successful
. Only if none of these are specified, the directERT
andFCE
values are stored (together with their correspondingstd_dev_
values if specified)Parameters: - fitnesses – Nested lists: A list of the fitness progression for each run
- target – What value to use as target for calculating ERT. Default set in
Config
- min_fitnesses – Single list containing the minimum value of the
fitnesses
list (if given instead) - min_indices – Single list containing the index in the
fitnesses
list where the minimum was found - num_successful – Integer to simply track how many of the runs reached the target
- ERT – Estimated Running Time
- FCE – Fixed Cost Error
- std_dev_ERT – Standard deviation corresponding to the ERT value
- std_dev_FCE – Standard deviation corresponding to the FCE value
-
modea.Utils.
create_bounds
(values, percentage)¶ For a given set of floating point values, create an upper and lower bound. Bound values are defined as a percentage above/below the given values.
Parameters: - values – List of floating point input values.
- percentage – The percentage value to use, expected as a fraction in the range (0, 1).
Returns: Tuple (u_bound, l_bound), each a regular list.
-
modea.Utils.
getBitString
(opts)¶ Reverse of getOpts, transforms options dictionary to integer ‘bitstring’
Parameters: opts – Dictionary with option names and the chosen option Returns: A list of integers that serve as index for the options tuple
-
modea.Utils.
getFitness
(individual)¶ Function that can be used as key when sorting
Parameters: individual – Some object of one of the classes from the Individual
moduleReturns: Fitness attribute of the given individual object
-
modea.Utils.
getFullOpts
(opts)¶ Ensures that an options dictionary actually contains all options that have been defined. Any missing options are given default values inline.
Parameters: opts – Dictionary to be checked for option names and the chosen option
-
modea.Utils.
getOpts
(bitstring)¶ Transformation from integer ‘bitstring’ to options dictionary
Parameters: bitstring – List/array of integers that serve as index for the options tuple Returns: Dictionary with all option names and the chosen option
-
modea.Utils.
getPrintName
(opts)¶ Create a human-readable name from an options dictionary
Parameters: opts – Dictionary to be checked for option names and the chosen option Returns: Human-readable string listing all active CMA-ES options for the given dictionary
-
modea.Utils.
getVals
(init_values)¶ Transformation from real numbered vector to values dictionary
Parameters: init_values – List/array of real values that serve as initial values for parameters Returns: Dictionary containing name-indexed initial parameter values
-
modea.Utils.
guaranteeFolderExists
(path_name)¶ Make sure the given path exists after this call
-
modea.Utils.
intToRepr
(integer)¶ Dencode the ES-structure from a single integer back to the mixed base-2 and 3 representation. Reverse of
reprToInt()
>>> intToRepr(93) >>> [0,0,0,0,0,1,0,1,0,1,0]
Parameters: integer – Integer (e.g. outoutput from reprToInt() ) Returns: String consisting of all structure choices concatenated,
-
modea.Utils.
reprToInt
(representation)¶ Encode the ES-structure representation to a single integer by converting it to base-10 as if it is a mixed base-2 or 3 number. Reverse of
intToRepr()
>>> reprToInt([0,0,0,0,0,1,0,1,0,1,0]) >>> 93
Parameters: representation – Iterable; the genotype of the ES-structure Returns: String consisting of all structure choices concatenated,
-
modea.Utils.
reprToString
(representation)¶ Function that converts the structure parameters of a given ES-structure representation to a string
>>> reprToInt([0,0,0,0,0,1,0,1,0,1,0]) >>> '00000101010'
Parameters: representation – Iterable; the genotype of the ES-structure Returns: String consisting of all structure choices concatenated, e.g.: 00000101010