culebra.abc.Fitness
class¶
- class Fitness(values: Tuple[float, ...] = ())¶
Construct a default fitness object.
- Parameters:
values (
tuple
, optional) – Initial values for the fitness, defaults to ()
Class attributes¶
- Fitness.weights = None¶
A
tuple
containing an integer value for each objective being optimized. The weights are used in the fitness comparison. They are shared among all fitnesses of the same type. When subclassingFitness
, the weights must be defined as a tuple where each element is associated to an objective. A negative weight element corresponds to the minimization of the associated objective and positive weight to the maximization. This attribute is inherited fromdeap.base.Fitness
.Note
If weights is not defined during subclassing, the following error will occur at instantiation of a subclass fitness object:
TypeError: Can't instantiate abstract <class Fitness[...]> with abstract attribute weights.
- Fitness.names = None¶
Names of the objectives.
If not defined, generic names will be used.
- Fitness.thresholds = None¶
A list with the similarity thresholds defined for all the objectives. Fitness objects are compared lexicographically. The comparison applies a similarity threshold to assume that two fitness values are similar (if their difference is lower than or equal to the similarity threshold). If not defined, 0 will be used for each objective.
Class methods¶
- classmethod Fitness.load_pickle(filename: str) Base ¶
Load a pickled object from a file.
- Parameters:
filename (
str
) – The file name.- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
PICKLE_FILE_EXTENSION
- classmethod Fitness.get_objective_threshold(obj_name: str) float ¶
Get the similarity threshold for the given objective.
- Parameters:
obj_name (
str
) – Objective name whose threshold is returned- Raises:
TypeError – If obj_name isn’t a string
ValueError – If obj_name isn’t a valid objective name
Properties¶
- property Fitness.pheromone_amount: Tuple[float, ...]¶
Return the amount of pheromone to be deposited.
This property is intended for ACO-based approaches. By default, the reciprocal of an objective fitness will be used for minimization objectives, while the objective’s value will be used for maximization problems. Fitness classes pretending a different behavior should override this property.
- Returns:
The amount of pheromone to be deposited for each objective
- Return type:
tuple
of py:class:float
Methods¶
- Fitness.save_pickle(filename: str) None ¶
Pickle this object and save it to a file.
- Parameters:
filename (
str
) – The file name.- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
PICKLE_FILE_EXTENSION
- Fitness.dominates(other: Fitness, which: slice = slice(None, None, None)) bool ¶
Check if this fitness dominates another one.
- Parameters:
- Returns:
True
if each objective of this fitness is not strictly worse than the corresponding objective of the other and at least one objective is strictly better- Return type:
Dunder methods¶
Intended to compare (lexicographically) two individuals according to their fitness.
- Fitness.__eq__(other: Fitness) bool ¶
Lexicographic equal to operator.
- Parameters:
other (
Fitness
) – The other fitness
- Fitness.__ne__(other: Fitness) bool ¶
Lexicographic not equal to operator.
- Parameters:
other (
Fitness
) – The other fitness
- Fitness.__lt__(other: Fitness) bool ¶
Lexicographic less than operator.
- Parameters:
other (
Fitness
) – The other fitness
- Fitness.__gt__(other: Fitness) bool ¶
Lexicographic greater than operator.
- Parameters:
other (
Fitness
) – The other fitness