culebra.fitness_function.abc.CooperativeFSScorer
class¶
- class CooperativeFSScorer¶
Abstract base class fitness function for cooperative FS problems.
Class attributes¶
- class culebra.fitness_function.abc.CooperativeFSScorer.Fitness¶
Handles the values returned by the
evaluate()
method within aSolution
.This class must be implemented within all the
CooperativeFSScorer
subclasses, as a subclass of theFitness
class, to define its three class attributes (weights
,names
, andthresholds
) according to the fitness function.
Class methods¶
- classmethod CooperativeFSScorer.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 CooperativeFSScorer.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 CooperativeFSScorer.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 CooperativeFSScorer.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¶
- CooperativeFSScorer.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
- CooperativeFSScorer.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 CooperativeFSScorer.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:
- CooperativeFSScorer.construct_solutions(sol: Solution, index: int | None = None, representatives: Sequence[Solution] | None = None) Tuple[Solution, ...] ¶
Assemble the solution and representatives.
This fitness function assumes that:
representatives[0]: Codes the SVC hyperparameters (C and gamma). Thus, it is an instance of
culebra.solution.parameter_optimization.Solution
representatives[1:]: The remaining solutions code the features selected, each solution a different range of features. All of them are instances of
culebra.solution.feature_selection.Solution
- Parameters:
- Returns:
The solutions to the different problems solved cooperatively
- Return type:
tuple
of py:class:culebra.abc.Solution