Selection¶
Selection operators for evolutionary algorithms.
Selection¶
Bases: ABC, Generic[G]
Abstract base class for selection operators.
Source code in src/rotalabs_redqueen/core/selection.py
select(population: Population[G], n: int, rng: np.random.Generator | None = None) -> list[Individual[G]]
abstractmethod
¶
Select N individuals from the population.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
population
|
Population[G]
|
Population to select from |
required |
n
|
int
|
Number of individuals to select |
required |
rng
|
Generator | None
|
Random number generator |
None
|
Returns:
| Type | Description |
|---|---|
list[Individual[G]]
|
List of selected individuals |
Source code in src/rotalabs_redqueen/core/selection.py
TournamentSelection¶
Bases: Selection[G], Generic[G]
Tournament selection operator.
Selects individuals by running tournaments where the best of a random subset wins.
Source code in src/rotalabs_redqueen/core/selection.py
__init__(tournament_size: int = 3)
¶
Initialize tournament selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tournament_size
|
int
|
Number of individuals per tournament |
3
|
select(population: Population[G], n: int, rng: np.random.Generator | None = None) -> list[Individual[G]]
¶
Select N individuals via tournament.
Source code in src/rotalabs_redqueen/core/selection.py
NoveltySelection¶
Bases: Selection[G], Generic[G]
Selection based purely on novelty.
Selects individuals with the most novel behaviors.
Source code in src/rotalabs_redqueen/core/selection.py
__init__(archive: NoveltyArchive[G] | None = None, k_nearest: int = 15)
¶
Initialize novelty selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
NoveltyArchive[G] | None
|
Shared novelty archive (or creates new one) |
None
|
k_nearest
|
int
|
Number of neighbors for novelty computation |
15
|
Source code in src/rotalabs_redqueen/core/selection.py
select(population: Population[G], n: int, rng: np.random.Generator | None = None) -> list[Individual[G]]
¶
Select N most novel individuals.
Source code in src/rotalabs_redqueen/core/selection.py
NoveltyFitnessSelection¶
Bases: Selection[G], Generic[G]
Combined novelty and fitness selection.
Balances exploration (novelty) and exploitation (fitness).
Source code in src/rotalabs_redqueen/core/selection.py
__init__(archive: NoveltyArchive[G] | None = None, novelty_weight: float = 0.5, k_nearest: int = 15)
¶
Initialize combined selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive
|
NoveltyArchive[G] | None
|
Shared novelty archive |
None
|
novelty_weight
|
float
|
Weight for novelty (0-1, rest goes to fitness) |
0.5
|
k_nearest
|
int
|
Number of neighbors for novelty |
15
|
Source code in src/rotalabs_redqueen/core/selection.py
select(population: Population[G], n: int, rng: np.random.Generator | None = None) -> list[Individual[G]]
¶
Select based on combined novelty and fitness score.
Source code in src/rotalabs_redqueen/core/selection.py
NoveltyArchive¶
Bases: Generic[G]
Archive for novelty search.
Tracks explored behaviors to compute novelty scores.
Source code in src/rotalabs_redqueen/core/selection.py
add(behavior: BehaviorDescriptor) -> None
¶
Add a behavior to the archive.
Only adds if sufficiently novel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
behavior
|
BehaviorDescriptor
|
Behavior descriptor to potentially add |
required |
Source code in src/rotalabs_redqueen/core/selection.py
compute_novelty(behavior: BehaviorDescriptor) -> float
¶
Compute novelty score for a behavior.
Novelty is the average distance to k-nearest neighbors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
behavior
|
BehaviorDescriptor
|
Behavior to score |
required |
Returns:
| Type | Description |
|---|---|
float
|
Novelty score (higher = more novel) |