culebra.solution.feature_selection.Species class

class Species(num_feats: int, min_feat: int | None = None, min_size: int | None = None, max_feat: int | None = None, max_size: int | None = None)

Bases: Species

Create a new species.

Parameters:
  • num_feats (int) – Number of input features considered in the feature selection problem

  • min_feat (int) – Smallest feature index considered in this species. Must be in the interval [0, num_feats). If omitted, the minimum value (0) will be used. Defaults to None

  • min_size (int) – Minimum size of solutions (minimum number of features selected by solutions in the species). Must be in the interval [0, max_feat - min_feat + 1]. If omitted, the minimum value (0) will be used. Defaults to None

  • max_feat (int) – Largest feature index considered in this species. Must be in the interval [min_feat, num_feats). If omitted, the maximum possible feature index (num_feats - 1) will be used. Defaults to None

  • max_size (int) – Maximum size of solutions. Must be in the interval [min_size, max_feat - min_feat + 1]. If omitted, the maximum possible size is used. Defaults to None

Raises:
  • TypeError – If any argument is not of the appropriate type

  • ValueError – If any argument has an incorrect value

Properties

property Species.max_feat: int

Maximum feature index for this species.

Return type:

int

property Species.max_size: int

Maximum subset size for this species.

Return type:

int

property Species.min_feat: int

Minimum feature index for this species.

Return type:

int

property Species.min_size: int

Minimum subset size for this species.

Return type:

int

property Species.num_feats: int

Number of features for this species.

Return type:

int

Class methods

classmethod Species.from_proportion(num_feats: int, prop: float | None = None) Species

Create a parametrized species for testing purposes.

Fix min_feat, max_feat, min_size and max_size proportionally to the number of features, according to prop, in this way:

  • min_feat = num_feats * prop

  • max_feat = num_feats - min_feat - 1

  • min_size = min_feat

  • max_size = max_feat - (2 * min_feat) + 1

Here are some examples for num_feats = 1000

prop

min_feat

max_feat

min_size

max_size

0.00

0

999

0

1000

0.05

50

949

50

850

0.10

100

899

100

700

0.15

150

849

150

550

0.20

200

799

200

400

0.25

250

749

250

250

The maximum value for prop is MAX_PROP.

Parameters:
  • num_feats (int) – Number of input features considered in the feature selection problem

  • prop (float) – Proportion of the number of features used to fix the species parameters. If omitted, the default proportion (DEFAULT_PROP) is used

Raises:
  • TypeError – If any argument is not of the appropriate type

  • ValueError – If any argument has an incorrect value

Returns:

A Species object

Return type:

Species

classmethod Species.load(filename: str) Base

Load a serialized object from a file.

Parameters:

filename (str) – The file name.

Returns:

The loaded object

Raises:

Methods

Species.dump(filename: str) None

Serialize this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
Species.is_member(sol: Solution) bool

Check if a solution meets the constraints imposed by the species.

Parameters:

sol (Solution) – The solution

Returns:

True if the solution belongs to the species. False otherwise

Return type:

bool