source: framspy/evolalg/mutation_cross/frams_mutation.py @ 1139

Last change on this file since 1139 was 1139, checked in by Maciej Komosinski, 4 years ago

Added --debug mode that prints names of steps; final multiple evaluation now evaluates genotypes in hall of fame instead of the last population

File size: 766 bytes
Line 
1import random
2
3from evolalg.base.frams_step import FramsStep
4from evolalg.base.individual import Individual
5
6
7class FramsMutation(FramsStep):
8    def __init__(self, frams_lib, commands, mutate_prob, *args, **kwargs):
9        super().__init__(frams_lib, commands, *args, **kwargs)
10        self.mutate_prob = mutate_prob
11
12    def call(self, population):
13        super(FramsMutation, self).call(population)
14        idx = []
15        for i in range(len(population)):
16            if random.random() < self.mutate_prob:
17                idx.append(i)
18        mutated = [population[_].genotype for _ in idx]
19        mutated = self.frams.mutate([_ for _ in mutated])
20
21        for i, m in zip(idx, mutated):
22            population[i] = Individual(m)
23
24        return population
Note: See TracBrowser for help on using the repository browser.