vectorized

This commit is contained in:
2025-11-05 20:32:09 +03:00
parent 26bd6da1b4
commit e6765c9254
8 changed files with 140 additions and 349 deletions

View File

@@ -1,3 +1,5 @@
import numpy as np
from gp import Chromosome, ops
from gp.population import ramped_initialization
from gp.primitive import Var
@@ -10,16 +12,25 @@ print("Depth:", chrom.root.get_subtree_depth())
print("Formula:", chrom)
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]
values = [
np.array([1.0]),
np.array([2.0]),
np.array([3.0]),
np.array([4.0]),
np.array([5.0]),
np.array([6.0]),
np.array([7.0]),
np.array([8.0]),
]
context = {var: value for var, value in zip(terminals, values)}
print("Value for ", values, ":", chrom.root.eval(context))
# 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]
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]