public class RankSelection extends Object implements SelectionStrategy<Object>
A selection strategy that is similar to fitness-proportionate selection except that is uses relative fitness rather than absolute fitness in order to determine the probability of selection for a given individual (i.e. the actual numerical fitness values are ignored and only the ordering of the sorted population is considered).
Rank selection is implemented in terms of a mapping function (mapRankToScore(int, int)
) and delegation to a fitness-proportionate selector. The
mapping function converts ranks into relative fitness scores that are used to
drive the delegate selector.
Constructor and Description |
---|
RankSelection()
Creates a default rank-based selector with a linear
mapping function and selection frequencies that correspond
to expected values.
|
RankSelection(SelectionStrategy<Object> delegate)
Creates a rank-based selector with a linear mapping function and
configurable delegate for performing the proportionate selection.
|
Modifier and Type | Method and Description |
---|---|
protected double |
mapRankToScore(int rank,
int populationSize)
Maps a population index to a relative pseudo-fitness score that can be used for
fitness-proportionate selection.
|
<S> List<S> |
select(List<EvaluatedCandidate<S>> population,
boolean naturalFitnessScores,
int selectionSize,
Random rng)
Select the specified number of candidates from the population.
|
String |
toString() |
public RankSelection()
public RankSelection(SelectionStrategy<Object> delegate)
delegate
- The proportionate selector that will be delegated
to after converting rankings into relative fitness scores.public <S> List<S> select(List<EvaluatedCandidate<S>> population, boolean naturalFitnessScores, int selectionSize, Random rng)
Select the specified number of candidates from the population. Implementations may assume that the population is sorted in descending order according to fitness (so the fittest individual is the first item in the list).
It is an error to call this method with an empty or null population.
select
in interface SelectionStrategy<Object>
S
- The type of evolved entity that we are selecting, a sub-type of T.population
- The population from which to select.naturalFitnessScores
- Whether higher fitness values represent fitter
individuals or not.selectionSize
- The number of individual selections to make (not necessarily
the number of distinct candidates to select, since the same individual may
potentially be selected more than once).rng
- Source of randomness for stochastic selection strategies.protected double mapRankToScore(int rank, int populationSize)
Maps a population index to a relative pseudo-fitness score that can be used for
fitness-proportionate selection. The general contract for the mapping function
f
is: f(rank) >= f(rank + 1)
for all legal values of
rank
, assuming natural scores.
The default mapping function is a simple linear transformation, but this can be over-ridden in sub-classes. Alternative implementations can be linear or non-linear and either natural or non-natural.
rank
- A zero-based index into the population
(0 <= rank < populationSize)
.populationSize
- The number of individuals in the population.populationSize - rank