Fitness¶
The library allows the use two main types of fitnesses (FitnessTuple, FitnessTupleMultiobj), both inherit from the Base class.
Base fitness class¶
-
class
microgp.fitness.base.
Base
¶ Base class for storing fitness.
The different selection schemes are implemented simply by overriding the > (greater than) operator. See the other fitness.Classes for details.
Please note that, according to Spencer’s ‘Survival of the Fittest’, the bigger the better. Thus we are maximizing the fitness and not minimizing a mathematical function.
The method calling the correspondent Base.sort()
is:
Fitness Tuple¶
-
class
microgp.fitness.fitnesstuple.
FitnessTuple
¶ Fitness used for single objective purposes.
-
static
sort
(fmap: List[Tuple[Any, Type[FitnessTuple]]]) → List[Tuple[Any, Type[microgp.fitness.fitnesstuple.FitnessTuple]]]¶ Sort a list of tuple (Any, FitnessTuple)
Parameters: fmap – list of tuple (Any, FitnessTuple) Returns: an ordered list of tuples (Any, FitnessTuple)
-
static
-
class
microgp.fitness.simple.
Simple
¶ The simplest possible fitness: a single value
-
class
microgp.fitness.lexicographic.
Lexicographic
¶ Tuples able to smoothly handle single- and multi-value fitnesses
Fitness Tuple Multiobjective¶
microgp.fitness.fitnesstuplemultiobj
-
class
microgp.fitness.fitnesstuplemultiobj.
FitnessTupleMultiobj
¶ Fitness used for multiple objective purposes.
-
static
sort
(fmap: List[Tuple[Any, Type[FitnessTupleMultiobj]]]) → List[Tuple[Any, Type[microgp.fitness.fitnesstuplemultiobj.FitnessTupleMultiobj]]]¶ Sort a list of tuple (Any, FitnessTupleMultiobj) using Pareto front
Parameters: fmap – list of tuple (Any, FitnessTupleMultiobj) Returns: an ordered list of tuples (Any, FitnessTupleMultiobj)
-
static
Sorting example considering an input of type List[Individual, FitnessTupleMultiobj].
real_order[ {ind3, ind2}, {ind5, ind1, ind7}, {ind4}, {ind6, ind8}, {ind9} ] ranking = { (ind1, ind1.fitness): 2, (ind2, ind2.fitness): 1, (ind3, ind3.fitness): 1, (ind4, ind4.fitness): 3, (ind5, ind5.fitness): 2, (ind6, ind6.fitness): 4, (ind7, ind7.fitness): 2, (ind8, ind8.fitness): 4, (ind9, ind9.fitness): 5 } returned_value = [ (ind2, ind2.fitness) (ind3, ind3.fitness) (ind1, ind1.fitness) (ind5, ind5.fitness) (ind7, ind7.fitness) (ind4, ind4.fitness) (ind6, ind6.fitness) (ind8, ind8.fitness) (ind9, ind9.fitness) ]
-
class
microgp.fitness.lexicase.
Lexicase
¶ A fitness for using Lexicase Selection.
Lexicase Selection is a technique supposedly able to handle multi-objective problems where solutions must perform optimally on each of many test cases.
See ‘Solving Uncompromising Problems With Lexicase Selection’, by T. Helmuth, L. Spector, and J. Matheson <https://dx.doi.org/10.1109/TEVC.2014.2362729>
Note: as an alternative, consider using Chromatic Selection.
-
class
microgp.fitness.aggregate.
Aggregate
¶ Tuples able to smoothly handle single- and multi-value fitnesses
-
class
microgp.fitness.chromatic.
Chromatic
¶ A fitness for using Chromatic Selection.
Chromatic Selection is a fast, simple and grossly approximate technique for tackling multi-value optimization. See: ‘Chromatic Selection – An Oversimplified Approach to Multi-objective Optimization’, by G. Squillero <https://dx.doi.org/10.1007/978-3-319-16549-3_55>
Note: as an alternative, consider using Lexicase Selection.
Evaluator¶
-
microgp.fitness.evaluator.
make_evaluator
(evaluator: Union[str, callable], fitness_type: Type[microgp.fitness.fitnesstuple.FitnessTuple] = <class 'microgp.fitness.simple.Simple'>, num_elements: int = None) → Callable¶ Build a fitness evaluator that calls a script.
Parameters: - evaluator (str or callable) – name of the script. The result is taken from stdout.
- fitness_type – kind of fitness, ie. type of comparison.
- num_elements (int) – number of relevant element in the script output, the remaining are considered “comment”. If None, the all output is part of the fitness.
Returns: A function that can be stored into Constraints.evaluator.