culebra.solution.parameter_optimization.Individual class¶
- class Individual(species: Species, fitness_cls: type[Fitness], values: Sequence[int | float] | None = None)¶
Bases:
Solution,IndividualConstruct a default solution.
Class attributes¶
- Individual.eta = 5¶
Default value for eta, which controls the probability distribution used in SBX and polynomial mutation.
Class methods¶
- classmethod Individual.load(filename: str) Base¶
Load a serialized object from a file.
- Parameters:
filename (str) – The file name.
- Returns:
The loaded object
- Raises:
TypeError – If filename is not a valid file name
ValueError – If the filename extension is not
SERIALIZED_FILE_EXTENSION
Properties¶
- property Individual.named_values_cls: type[NamedTuple]¶
Named tuple class to hold the parameter values.
- Return type:
- property Individual.values: NamedTuple[int | float, ...]¶
Parameter values evolved by the solution.
- Return type:
- Setter:
Set new parameter values.
- Parameters:
- Raises:
ValueError – If the values do not meet the species constraints
Methods¶
- Individual.crossover(other: Individual) tuple[Individual, Individual]¶
Cross this individual with another one.
SBX is used.
- Parameters:
other (Individual) – The other individual
- Returns:
The two offspring
- Return type:
- Individual.dump(filename: str) None¶
Serialize 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
SERIALIZED_FILE_EXTENSION
- Individual.mutate(indpb: float) tuple[Individual]¶
Mutate the individual.
Polynomial mutation is used.
- Parameters:
indpb (float) – Independent probability for each parameter to be mutated.
- Returns:
The mutant
- Return type:
Private methods¶
Dunder methods¶
Intended to compare (lexicographically) two individuals according to their fitness.
- Individual.__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.
- Return type:

