/// <summary> /// Calculates the adjusted fitness of all genomes. /// Also syncs up species fitness information. /// </summary> public void AdjustFitness() { Fitness.TotalAdjustedScore = 0.0; foreach (var genome in Genomes) { GenomeFitnessInformation genomeFitness = genome.Fitness; genomeFitness.AdjustedScore = genomeFitness.Score; if ((Age - AgePrime + 1 - Const.SpeciesStagnationAge >= 0) || OnDeathBed) { genomeFitness.AdjustedScore *= 0.01; } if (Age <= Const.AgeOfYouthThresh) { genomeFitness.AdjustedScore *= Const.YouthRewardCoefficient; } if (genomeFitness.AdjustedScore < 0) { genomeFitness.AdjustedScore = 0; } genomeFitness.AdjustedScore /= Size(); Fitness.TotalAdjustedScore += genomeFitness.AdjustedScore; } Fitness.AverageAdjustedScore = Fitness.TotalAdjustedScore / Size(); }
public static void Pole2_Evaluate(Random rando, Network network, GenomeFitnessInformation fitnessInfo) { }
public static void Pole1_Evaluate(Random rando, Network network, GenomeFitnessInformation fitnessInfo) { int maxSteps = 100000; int steps = 0; int y; Dictionary <int, double> inputArray = new Dictionary <int, double>() { { 1, 0.0 }, { 2, 0.0 }, { 3, 0.0 }, { 4, 0.0 }, }; CartInfo cartInfo = new CartInfo(rando); if (false) { inputArray[1] = (cartInfo.x + 2.4) / 4.8;; inputArray[2] = (cartInfo.x_Dot + .75) / 1.5; inputArray[3] = (cartInfo.theta + twelve_degrees) / .41; inputArray[4] = (cartInfo.theta_Dot + 1.0) / 2.0; network.LoadSensors(inputArray); network.Initialize(); } while (steps++ < maxSteps) { inputArray[1] = (cartInfo.x + 2.4) / 4.8; inputArray[2] = (cartInfo.x_Dot + .75) / 1.5; inputArray[3] = (cartInfo.theta + twelve_degrees) / .41; inputArray[4] = (cartInfo.theta_Dot + 1.0) / 2.0; network.LoadSensors(inputArray); Dictionary <int, double> outputArray = network.Activate(); double val5 = 0.0; double val6 = 0.0; if (outputArray.Keys.Contains(5)) { val5 = outputArray[5]; } if (outputArray.Keys.Contains(6)) { val6 = outputArray[6]; } if (val5 > val6) { y = 0; } else { y = 1; } cartInfo.AdjustCart(y); if (!cartInfo.IsStable()) { break; } } fitnessInfo.Score = steps; }