Created
January 10, 2023 04:11
-
-
Save mmore500/35bd39e1e26b53cfde6e9da482595932 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
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