private void UpdateCrossovers() { ICrossover oldCrossover = CrossoverParameter.Value; ICrossover defaultCrossover = Problem.Operators.OfType <ICrossover>().FirstOrDefault(); CrossoverParameter.ValidValues.Clear(); foreach (ICrossover crossover in Problem.Operators.OfType <ICrossover>().OrderBy(x => x.Name)) { ParameterizeStochasticOperatorForIsland(crossover); CrossoverParameter.ValidValues.Add(crossover); } if (oldCrossover != null) { ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType()); if (crossover != null) { CrossoverParameter.Value = crossover; } else { oldCrossover = null; } } if (oldCrossover == null && defaultCrossover != null) { CrossoverParameter.Value = defaultCrossover; } }
private void UpdateCrossovers() { ICrossover oldCrossover = CrossoverParameter.Value; CrossoverParameter.ValidValues.Clear(); foreach (ICrossover crossover in Problem.Operators.OfType <ICrossover>().OrderBy(x => x.Name)) { CrossoverParameter.ValidValues.Add(crossover); } if (oldCrossover != null) { ICrossover crossover = CrossoverParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldCrossover.GetType()); if (crossover != null) { CrossoverParameter.Value = crossover; } } }
private void UpdateRecombinators() { ICrossover oldRecombinator = Recombinator; RecombinatorParameter.ValidValues.Clear(); foreach (ICrossover recombinator in Problem.Operators.OfType <ICrossover>().OrderBy(x => x.Name)) { RecombinatorParameter.ValidValues.Add(recombinator); } if (oldRecombinator != null) { ICrossover recombinator = RecombinatorParameter.ValidValues.FirstOrDefault(x => x.GetType() == oldRecombinator.GetType()); if (recombinator != null) { RecombinatorParameter.Value = recombinator; } } }
public int Prediction(Customer customer) { double prediction = 0.0; double cutoffRate = 0.85; for (int i = 0; i < customer.attributes.Count; i++) { prediction += customer.attributes[i] * topSeed.attributes[i]; } Console.WriteLine("Genetic Algorithms"); Console.WriteLine("population size: " + size); Console.WriteLine("generations: " + k); Console.WriteLine("crossover rate: " + crossoverRate); Console.WriteLine("mutation rate: " + mutationRate); Console.WriteLine("selection method: " + selection.GetType().Name); Console.WriteLine("crossover method: " + crossover.GetType().Name); Console.WriteLine("size of training data: " + trainingData.Count); Console.WriteLine(); Console.WriteLine("the best fitness value (" + topSeed.fitness + ") belongs to the following seed:"); Console.Write("["); for (int i = 0; i < topSeed.attributes.Count; i++) { if (i < topSeed.attributes.Count - 1) { Console.Write(Math.Round(topSeed.attributes[i], 3) + ", "); } else { Console.Write(Math.Round(topSeed.attributes[i], 3) + "]"); } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("The customer that was input has the following attributes:"); Console.Write("["); for (int i = 0; i < customer.attributes.Count; i++) { if (i < customer.attributes.Count - 1) { Console.Write(customer.attributes[i] + ", "); } else { Console.Write(customer.attributes[i] + "]"); } } Console.WriteLine(); Console.WriteLine(); Console.WriteLine("After multiplying the customer with the top seed we receive the following prediction: " + prediction); if (prediction > cutoffRate) { Console.WriteLine("The prediction is greater than the cutoffrate (" + cutoffRate + ")"); Console.WriteLine("We can therefore assume that this customer is pregnant"); return(1); } else { Console.WriteLine("The prediction is lower than the cutoffrate (" + cutoffRate + ")"); Console.WriteLine("We can therefore assume that this customer is not pregnant"); return(0); } }
/// <summary> /// Initializes a new instance of the <see cref="GeneticSharp.Domain.Crossovers.CrossoverException"/> class. /// </summary> /// <param name="crossover">The crossover where occurred the error.</param> /// <param name="message">The error message.</param> /// <param name="innerException">The inner exception.</param> public CrossoverException(ICrossover crossover, string message, Exception innerException) : base("{0}: {1}".With(crossover != null ? crossover.GetType().Name : String.Empty, message), innerException) { Crossover = crossover; }