public double TrainNeuralNetwork()
        {
            var chromosome = new KasandraChromosome(_fitness.TotalNumberOfWeights);

            var population = new Population(minPopulation, maxPopulation, chromosome);
            _geneticAlgorithm = new GeneticAlgorithm(population, _fitness, new EliteSelection(), new UniformCrossover(), new UniformMutation(true));

            _geneticAlgorithm.MutationProbability = mutationRate;
            _geneticAlgorithm.CrossoverProbability = crossoverProbabilty;
            _geneticAlgorithm.Termination = new GenerationNumberTermination(maxIterations);
            _geneticAlgorithm.TerminationReached += _geneticAlgorithm_TerminationReached;
            _geneticAlgorithm.GenerationRan += _geneticAlgorithm_GenerationRan;

            _geneticAlgorithm.Start();

            return 0;
        }
 private void _geneticAlgorithm_GenerationRan(object sender, EventArgs e)
 {
     var ga = (GeneticAlgorithm)sender;
     //if(ga.GenerationsNumber%50 == 0 || ga.GenerationsNumber == 1 || ga.GenerationsNumber < 100)
     Console.WriteLine("" + ga.GenerationsNumber + "\t" + Math.Abs(ga.BestChromosome.Fitness.Value));
     winner = (KasandraChromosome) ga.BestChromosome;
     if (winner.Fitness.Value > bestEverFitness)
     {
         bestEver = winner;
         bestEverFitness = winner.Fitness.Value;
     }
 }
 private void _geneticAlgorithm_TerminationReached(object sender, EventArgs e)
 {
     var ga = (GeneticAlgorithm) sender;
     winner = (KasandraChromosome) ga.BestChromosome;
     if (winner.Fitness.Value < bestEver.Fitness.Value)
         winner = bestEver;
 }