vectorized
This commit is contained in:
29
lab4/gp/utils.py
Normal file
29
lab4/gp/utils.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from typing import Sequence
|
||||
|
||||
from .chromosome import Chromosome
|
||||
from .primitive import Primitive
|
||||
from .types import Population
|
||||
|
||||
|
||||
def ramped_initialization(
|
||||
chromosomes_per_variation: int,
|
||||
depths: list[int],
|
||||
terminals: Sequence[Primitive],
|
||||
operations: Sequence[Primitive],
|
||||
) -> Population:
|
||||
"""Комбинация методов grow и full инициализации хромосом для инициализации начальной
|
||||
популяции.
|
||||
"""
|
||||
population: Population = []
|
||||
|
||||
for depth in depths:
|
||||
population.extend(
|
||||
Chromosome.full_init(terminals, operations, depth)
|
||||
for _ in range(chromosomes_per_variation)
|
||||
)
|
||||
population.extend(
|
||||
Chromosome.grow_init(terminals, operations, depth)
|
||||
for _ in range(chromosomes_per_variation)
|
||||
)
|
||||
|
||||
return population
|
||||
Reference in New Issue
Block a user