another save
This commit is contained in:
33
lab4/main.py
33
lab4/main.py
@@ -1,24 +1,25 @@
|
||||
from gp import Chromosome, Terminal, ops
|
||||
from gp.chromosome import init_grow
|
||||
from gp import Chromosome, ops
|
||||
from gp.population import ramped_initialization
|
||||
from gp.primitive import Var
|
||||
|
||||
operations = ops.ALL
|
||||
terminals = [Var(f"x{i}") for i in range(1, 9)]
|
||||
|
||||
terminals = [Terminal(f"x{i}") for i in range(1, 9)]
|
||||
|
||||
chrom = Chromosome(operations, terminals, init_func=lambda c: init_grow(c, 8))
|
||||
print("Depth:", chrom.get_depth())
|
||||
chrom = Chromosome.full_init(terminals, operations, max_depth=3)
|
||||
print("Depth:", chrom.root.get_subtree_depth())
|
||||
print("Formula:", chrom)
|
||||
print("Tree:\n", chrom.str_tree())
|
||||
print("Tree:\n", chrom.root.to_str_tree())
|
||||
|
||||
values = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
|
||||
print("Value for ", values, ":", chrom.eval(values))
|
||||
context = {var: value for var, value in zip(terminals, values)}
|
||||
print("Value for ", values, ":", chrom.root.eval(context))
|
||||
|
||||
population = ramped_initialization(
|
||||
100,
|
||||
[3, 4, 5, 6, 7, 8],
|
||||
lambda init_func: Chromosome(operations, terminals, init_func),
|
||||
)
|
||||
print("Population size:", len(population))
|
||||
print("Population:")
|
||||
[print(str(chrom)) for chrom in population]
|
||||
# population = ramped_initialization(
|
||||
# 5,
|
||||
# [3, 4, 5, 6, 7, 8],
|
||||
# terminals,
|
||||
# operations,
|
||||
# )
|
||||
# print("Population size:", len(population))
|
||||
# print("Population:")
|
||||
# [print(str(chrom)) for chrom in population]
|
||||
|
||||
Reference in New Issue
Block a user