def evolveNewPop(rankedPop): """ rankedPop is zip(weights, errors, fitnesses) ordered in ascending order of fitness """ rankedWeights = [item[0] for item in rankedPop] fitnessScores = [item[-1] for item in rankedPop] newpopW = deepcopy(rankedWeights[:NN.eliteN]) while len(newpopW) < NN.pop_size: ch1, ch2 = selectTwoIndividuals(fitnessScores, rankedWeights) if random.random() <= NN.crossover_rate: ch1, ch2 = crossover(ch1, ch2, NN) mutate(ch1, NN.mutation_rate) mutate(ch2, NN.mutation_rate) newpopW.append(ch1) newpopW.append(ch2) return newpopW[:NN.pop_size]