ShuhuaGao / geppy

A framework for gene expression programming (an evolutionary algorithm) in Python
https://geppy.readthedocs.io/en/latest/
GNU Lesser General Public License v3.0
207 stars 76 forks source link

adapt the linker when dealing three or more genes in one chromosome #6

Closed bolzzzz closed 5 years ago

bolzzzz commented 5 years ago

Generally the linker function links two genes and this is how the linking is implemented in geppy. However, when the number of genes was set to 3 or more, I encountered an error saying that extra parameters are passed to the linker function. I modified the linking mechanism so that it can links 3 or more genes.

ShuhuaGao commented 5 years ago

Thanks for your contribution. However, I am afraid you didn't quite get the implementation logic. The rule is that if you have used n genes, then you should also provide a linker function which can accept exactly n arguments.

In the example, we simply use the + function as the linker, indicating that we can only use 2 genes. Supposing a chromosome is made up of 3 genes, a proper linker function is:

def add3(x, y, z):
    return x + y + z

Of course, you can use any linker function as you like once it can accept the right number of parameters.

NOTE: here the linker works a little differently from the GEP textbook. In the textbook, it works recursively just like what you have done. However, I think such recursion is unnecessarily complicated. In the current implementation, the model will simply feed all the n outputs from the n genes into the linker, and thus you can do whatever you like by defining a dedicated linker function to generate the final output.

bolzzzz commented 5 years ago

Thanks, I see!