tradytics / eiten

Statistical and Algorithmic Investing Strategies for Everyone
https://www.tradytics.com/
GNU General Public License v3.0
2.72k stars 316 forks source link

Genetic Algorithm is actually Random #12

Open silvavn opened 3 years ago

silvavn commented 3 years ago

I went through the Genetic Algorithm Strategy code and it seems to me to be actually random. The purpose of selecting the top K is that we want to preserve their qualities and use them in crossover. However, that preservation does not occur since their are straight crossed. Further, there is no probability involved into mutation.

Point being: The qualities of top k are most likely lost because the code does not preserve them, and does not prioritize them into crossover (we want to reproduce its qualities).

tradytics commented 3 years ago

I would respectfully disagree, let's discuss.

So the mutate function takes in the best genes from the previous iteration before mutating them further, here is a screenshot of the code:

https://i.imgur.com/679b2ke.png

Also, this isn't how most of the typical GAs are done so there are definitely some differences in the implementation but the idea of selecting the best and mutating them next thus evolving them in the entire process is still there which is why you see such high gains for GA. If it was random, there would be no gains right?

silvavn commented 3 years ago

I agree with the gains argument. My reasoning is: If I always mutate the top genes, I have the chance of losing the good characteristics from them. It follows that the select function will weed out the ones that perform bad after mutation. However, there is a chance of worsening the entire population because the top genes that were mutated might perform bad. With that i mind, the GA becomes a random walk (of course biased toward the gains xD).

I understand the reasoning I just thought I would raise this, since, by change, someone might get a bad result. Please correct me if I am wrong.