Skip to content

select

SelectDefault

select(self, *, population, population_fitness, n, method='roulette', **kwargs)

Select individuals in population using specified method.

Parameters:

Name Type Description Default
population ndarray

the population to mutate. Shape is n_individuals x n_chromosomes.

required
population_fitness ndarray

the population fitness. Is a 1D array same length as population.

required
n int

total number of individuals to select

required
method str

'roulette', 'su', 'scaled'; default 'roulette'

'roulette'
**kwargs

keyword arguments for plugins

{}

Returns:

Type Description
ndarray

np.ndarray: selected population

Source code in pangadfs/select.py
def select(self, 
           *, 
           population: np.ndarray, 
           population_fitness: np.ndarray,
           n: int,
           method: str = 'roulette',
           **kwargs) -> np.ndarray:
    """Select individuals in population using specified method.

    Args:
        population (np.ndarray): the population to mutate. Shape is n_individuals x n_chromosomes.
        population_fitness (np.ndarray): the population fitness. Is a 1D array same length as population.
        n (int): total number of individuals to select
        method (str): 'roulette', 'su', 'scaled'; default 'roulette'
        **kwargs: keyword arguments for plugins

    Returns:
        np.ndarray: selected population

    """
    dispatch = {
        'roulette': self._roulette_wheel,
        'sus': self._sus,
        'rank': self._rank,
        'tournament': self._tournament,
        'scaled': self._scaled,
        'fittest': self._fittest
    }        

    params = {
        'population': population,
        'population_fitness': population_fitness,
        'n': n
    }

    return dispatch.get(method, self._roulette_wheel)(**params, **kwargs)