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)

Create a new species.

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

  • min_feat (int, optional) – 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, optional) – 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, optional) – 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, optional) – 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.num_feats: int

Get the number of features for this species.

Type:

int

property Species.min_feat: int

Get the minimum feature index for this species.

Type:

int

property Species.max_feat: int

Get the maximum feature index for this species.

Type:

int

property Species.min_size: int

Get the minimum subset size for this species.

Type:

int

property Species.max_size: int

Get the maximum subset size for this species.

Type:

int

Class methods

classmethod Species.load_pickle(filename: str) Base

Load a pickled object from a file.

Parameters:

filename (str) – The file name.

Raises:
classmethod Species.from_proportion(num_feats: int, prop: float = 0.15) 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, optional) – Proportion of the number of features used to fix the species parameters. Defaults to DEFAULT_PROP. The maximum allowed value is MAX_PROP.

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

Methods

Species.save_pickle(filename: str) None

Pickle 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