DEAP framework - mutGaussian using per gene statistics

415 views Asked by At

I have an individual with the following genes:

genes = [8, 2, 300, 2, 25, 10, -64, -61]

and I then apply the following gaussian mutation:

toolbox.register("mutate", tools.mutGaussian, mu=0, sigma=1, indpb=1)
toolbox.mutate(genes)

to produce the new genes:

[9, 4, 301, 2, 24, 9, -65, -60]

My problem with this mutation is that the gaussian stats for this individual seem to be determined using all of genes instead of for each gene...while a +/- 2 mutation to most of the genes is fine, the value that started at 300 should change more dramatically.

It's strange to me that there's no accounting for this need in the docs.

Is there no in-built mechanism for mutating individuals using the per-gene statistics?

I'm supposing that a distribution is formed for each individual in the population using all of its genes. What I want is for a distribution to be formed for each gene using all the individuals in the population.

1

There are 1 answers

0
usernumber On BEST ANSWER

You can set sigma to be a list rather than a float. This way, if each gene is taken from a different range, you can adjust the value of sigma to better fit the values taken by each gene.

If you don't know ahead of time which genes will be bigger than others, you can implement your own mutation function. For instance, you can set the sigma of the gaussian to depend on the value of the gene:

def mutGaussian(individual, sigma, indpb):
    for i in range(len(individual)):
        if random.random() < indpb:
            individual[i] = random.gauss(individual[i], sigma*individual[i])

    return individual,