private void GlobalDiscreteRecombination(ref ESSolution offspring) { int index1, index2; ESSolution parent1 = null; ESSolution parent2 = null; int index = 0; offspring = new ESSolution(this, this.variableCount); foreach (var variable in base.context.Variables) { GenerateTwoIndeces(out index1, out index2); parent1 = this.parentPopulation[index1]; parent2 = this.parentPopulation[index2]; if (base.random.Next(0, 2) == 0) { base.modelBuilder.TryAssign(variable, parent1.currentModel.GetValue(variable.Term)); offspring.SetStdDev(index, parent1.GetStdDev(index)); } else { base.modelBuilder.TryAssign(variable, parent2.currentModel.GetValue(variable.Term)); offspring.SetStdDev(index, parent2.GetStdDev(index)); } index++; } offspring.UpdateModel(base.modelBuilder.ToArithmeticModel()); }
private void MultiStdDevMutation(ref ESSolution offspring) { SafeDebug.AssertNotNull(offspring, "offspring != null"); base.modelBuilder = base.context.CreateArithmeticModelBuilder(offspring.currentModel); double globalLearningRate = (double)1 / Math.Sqrt((double)2 * (double)base.context.Variables.Count <IArithmeticVariable>()); double localLearningRate = (double)1 / Math.Sqrt((double)2 * Math.Sqrt((double)base.context.Variables.Count <IArithmeticVariable>())); double overallT = globalLearningRate * Gaussian(0, 1); int index = 0; foreach (var variable in base.context.Variables) { Term sum = null; double ni = overallT + localLearningRate * Gaussian(0, 1); double scaleFactor = offspring.GetStdDev(index) * Math.Exp(ni); offspring.SetStdDev(index, scaleFactor); bool success = TryAddDoubleToTerm(variable.Term, scaleFactor * Gaussian(0, 1), out sum); if (success) { base.modelBuilder.TryAssign(variable, offspring.currentModel.GetValue(sum)); } index++; } offspring.UpdateModel(base.modelBuilder.ToArithmeticModel()); }
private void GlobalIntermediateRecombination(ref ESSolution offspring) { int index1, index2; ESSolution parent1 = null; ESSolution parent2 = null; offspring = new ESSolution(this, this.variableCount); Term sum = null; int index = 0; foreach (var variable in base.context.Variables) { GenerateTwoIndeces(out index1, out index2); parent1 = this.parentPopulation[index1]; parent2 = this.parentPopulation[index2]; sum = base.termManager.Add(parent1.currentModel.GetValue(variable.Term), parent2.currentModel.GetValue(variable.Term)); base.modelBuilder.TryAssign(variable, DivideByTwo(sum)); double stdDev1 = parent1.GetStdDev(index); double stdDev2 = parent2.GetStdDev(index); offspring.SetStdDev(index, (0.5 * (stdDev1 + stdDev2))); index++; } offspring.UpdateModel(base.modelBuilder.ToArithmeticModel()); }
private void SingleStdDevMutation(ref ESSolution offspring) { SafeDebug.AssertNotNull(offspring, "offspring != null"); base.modelBuilder = base.context.CreateArithmeticModelBuilder(offspring.currentModel); double learningRate = (double)1 / Math.Sqrt((double)base.context.Variables.Count <IArithmeticVariable>()); double stdDev = offspring.GetStdDev(0) * Math.Exp(learningRate * Gaussian(0, 1)); offspring.SetStdDev(0, stdDev); foreach (var variable in base.context.Variables) { Term sum = null; bool success = TryAddDoubleToTerm(variable.Term, stdDev * Gaussian(0, 1), out sum); if (success) { base.modelBuilder.TryAssign(variable, offspring.currentModel.GetValue(sum)); } } offspring.UpdateModel(base.modelBuilder.ToArithmeticModel()); }
private void DiscreteRecombination(ref ESSolution offspring) { int index1, index2; int index = 0; GenerateTwoIndeces(out index1, out index2); ESSolution parent1 = this.parentPopulation[index1]; ESSolution parent2 = this.parentPopulation[index2]; offspring = parent1.MakeDeepCopy(); foreach (var variable in base.context.Variables) { if (base.random.Next(0, 2) != 0) { base.modelBuilder.TryAssign(variable, parent2.currentModel.GetValue(variable.Term)); offspring.SetStdDev(index, parent2.GetStdDev(index)); } index++; } offspring.UpdateModel(base.modelBuilder.ToArithmeticModel()); }