private void DieOfAge(int maxAge) { if (PopulationList.Exists(x => x.Age > maxAge)) { PopulationList = PopulationList.OrderBy(x => x.Age).ToList(); NeuronNet firstOld = PopulationList.First(x => x.Age > maxAge); int index = PopulationList.IndexOf(firstOld); PopulationList.RemoveRange(index, PopulationList.Count - index); PopulationList = PopulationList.OrderBy(x => x.Error).ToList(); } }
private void SurvivalOfTheFitest(double fatality, int populationSize, int maxAge) { if (PopulationList.Count > populationSize) { PopulationList.RemoveRange(populationSize, PopulationList.Count - populationSize); } int casualityNumber = (int)Math.Round(PopulationList.Count * fatality); for (int i = PopulationList.Count - 1; i >= PopulationList.Count - casualityNumber; i--) { PopulationList[i].RandomizeWeights(MinWeightValue, MaxWeightValue); } }