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]


With this i manage to get a random operation as described 
here: http://docs.sympy.org/dev/tutorial/manipulation.html

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

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/becbb2b4-82c0-4fe8-a33f-ad51a4e629da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to