culebra.solution.feature_selection.Ant class¶
- class Ant(species: Species, fitness_cls: type[Fitness], features: Sequence[int] | None = None)¶
Bases:
IntSolution,AntConstruct a default solution.
Class attributes¶
Class methods¶
- classmethod Ant.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¶
- property Ant.features: ndarray[int]¶
Features selected by the ant
- Returns:
Return an ordered sequence with the indices of the selected features. Use
pathto get the path in the order the ant traveled it- 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.
Methods¶
- Ant.append(feature: int) None¶
Append a new feature to the ant’s path.
- Parameters:
feature (int) – The feature index
- 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.
- Parameters:
feature (int) – The feature index
- Raises:
TypeError – If feature is not an integer number
ValueError – If feature is already in the path or has been previously discarded
- Ant.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¶
Dunder methods¶
Intended to compare (lexicographically) two ants according to their fitness.
- 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.
- Return type:

