I found out about genetic algorithms a few months ago, and then found this site. Well, it’s more of an online book to be precise. Anyways, in that chapter, I read the first part and wrote it in Python. Like I wrote previously, the explanations and the concepts were simple and it was easy to convert the code.
What I coded was you could enter a string (for example a sentence), and then it would create a population of objects. These objects had “genes” which was the string of letters. Keep in mind that at the beginning, the characters in these genes were randomly chosen. Then the fitness of each object would be calculated, that is the objects that were closer to the actual string had a higher fitness. Then the best strings “merged” and formed the next generation. In this way, theoretically, it would eventually reach the goal. And it did. In the beginning, I could understand the concept and see why, but I think I secretly had doubts about whether A, it could actually work and B if I could actually code it. But work it did, and I was seriously amazed. It still doesn’t cease to amaze me that random characters become a legible string through a simple algorithm.
Anyways, I chose to print the best string (highest fitness) of each generation and without further ado, here is the code (I made a few minor changes too):
This subject was far harder to begin with than genetic algorithms. I’m going with a top-bottom approach, as the technical aspects are still a bit difficult to grasp, but the results are really quite cool. I acquired and went through a little of Fundamentals of Neural Networks: Architectures, Algorithms And Applications, which was a bit hard to read but I managed. That was my first taste of neural networks and it was interesting, but I thought I was going a bit slow so I then went through a little of this course. I’m still going through them, but at this point I wanted to do some practical stuff, so I downloaded Pybrain which is a NN library that could let me abstractly deal with the concepts. And using Pybrain I made a Handwritten Digit recognition program of a sort (it doesn’t work very well and I don’t think it really does anything but compare pixels that are “on” and “off”). Everything’s still a bit confusing and I don’t get why some modifications make it work better, but here it is: