Esempio n. 1
0
    def mutate_individual(self, candidate):
        if random.random() < self.prob_order_mutates:
            candidate.order *= -1
        if random.random() < self.prob_orientation_mutates:
            candidate.orientation = candidate.orientation.negate()
        # if random.random() < self.prob_t_mutates:
        #     candidate.t += random.uniform(-self.t_mutation_magnitude, self.t_mutation_magnitude)
        if random.random() < self.prob_padding_mutates:
            candidate.padding = not candidate.padding

        candidate.t = min(max(candidate.t, 0.3), 0.7)

        for child in candidate.children:
            self.mutate_individual(child)
Esempio n. 2
0
 def mutate_individual(self, weights):
     mutant = dict(weights)
     for key in weights.keys():
         if random.random() <= self.prob_point_mutation:
             mutant[key] += random.uniform(-0.3, 0.3)
             mutant[key] = max(0.05, mutant[key])
     self.normalize_groom_weights(mutant)
     mutant["scoreCurveExponent"] = max(1, mutant["scoreCurveExponent"])
     return mutant
Esempio n. 3
0
 def mutate_individual(self, candidate):
     for i in range(len(candidate.vector)):
         if random.random() < self.prob_point_mutation:
             candidate.vector[i] = 1 - candidate.vector[i]
Esempio n. 4
0
 def crossover_weights(self, a, b):
     child = dict(a)
     for key in a.keys():
         if random.random() < self.prob_inherit_from_b:
             child[key] = b[key]
     return child