Created
May 18, 2020 11:41
-
-
Save pierrelouisbescond/611a1b178e609eacd4edcae4036003b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def min_max_select(constraints, population_in, features_names, generation_size, population_out_size, target, model): | |
# We create a new generation, based on the input population characteristics | |
new_generation = generate_min_max_population(population_in, constraints, generation_size) | |
# We append the original population to the new generation to keep the best | |
# individuals of these two DataFrames | |
new_generation = new_generation.append(population_in, ignore_index=True) | |
# We calculate Y thanks to the model and the distance from target | |
new_generation["Y"]= model.predict(new_generation) | |
new_generation["target_distance"]=abs(new_generation["Y"]-np.ones(new_generation.shape[0])*target) | |
# We sort individuals according to their distance from the target and | |
# keep only the desired number of individuals | |
new_generation = new_generation.sort_values(by="target_distance").head(population_out_size) | |
return new_generation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment