Skip to content

Instantly share code, notes, and snippets.

@rocreguant
Created January 31, 2021 16:21
Show Gist options
  • Save rocreguant/e89b2efde4246c1d91847b467064776b to your computer and use it in GitHub Desktop.
Save rocreguant/e89b2efde4246c1d91847b467064776b to your computer and use it in GitHub Desktop.
# 3. Selecting the progenitors
def progenitor_selection(population_set,fitnes_list):
total_fit = fitnes_list.sum()
prob_list = fitnes_list/total_fit
#Notice there is the chance that a progenitor. mates with oneself
progenitor_list_a = np.random.choice(list(range(len(population_set))), len(population_set),p=prob_list, replace=True)
progenitor_list_b = np.random.choice(list(range(len(population_set))), len(population_set),p=prob_list, replace=True)
progenitor_list_a = population_set[progenitor_list_a]
progenitor_list_b = population_set[progenitor_list_b]
return np.array([progenitor_list_a,progenitor_list_b])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment