how to exclude twins from population?

91 views
Skip to first unread message

Lisa Bang

unread,
Oct 30, 2014, 7:16:56 AM10/30/14
to deap-...@googlegroups.com
Hello,

First I'd like to say thanks to the contributors of this project.  I love that there's a framework like DEAP so I'm not reinventing the wheel every time I want to run a GA :)

I've been working on a DEAP algorithm to implement variable subset selection (GA-VSS, as described here).  In QSAR (structure-activity relationship), it's common practice to use GA to generate a set of useful models -- that is, given a bunch of variables (1000+) to predict activity Y, we want to select the best 5 or so.  Since there isn't currently a python implementation of the GA-VSS method, I've been using DEAP to construct such an algorithm, but I've gotten stuck on a crucial point -- none of the individuals in the population can be twins in GA-VSS.  

Is there any built-in method to exclude twins from the population?  I've already tried set() which hasn't worked because Individuals are unhashable, as well as this method and these methods here.  

Could someone point me in the right direction?  When I can't exclude twins, my population quickly turns into identical individuals even with a very high crossover/mutation rate... which is exactly why twins must be excluded from GA-VSS...

Lisa

Félix-Antoine Fortin

unread,
Oct 30, 2014, 4:05:33 PM10/30/14
to deap
Hi Lisa,

As you found out, Individual list are not hashable. However, it is possible to define a __hash__ method for the class Individual.

I have written a simple example that illustrates how :

This makes the hash function dynamic. The modification of the individual will change its hash, but Python do not recompute the hash of each element in the set as it is supposed to be a constant. Therefore before modifying an individual, remove it from the set, or simply use the set as a temporary storage when doing crossover and mutation, then convert the population to a list for the rest of the operations.

Feel free to ask more questions as I might have left some imprecisions.

Félix-Antoine

--
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.

Lisa Bang

unread,
Nov 2, 2014, 7:50:33 PM11/2/14
to deap-...@googlegroups.com
Thank you!  This worked very well for me.
Reply all
Reply to author
Forward
0 new messages