A lightweight and beginner friendly implementation of the neat algorithm
//Create a manager with all necessary properties
//The Evaluate function has to a function that returns the fitness of
//the current network. The BaseGenome, Mutator can be created outside
//the obj initializer and be customized to your needs.
var manager = new Manager
{
EvaluationFunction = Evaluate,
BaseGenome = Genome.Generate(1, 1, true),
Mutator = new Mutator(),
};
//Setup ManagerOnOnLifecycleFinishedEvent
//This event is called a lifecycle is finished
manager.LifecycleFinishedEvent += OnLifecycleFinishedEvent;
//This method evolves the network untill the given fitness is reached
//and returns the network that has reached the given fittnes
var network = manager.TrainUntil(0.98);
//After the process is finished you can use the network.
//The network can also be saved and restored using the
//toString and fromString method.
while (true)
{
Console.Write("Input: ");
var input = Convert.ToDouble(Console.ReadLine());
//Calculate and print out the result
Console.WriteLine("Output: " + String.Join(", ", network.Calculate(new[] { input })) + "\n");
}
Or take a look at the sample project here.
The network is evolved by a slightly modified version of the NEAT algorithm.
If you want to learn more about it you can read the official PDF or watch this youtube video: