crossover
CrossoverDefault
¶
crossover(self, *, population, method='uniform', **kwargs)
¶
Crossover individuals in population.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
population |
ndarray |
the population to crossover. Shape is n_individuals x n_chromosomes. |
required |
method |
str |
crossover method, 'uniform', 'diverse', 'one_point', or 'two_point'. |
'uniform' |
**kwargs |
|
Arbitrary keyword arguments |
{} |
Returns:
Type | Description |
---|---|
ndarray |
np.ndarray: concatenation of two offspring |
Source code in pangadfs/crossover.py
def crossover(self, *, population: np.ndarray, method: str = 'uniform', **kwargs) -> np.ndarray:
"""Crossover individuals in population.
Args:
population (np.ndarray): the population to crossover. Shape is n_individuals x n_chromosomes.
method (str): crossover method, 'uniform', 'diverse', 'one_point', or 'two_point'.
**kwargs: Arbitrary keyword arguments
Returns:
np.ndarray: concatenation of two offspring
"""
dispatch = {
'uniform': self._uniform,
'diverse': self._diverse,
'one_point': self._one_point,
'two_point': self._two_point
}
return dispatch.get(method, self._uniform)(population=population, **kwargs)