If I may request one specific area of focus: you might notice that there are what seem like semi-half-hearted attempts at using generators that look like I just gave up and used lists. I'm excited to hear about any and all potential improvements, even the aforementioned structural refactoring. The simulation can already handle custom configuration parameters, albeit only like four of them, but the mechanism is really clunky. The one change I would make is incorporating configparser and argparse to be able to handle both configuration files and command-line parameters. I wrote the entire thing as a one-file script, which I know is not ideal, but I was having a blast writing the actual logic. I keep track of the extant number of each genome over each iteration, and I use Matplotlib to plot a graph at the end of the genomes which scored higher than an eight on the fitness function (this is pretty arbitrary, but the vast majority of the genomes were massively outdone pretty quickly and became afterthoughts right away, so it helps to not clutter the graph). Again, I know nothing about this field, though. After each iteration, I calculate the z-score of each solution and I pass that in to the \$\tanh x\$ function, yielding what seemed to me like pretty decent results. I decided the model the probability of successfully reproducing using the hyperbolic tangent function. When the sum of the weights exceed the specified limit, however, the fitness of that particular solution is set to zero. The fitness parameter is a particular solution's utility as calculated by the fitness function, which is itself simply the sum of the values of all the items in the solution. Solution count fitness reproduction_probability population_size I was watching Computerphile's video on using genetic algorithms to solve the Knapsack problem, and I decided to give it a whack.įor anyone running the code, the result_data pandas Data Frame contains the most recent iteration's breakdown of the genomes that are "still alive".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |