Skip to content

Instantly share code, notes, and snippets.

@mmore500
Created January 10, 2023 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmore500/35bd39e1e26b53cfde6e9da482595932 to your computer and use it in GitHub Desktop.
Save mmore500/35bd39e1e26b53cfde6e9da482595932 to your computer and use it in GitHub Desktop.
arr = pop_df.to_numpy()
split = np.split(
arr[:, 2],
np.unique(arr[:, [0, 1]], axis=0, return_index=True)[1][1:],
)
pos = 0
for group in split:
# minimizing operations on group_df gives >50% speedup
genome_lookup = group
tournament_rosters = np.random.randint(
len(genome_lookup),
size=(island_niche_size, tournament_size),
)
tournamnt_fitnesses = genome_lookup[tournament_rosters]
winning_tournament_positions = tournamnt_fitnesses.argmax(1)
winning_idxs = tournament_rosters[
np.arange(len(tournament_rosters)),
winning_tournament_positions,
] + pos
assert len(winning_idxs) == island_niche_size
pos += len(group)
res.extend(winning_idxs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment