culebra.fitness_function.feature_selection.NumFeats
class¶
- class NumFeats¶
Dummy single-objective fitness function for testing purposes.
Return the number of selected features by a solution.
Class attributes¶
- class culebra.fitness_function.feature_selection.NumFeats.Fitness¶
Handles the values returned by the
evaluate()
method within aSolution
.- Fitness.weights = (-1.0,)¶
Minimize the number of features that a solution has selected.
- Fitness.names = ('NF',)¶
Name of the objective.
- Fitness.thresholds = [0]¶
Similarity threshold for fitness comparisons.
Class methods¶
- classmethod NumFeats.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 NumFeats.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 NumFeats.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 NumFeats.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¶
- NumFeats.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
- NumFeats.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
- NumFeats.evaluate(sol: Solution, index: int | None = None, representatives: Sequence[Solution] | None = None) Tuple[float, ...] ¶
Evaluate a solution.
- Parameters:
sol (
Solution
) – Solution to be evaluated.index (
int
, ignored) – Index where sol should be inserted in the representatives sequence to form a complete solution for the problem. Only used by cooperative problemsrepresentatives (
Sequence
ofSolution
, ignored) – Representative solutions of each species being optimized. Only used by cooperative problems
- Returns:
The fitness of sol
- Return type: