culebra.solution.parameter_optimization.Individual
class¶
- class Individual(species: Species, fitness_cls: Type[Fitness], values: Sequence[int | float] | None = None)¶
Construct a default solution.
- Parameters:
species (
species_cls
) – The species the solution will belong tofitness (
Fitness
) – The solution’s fitness classvalues (
Sequence
ofint
orfloat
values, optional) – Initial values
- Raises:
Class attributes¶
- Individual.species_cls = <class 'culebra.solution.parameter_optimization.Species'>¶
Class for the species used by the
Solution
class to constrain all its instances.
- Individual.eta = 5¶
Default value for eta, which controls the probability distribution used in SBX and polynomial mutation.
Class methods¶
- classmethod Individual.load_pickle(filename: str) Base ¶
Load a pickled object from 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
PICKLE_FILE_EXTENSION
Properties¶
- property Individual.fitness: Fitness¶
Get and set the solution’s fitness.
- Getter:
Return the current fitness
- Setter:
Set a new Fitness
- Type:
- property Individual.named_values_cls: Type[NamedTuple]¶
Return the named tuple class to hold the parameter values.
- property Individual.values: NamedTuple[int | float, ...]¶
Get and set the parameter values evolved by the solution.
- Getter:
Return the parameter values
- Setter:
Set the new parameter values.
- Type:
- Raises:
ValueError – If set to new parameter values which do not meet the species constraints.
Methods¶
- Individual.save_pickle(filename: str) None ¶
Pickle 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
PICKLE_FILE_EXTENSION
- 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.mutate(indpb: float) Tuple[Individual] ¶
Mutate the individual.
Polynimial mutation is used.
Private methods¶
Dunder methods¶
- 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.