Closed cosminmarina closed 5 months ago
I feel like this doesn't quite fit with the purposed of this library, however, I have implemented it in another library based on this one (https://github.com/eugenioLR/evolml) where it fits a bit better than this.
Add GEP as Encoding. It would add availability to working with trees as Invidiuals, and the Encoding/Decoding process is quite easy.
It will need some parameters: as the maximum length of the Individual (L), the length of the head (l0), the maximum arity of the operators (n) and a list of operators.
P.e.: n = 2, l0 = 7. For this, lf = l0(n - 1) + 1 = 7 (2 - 1) + 1 = 8, and L = 7 + 8 = 15. Imagine we have the following list of operators = [+, -, *, /, x], where x is the input dependent variable. And we can use any float number with this operators. A possible Individual will be: [1, 2, 0, 2, 4, 2, 3, -1, -1, 2.0, -1, 6.0, 1.5, 1.2, -1]
The head part will correspond to index of the list of operators, while the tail part will correspond to the float numbers, or the value -1 to indicate the use of the x input variable in the tail part. So, the decodification of the Individual will be: [-, , +, , x, *, /, x, x, 2.0, x, 6.0, 1.5, 1.2, x].
With this, we will construct the tree, taking into account the arity of each element. We will build the tree be levels, until we finish the head part. After this, we will take element for the decotification in order. This means that - will be the root node from level 0 of the tree, + will be the child nodes from level 1, and x * / will be the child nodes from level 2. As x has arity = 0, it will do not have any child nodes in the next level. So level 3 will be composed of x x 2.0 x 6.0 1.5. This means that 1.2 and x will not be used in the tree. This way of encoding for tree will require to set a maximum size of the tree.
The obtained tree will be:
and this tree will correspond to the equation f(x) = x3 - 2x + 4