culebra.abc.FitnessFunction
class¶
- class FitnessFunction¶
Base fitness function.
Class attributes¶
- class culebra.abc.FitnessFunction.Fitness¶
Handles the values returned by the
evaluate()
method, within aSolution
.This class must be implemented within all the
FitnessFunction
subclasses, as a subclass of theFitness
class, to define its three class attributes (weights
,names
, andthresholds
) according to the fitness function.
Class methods¶
- classmethod FitnessFunction.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 FitnessFunction.set_fitness_thresholds(thresholds: float | Sequence[float]) None ¶
Set new fitness thresholds.
Modifies the
thresholds
of theFitness
objects generated by this fitness function.- Parameters:
thresholds (
float
orSequence
offloat
) – The new thresholds. If only a single value is provided, the same threshold will be used for all the objectives. Different thresholds can be provided in aSequence
- Raises:
TypeError – If thresholds is not a real number or a
Sequence
of real numbersValueError – If any threshold is negative
- classmethod FitnessFunction.get_fitness_objective_threshold(obj_name: str) None ¶
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 value isn’t a valid objective name
- classmethod FitnessFunction.set_fitness_objective_threshold(obj_name: str, value: float) None ¶
Set a similarity threshold for the given fitness objective.
- Parameters:
- Raises:
TypeError – If obj_name isn’t a string or value isn’t a real number
ValueError – If obj_name isn’t a valid objective name or value is lower than 0
Properties¶
Methods¶
- FitnessFunction.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
- FitnessFunction.heuristic(species: Species) Sequence[ndarray, ...] | None ¶
Get the heuristic matrices for ACO-based trainers.
Subclasses solvable with ACO-based approaches should override this method. Otherwise,
None
is returned
- abstract FitnessFunction.evaluate(sol: Solution, index: int | None = None, representatives: Sequence[Solution] | None = None) Tuple[float, ...] ¶
Evaluate a solution.
Parameters representatives and index are used only for cooperative evaluations
This method must be overridden by subclasses to return a correct value.
- Parameters:
sol (
Solution
) – Solution to be evaluated.index (
int
, optional) – Index where sol should be inserted in the representatives sequence to form a complete solution for the problemrepresentatives (A
Sequence
containing instances ofSolution
, optional) – Representative solutions of each species being optimized
- Raises:
NotImplementedError – if has not been overridden
- Returns:
The fitness values for sol
- Return type: