culebra.fitness_func.feature_selection.NumFeats class

class NumFeats(index: int | None = None)

Bases: FSScorer

Construct the fitness function.

Parameters:

index (int) – Index of this objective when it is used for multi-objective fitness functions, optional

Raises:

Class methods

classmethod NumFeats.load(filename: str) Base

Load a serialized object from a file.

Parameters:

filename (str) – The file name.

Returns:

The loaded object

Raises:

Properties

property NumFeats.fitness_cls: type[Fitness]

Fitness class.

Return type:

type[Fitness]

property NumFeats.index: int

Objective index.

Return type:

int

Setter:

Set a new index

Parameters:

value (int) – The new index. If set to None, _default_index is chosen

Raises:
property NumFeats.num_obj: int

Number of objectives.

Return type:

int

property NumFeats.obj_names: tuple[str, ...]

Objective names.

Returns:

(“NF”,)

Return type:

tuple[str]

property NumFeats.obj_thresholds: tuple[float]

Objective similarity thresholds.

Return type:

tuple[float]

Setter:

Set new thresholds.

Parameters:

values (float | Sequence[float]) – The new values. If only a single value is provided, the same threshold will be used for all the objectives. Different thresholds can be provided in a Sequence. If set to None, all the thresholds are set to _default_similarity_threshold

Raises:
  • TypeError – If neither a real number nor a Sequence of real numbers is provided

  • ValueError – If any value is negative

  • ValueError – If the length of the thresholds sequence does not match the number of objectives

property NumFeats.obj_weights: tuple[int, ...]

Objective weights.

Minimize the number of features that a solution has selected.

Returns:

(-1, )

Return type:

tuple[int]

property NumFeats.objectives: tuple[SingleObjectiveFitnessFunction]

Objectives to be optimized.

Return type:

tuple[SingleObjectiveFitnessFunction]

Private properties

property NumFeats._default_index: int

Default index.

Returns:

DEFAULT_INDEX

Return type:

int

property NumFeats._default_similarity_threshold: float

Default similarity threshold for fitnesses.

Returns:

DEFAULT_SIMILARITY_THRESHOLD

Return type:

float

Methods

NumFeats.dump(filename: str) None

Serialize this object and save it to a file.

Parameters:

filename (str) – The file name.

Raises:
NumFeats.evaluate(sol: Solution, index: int | None = None, cooperators: Sequence[Solution | None] | None = None) tuple[float, ...]

Evaluate a solution.

Neither the solution nor its fitness should be modified.

Parameters:
  • sol (Solution) – Solution to be evaluated.

  • index (int) – Index where sol should be inserted in the cooperators sequence to form a complete solution for the problem. Only used by cooperative problems

  • cooperators (Sequence[Solution]) – Cooperators of each species being optimized. Only used by cooperative problems

Returns:

The fitness values for sol

Return type:

tuple[float, …]

Raises:

ValueError – If sol is not evaluable

NumFeats.is_evaluable(sol: Solution) bool

Assess the evaluability of a solution.

Parameters:

sol (Solution) – Solution to be evaluated.

Returns:

True if the solution can be evaluated

Return type:

bool

Raises:

NotImplementedError – If has not been overridden

Private methods

NumFeats._get_repr_properties() dict[str, object]

Return the subset of properties used for __repr__.

Filters and evaluates all class-level @property attributes, returning only those intended for representation purposes. Private properties (names starting with _) are excluded.

Returns:

Mapping of property names to their corresponding values.

Return type:

dict[str, object]