Вынес методы инициализации из хромосомы
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
from gp import Chromosome, Terminal, ops
|
||||
from gp.chromosome import init_grow
|
||||
from gp.population import ramped_initialization
|
||||
|
||||
operations = ops.ALL
|
||||
|
||||
terminals = [Terminal(f"x{i}") for i in range(1, 9)]
|
||||
|
||||
chrom = Chromosome(operations, terminals, 8, "grow")
|
||||
print("Depth:", chrom.depth)
|
||||
chrom = Chromosome(operations, terminals, init_func=lambda c: init_grow(c, 8))
|
||||
print("Depth:", chrom.get_depth())
|
||||
print("Formula:", chrom)
|
||||
print("Tree:\n", chrom.str_tree())
|
||||
|
||||
@@ -16,7 +17,7 @@ print("Value for ", values, ":", chrom.eval(values))
|
||||
population = ramped_initialization(
|
||||
100,
|
||||
[3, 4, 5, 6, 7, 8],
|
||||
lambda depth, method: Chromosome(operations, terminals, depth, method),
|
||||
lambda init_func: Chromosome(operations, terminals, init_func),
|
||||
)
|
||||
print("Population size:", len(population))
|
||||
print("Population:")
|
||||
|
||||
Reference in New Issue
Block a user