culebra.solution.feature_selection.Solution
class¶
- class Solution(species: Species, fitness_cls: Type[Fitness], features: Sequence[int] | None = None)¶
Construct a default solution.
Class attributes¶
Class methods¶
- classmethod Solution.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
Properties¶
- property Solution.fitness: Fitness¶
Get and set the solution’s fitness.
- Getter:
Return the current fitness
- Setter:
Set a new Fitness
- Type:
- abstract property Solution.features: Sequence[int]¶
Get and set the indices of the features selected by the solution.
This property must be overridden by subclasses to return a correct value.
- Getter:
Return an ordered sequence with the indices of the selected features.
- Setter:
Set the new feature indices. An array-like object of feature indices is expected
- Type:
- Raises:
NotImplementedError – if has not been overridden
- abstract property Solution.num_feats: int¶
Get the number of features selected by the solution.
This property must be overridden by subclasses to return a correct value.
- Raises:
NotImplementedError – if has not been overridden
- Type:
- 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.
- Raises:
NotImplementedError – if has not been overridden
- Type:
Methods¶
- Solution.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
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¶
- 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.