culebra.solution.feature_selection.IntVector class

class IntVector(species: Species, fitness_cls: Type[Fitness], features: Sequence[int] | None = None)

Construct a default solution.

Parameters:
  • species (species_cls) – The species the solution will belong to

  • fitness (Fitness) – The solution’s fitness class

  • features (Sequence of int) – Initial features

Raises:
  • TypeError – If species is not a valid species

  • TypeError – If fitness_cls is not a valid fitness class

Class attributes

IntVector.species_cls = <class 'culebra.solution.feature_selection.Species'>

Class for the species used by the Solution class to constrain all its instances.

Class methods

classmethod IntVector.load_pickle(filename: str) Base

Load a pickled object from a file.

Parameters:

filename (str) – The file name.

Raises:

Properties

property IntVector.species: Species

Get the solution’s species.

Returns:

The species

Return type:

Species

property IntVector.fitness: Fitness

Get and set the solution’s fitness.

Getter:

Return the current fitness

Setter:

Set a new Fitness

Type:

Fitness

property IntVector.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:

numpy.ndarray

Raises:

ValueError – If set to new feature indices values which do not meet the species constraints.

property IntVector.num_feats: int

Get the number of features selected by the solution.

Type:

int

property IntVector.min_feat: int | None

Minimum feature index selected by the solution.

Type:

int or None if no feature has been selected

property IntVector.max_feat: int | None

Maximum feature index selected by the solution.

Type:

int or None if no feature has been selected

Methods

IntVector.save_pickle(filename: str) None

Pickle this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
IntVector.crossover(other: IntVector) Tuple[IntVector, IntVector]

Cross this individual with another one.

All the common features will remain common in the new offspring. The remaining features will be randomly distributed to generate two new individuals.

Parameters:

other (IntVector) – The other individual

Returns:

The two offspring

Return type:

tuple

IntVector.mutate(indpb: float) Tuple[IntVector]

Mutate the individual.

Each feature is independently mutated according to the given probability.

Parameters:

indpb (float) – Independent probability for each feature to be mutated.

Returns:

The mutant

Return type:

tuple

IntVector.dominates(other: Solution) bool

Dominate operator.

Parameters:

other (Solution) – Other solution

Returns:

True if each objective of the solution is not strictly worse than the corresponding objective of other and at least one objective is strictly better.

Return type:

bool

IntVector.delete_fitness() None

Delete the solution’s fitness.

Private methods

IntVector._setup() None

Init the features of this solution randomly.

Dunder methods

IntVector.__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.

IntVector.__eq__(other: Solution) bool

Equality test.

Parameters:

other (Solution) – Other solution

Returns:

True if other codes the same solution, or False otherwise

Return type:

bool

IntVector.__ne__(other: Solution) bool

Not equality test.

Parameters:

other (Solution) – Other solution

Returns:

False if other codes the same solutions, or True otherwise

Return type:

bool

IntVector.__lt__(other: Solution) bool

Less than operator.

Parameters:

other (Solution) – Other solution

Returns:

True if the solution’s fitness is less than the other’s fitness

Return type:

bool

IntVector.__gt__(other: Solution) bool

Greater than operator.

Parameters:

other (Solution) – Other solution

Returns:

True if the solution’s fitness is greater than the other’s fitness

Return type:

bool

IntVector.__le__(other: Solution) bool

Less than or equal to operator.

Parameters:

other (Solution) – Other solution

Returns:

True if the solution’s fitness is less than or equal to the other’s fitness

Return type:

bool

IntVector.__ge__(other: Solution) bool

Greater than or equal to operator.

Parameters:

other (Solution) – Other solution

Returns:

True if the solution’s fitness is greater than or equal to the other’s fitness

Return type:

bool

IntVector.__str__() str

Return the solution as a string.