private Individual[] MutatePopulation() { int populationSize = population.Length; for (int i = elitism; i < populationSize; i++) { population[i].gen = Genoma.Mutate(r, population[i].gen, mutationRate, maxPerturbation); } return(population); }
public void Initialize(MendelMachine mendelMachine, Genoma genoma, ActivationFunction activationFunction, bool learningPhase, float lifeTime, int index) { fitness = 0; this.index = index; this.mendelMachine = mendelMachine; this.learningPhase = learningPhase; this.lifeTime = lifeTime; perceptron = new Perceptron(genoma, activationFunction); on = true; }
private Individual[] CrossPopulation() { int populationSize = population.Length; List <Individual> crosspop = new List <Individual>(); for (int i = 0; i < populationSize; i++) { population[i].fitness = -1; for (int j = 0; j < populationSize - i; j++) { crosspop.Add(population[i]); } } List <Individual> newpop = new List <Individual>(); for (int i = 0; i < elitism; i++) { newpop.Add(population[i]); } for (int i = 0; i < newIndividuals; i++) { newpop.Add(GenerateIndividual()); } for (int i = 0; i < populationSize - newIndividuals - elitism; i++) { Individual individual = new Individual { gen = Genoma.Cross(r, crosspop[Random.Range(0, crosspop.Count)].gen, crosspop[Random.Range(0, crosspop.Count)].gen), fitness = 0 }; newpop.Add(individual); } return(newpop.ToArray()); }