You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on the probability of reseting a member of the generation (prob=10% means we randomly choose 10% of the members and use the genome generator to create new genomes for selected members), an efficient way to apply mutation is required.
IMPORTANT: it shouldn't be done in a loop, as computing probabilities, even pseudo-random ones, takes up a lot of time. It's better to have a tool to create a "mask" with indexes of the members to be mutated and then, e.g., to use the mutate_member method in the Generation class.
The text was updated successfully, but these errors were encountered:
def mutate(self):
"""Mutation probability is the probability of 'resetting' a member of the current generation, i.e. changing
it genome randomly. For optimisation purposes instead of a loop over the whole generation, I calculate the
number of members to be mutated and then generate pseudo-randomly a list of member indexes in the current
generation to be mutated.
"""
number_of_mutations = np.floor(self.mutation_prob * self.current_generation.size)
"""Size of generation is a constant, it has to be adjusted to the lack of elite; the elite Members are not
supposed to be mutated. Additionally, number of mutations has to be an integer, e.g.,
half of a mutation cannot be performed.
"""
indexes = random.sample(
range(self.current_generation.size - self.elite_size),
int(number_of_mutations) # has to be an integer, e.g. you can't make half of a mutation
)
"""For new (mutated) genome creation I use the generator passed to the superclass in it's initialisation:"""
for index in indexes:
self.current_generation.members[index].change_genes(
self.genome_generator(self.genome_generator_args)
)
Based on the probability of reseting a member of the generation (prob=10% means we randomly choose 10% of the members and use the genome generator to create new genomes for selected members), an efficient way to apply mutation is required.
IMPORTANT: it shouldn't be done in a loop, as computing probabilities, even pseudo-random ones, takes up a lot of time. It's better to have a tool to create a "mask" with indexes of the members to be mutated and then, e.g., to use the
mutate_member
method in theGeneration
class.The text was updated successfully, but these errors were encountered: