culebra.solution.feature_selection.BitVector
class¶
- class BitVector(species: Species, fitness_cls: Type[Fitness], features: Sequence[int] | None = None)¶
Construct a default solution.
Class attributes¶
Class methods¶
- classmethod BitVector.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 BitVector.fitness: Fitness¶
Get and set the solution’s fitness.
- Getter:
Return the current fitness
- Setter:
Set a new Fitness
- Type:
- property BitVector.features: Sequence[int]¶
Get and set the indices of the features selected by the solution.
- 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:
ValueError – If set to new feature indices values which do not meet the species constraints.
Methods¶
- BitVector.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
- BitVector.crossover1p(other: BitVector) Tuple[BitVector, BitVector] ¶
Cross this individual with another one.
This method implements the single-point crossover.
- BitVector.crossover2p(other: BitVector) Tuple[BitVector, BitVector] ¶
Cross this individual with another one.
This method implements the two-points crossover.
- BitVector.crossover(other: BitVector) Tuple[BitVector, BitVector] ¶
Default crossover operator.
Implemented as the single-point crossover.
- BitVector.mutate(indpb: float) Tuple[BitVector] ¶
Mutate the individual.
Each feature is independently mutated according to the given probability.
Private methods¶
Dunder methods¶
- BitVector.__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.