pygx.algo.evolution¶
Compositional evolutionary algorithms.
evolution
¶
Compositional evolutionary algorithms.
pygx.algo.evolution builds search algorithms from small, composable
operations: selectors choose individuals, mutators perturb them,
recombinators combine them, and pipelines connect them with the >> operator.
The top-level Evolution class wires reproduction, population initialization,
population updates, and stopping criteria into a single DNAGenerator that
plugs into pg.sample,
pg.iter, or any other consumer.
Common algorithm constructors are exposed at this level:
Each takes a Mutator (defaulting to mutators.Uniform()) and returns a
ready-to-use Evolution object.
hill_climb
¶
hill_climb(
mutator: Mutator = Uniform(),
batch_size: int = 1,
init_population_size: int = 1,
seed: int | None = None,
) -> Evolution
Hill-Climbing algorithm, with an extra batched setting.
Batched setting was shown to be effective in https://arxiv.org/pdf/1911.06317.pdf and https://arxiv.org/pdf/2003.01239.pdf, especially in noisy objective settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mutator
|
Mutator
|
Mutator to use. |
Uniform()
|
batch_size
|
int
|
Number of mutations of the current best. |
1
|
init_population_size
|
int
|
Initial population size (randomly generated). |
1
|
seed
|
int | None
|
Random seed. |
None
|
Returns:
| Type | Description |
|---|---|
Evolution
|
An |
Source code in pygx/algo/evolution/_hill_climb.py
neat
¶
neat(
mutator: Mutator = Uniform(),
population_size: int = 100,
disjoint_coefficient: float = 1.0,
matching_coefficient: float = 3.0,
compatibility_threshold: float = 0.4,
remaining_ratio: float = 0.6,
seed: int | None = None,
) -> Evolution
NEAT Algorithm.
See http://nn.cs.utexas.edu/downloads/papers/stanley.cec02.pdf for the original paper.
NOTE(daiyip): PyGX supports search spaces that do not change during exploration. Therefore we do not grow the program (e.g. Neural Architecture in the paper) from a minimal program. Also, crossover can take place on any two individuals due to a fixed program structure, which will be implemented later. This algorithm illustrates how speciation is expressed in the compositional evolution framework.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mutator
|
Mutator
|
Mutator to use. |
Uniform()
|
population_size
|
int
|
Population size for each generation. |
100
|
disjoint_coefficient
|
float
|
Coefficient for DNA disjointness. Used for distance computations. |
1.0
|
matching_coefficient
|
float
|
Coefficient for DNA matching. Used for distance computations. |
3.0
|
compatibility_threshold
|
float
|
Threshold for max distances between two DNA in the same species. |
0.4
|
remaining_ratio
|
float
|
Ratio of best individuals in a species to remain. |
0.6
|
seed
|
int | None
|
Random seed. If None, use the current system time. |
None
|
Returns:
| Type | Description |
|---|---|
Evolution
|
An |
Source code in pygx/algo/evolution/_neat.py
nsga2
¶
nsga2(
mutator: Mutator = Uniform(),
population_size: int = 100,
seed: int | None = None,
) -> Evolution
NSGA-II: A multi-objective evolutionary search algorithm.
For reference and for citations, please use: https://ieeexplore.ieee.org/document/996017
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mutator
|
Mutator
|
Mutator to use. |
Uniform()
|
population_size
|
int
|
Population size, which will be used as both batch size for proposing new individuals and tourament size for finding the elites among recently added populations. |
100
|
seed
|
int | None
|
Random seed for initializing the population. If None, the system time will be used. |
None
|
Returns:
| Type | Description |
|---|---|
Evolution
|
An |
Source code in pygx/algo/evolution/_nsga2.py
regularized_evolution
¶
regularized_evolution(
mutator: Mutator = Uniform(),
population_size: int = 100,
tournament_size: int = 10,
seed: int | None = None,
) -> Evolution
Regularized Evolution algorithm.
https://www.aaai.org/ojs/index.php/AAAI/article/view/4405.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mutator
|
Mutator
|
Mutator to use. |
Uniform()
|
population_size
|
int
|
Population size. Must be larger than tournament size. |
100
|
tournament_size
|
int
|
Tournament size. |
10
|
seed
|
int | None
|
Random seed. If None, the current system time is used as seed. |
None
|
Returns:
| Type | Description |
|---|---|
Evolution
|
An |
Source code in pygx/algo/evolution/_regularized_evolution.py
options: show_root_heading: false show_root_toc_entry: false members_order: source heading_level: 2