Proper way to have multiple mutation operations in DEAP?

361 views
Skip to first unread message

Randy Olson

unread,
Sep 9, 2015, 5:03:17 PM9/9/15
to deap-users
Hello,

I've been using DEAP for one of my research projects and it's been working great. Thank you for developing such a wonderful code library!

I'm looking to implement multiple mutation operators in my DEAP GP algorithm. For example, I may want a mutUniform, a mutInsert, or a mutShrink to happen during a mutation all with equal probability. What is the proper way to implement this mutation scheme? Currently, I have it coded as follows:

toolbox.register('expr_mut', gp.genFull, min_=0, max_=2)


def random_mutation_operator(individual):
   
'''
        Randomly picks a replacement, insert, or shrink mutation.
    '''

    roll
= random.random()
   
if roll <= 0.333333:
       
return gp.mutUniform(individual, expr=toolbox.expr_mut, pset=pset)
   
elif roll <= 0.666666:
       
return gp.mutInsert(individual, pset=pset)
   
else:
       
return gp.mutShrink(individual)


toolbox
.register('mutate', random_mutation_operator)

but that feels a bit "hacky." Is there a built-in way to do this?

Best regards,
Randy Olson

François-Michel De Rainville

unread,
Sep 9, 2015, 7:11:13 PM9/9/15
to deap-...@googlegroups.com
There is no built-in way. You got it exactly as I would do it. It may feel hacky, but it is the best way to have complete control!

Thanks for the kind words,
Have fun with DEAP,

Cheers,
François-Michel 

--
You received this message because you are subscribed to the Google Groups "deap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages