kstaats / karoo_gp

A Genetic Programming platform for Python with TensorFlow for wicked-fast CPU and GPU support.
Other
157 stars 61 forks source link

Conditionals and Logical Operators #54

Closed granawkins closed 2 years ago

granawkins commented 2 years ago

As part of the ongoing redesign, I'd like to optimize if and if else operations. This is also discussed in #27 and there is some good guidance there.

A logical tree should be able to express something like "If volume is above 100, price squared over 200, else short / 300." In a poorly-rendered tree structure that looks like:

               IF
     >         /          /
 vol  100   **  200  short  300
        price 2

As I see it, there ought to be three classes of nodes: operators, terminals and booleans(new). In addition to arity, different types of nodes now specify that their children be a certain class.

Class Type Symbol Arity Child Class
operator arithmetic +, -, *, /, ** 2 op/tm
operator logic IF, IFELSE 2, 3 bool, op/tm
boolean comparison ==, !=, >, <, >=, <= 2 op/tm
boolean logic AND, OR, NOT 2, 1 bool
terminal inputs a, b, c 0 -
terminal constants 1, 2, 3 0 -
granawkins commented 2 years ago

This was implemented in #85