culebra.solution.feature_selection.Solution class¶
- class Solution(species: Species, fitness_cls: type[Fitness], features: Sequence[int] | None = None)¶
Bases:
SolutionConstruct a default solution.
Class attributes¶
Class methods¶
- classmethod Solution.load(filename: str) Base¶
Load a serialized object from a file.
- Parameters:
filename (str) – The file name.
- Returns:
The loaded object
- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
SERIALIZED_FILE_EXTENSION
Properties¶
- abstract property Solution.features: ndarray[int]¶
Features selected by the solution
This property must be overridden by subclasses to return a correct value.
- Returns:
Return an ordered sequence with the indices of the selected features
- Return type:
- Setter:
Set a new set of selected features
- Parameters:
- Raises:
ValueError – If set to new feature indices values which do not meet the species constraints.
NotImplementedError – If has not been overridden
- abstract property Solution.max_feat: int | None¶
Maximum feature index selected by the solution.
This property must be overridden by subclasses to return a correct value.
- Returns:
The maximum feature index or
Noneif no feature has been selected- Return type:
- Raises:
NotImplementedError – If has not been overridden
- abstract property Solution.min_feat: int | None¶
Minimum feature index selected by the solution.
This property must be overridden by subclasses to return a correct value.
- Returns:
The minimum feature index or
Noneif no feature has been selected- Return type:
- Raises:
NotImplementedError – If has not been overridden
- abstract property Solution.num_feats: int¶
Number of features selected by the solution.
This property must be overridden by subclasses to return a correct value.
- Return type:
- Raises:
NotImplementedError – If has not been overridden
Methods¶
- Solution.dump(filename: str) None¶
Serialize 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
SERIALIZED_FILE_EXTENSION
Private methods¶
- abstract Solution._setup() None¶
Init the features of this solution randomly.
This method must be overridden by subclasses.
- Raises:
NotImplementedError – If has not been overridden
Dunder methods¶
Intended to compare (lexicographically) two solutions according to their fitness.
- Solution.__hash__() int¶
Return the hash number for this solution.
The hash number is used for equality comparisons. Currently is implemented as the hash of the solution’s string representation.
- Return type:

