culebra.solution.feature_selection.Ant
class¶
- class Ant(species: Species, fitness_cls: Type[Fitness], features: Sequence[int] | None = None)¶
Construct a default solution.
Class attributes¶
Class methods¶
- classmethod Ant.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 Ant.fitness: Fitness¶
Get and set the solution’s fitness.
- Getter:
Return the current fitness
- Setter:
Set a new Fitness
- Type:
- property Ant.features: Sequence[int]¶
Get and set the features path traveled by the ant.
- Getter:
Return an ordered sequence with the indices of the selected features. Use
path
to get the path in the order the ant traveled it- Setter:
Set a new path. An array-like object of feature indices is expected
- Type:
- Raises:
ValueError – If any feature in the path does not meet the species constraints.
Methods¶
- Ant.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
- Ant.append(feature: int) None ¶
Append a new feature to the ant’s path.
- Raises:
TypeError – If feature is not an integer number
ValueError – If feature does not meet the species constraints.
ValueError – If feature is already in the path or has been previously discarded
- Ant.discard(feature: int) None ¶
Discard a feature.
The discarded feature is not appended to the ant’s path.
- Raises:
TypeError – If feature is not an integer number
ValueError – If feature is already in the path or has been previously discarded
Private methods¶
Dunder methods¶
- Ant.__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.