Encog.Neural.NEAT.Training.NEATTraining.TournamentSelection C# (CSharp) Method

TournamentSelection() public method

Select a gene using a tournament.
public TournamentSelection ( int numComparisons ) : NEATGenome
numComparisons int The number of compares to do.
return NEATGenome
        public NEATGenome TournamentSelection(int numComparisons)
        {
            double bestScoreSoFar = 0;

            int chosenOne = 0;

            for (int i = 0; i < numComparisons; ++i)
            {
                var thisTry = (int) RangeRandomizer.Randomize(0,Population.Size() - 1);

                if (Population.Get(thisTry).Score > bestScoreSoFar)
                {
                    chosenOne = thisTry;

                    bestScoreSoFar = Population.Get(thisTry).Score;
                }
            }

            return (NEATGenome) Population.Get(chosenOne);
        }
    }