How to implement the NEAT Algorithm from scratch(1/6)
This blog is my second blog, and also the first in this series. The series is named "How to implement the NEAT Algorithm from Scratch". For this, you only need the basic requirements that are:
1. Basic coding knowledge. (in any language, I use java here)
2. At least one proper read of the official NEAT Paper by Kenneth O. Stanley.
3. Some knowledge of a neural network.
And you are ready !
In every part of this blog I will write some code and explain it line by line to you, sometimes in detail, sometimes not. At the end, you will probably have the power to use the NEAT Algorithm in any of your projects.
In this part, we are just going to get an overview of the NEAT Algorithm, if you have not understood the official paper (It is very hard, I Know).
The first thing to understand is that NEAT is just a very complex variation of a neural network. But as a neural network can have any number of hidden layers, and any number of hidden nodes, it becomes difficult to choose and eventually find the best topology for the network.
This is where NEAT comes in. NEAT is "NeuroEvolution of Augumenting Topologies", which is just a fancy way to say that the structure of the neural network(Topology) can change flexibly (Augumenting), and this is made possible by the idea of neuroevolution, which involves breeding new neuralnetworks in generations to find the best topology and also the best weights for a neural network.
If you understand the paper, then you should try to implement it by yourself. I encourage you to try and not use any libraries(cause libraries are lame). I have tried to understand and implement this algo from scratch, but even I don't know if my implementation is a 100% correct.
Well thats enough small talk, lets get started. I'll be using the java programming language, which is my second favorite language (after c#), and I'm using this because it is faster than python, and 'millions of devices run java'. As you might understand, we need to have some very important classes, namely node and connection (or gene). The nodes will be connected by the genes with a random weight between -1 and 1. So make a new java project (or a new project in any language you use) and make a new class named Node.java.
Node.java
Now, in this script, the number denotes the number of the node(to identify it), the layer denotes its layer (input, hidden, output), the sum denotes the sum of all the weights x previous nodes' outputValue, and outputValue is the activated sum.
You can think about what the connectionGene class will look like till the next part drops!
Peace.
Comments
Post a Comment