Hello everyone.
I am rather new to both symbolic regression and sympy. I am trying to use expressions (mathematical equations) to represent individuals in a genetic algorithm population. However, i came across the following issue:
When trying to create an initial population, i have to create equations/expressions/trees from a fixed set of Symbols and operations. I do not know how to combine them into random combinations representing complete expression trees.
Here is my code snippet:
# Symbols
x1, x2 = symbols('x1, x2')
# Functions
operations = [Add, Mul, Rational, Pow, sin, cos, tanh, log]
for i in xrange(100):
random_operation = randint(0, 7)
print operations[random_operation]
However, i would like to create complete examples of equations/expressions/trees, including my symbols, so that i can represent them as trees. My ultimate goal is to evolve this population by substituting certain operations/symbols for the new population (crossover, mutation, etc). For example, i would like to have (many different random combinations):
>>> expr = (Symbol('x1')+Symbol('x2'))**2 / 3
>>> srepr(expr)
Mul(Rational(1,3),Pow(Add(Symbol(′x1′),Symbol(′x2′)),Integer(2)))
Any help much appreciated.
Thank you and kind regards,
Gasper