Tournament selection and Minimizing objective

39 views
Skip to first unread message

David Valera Laborda

unread,
Mar 6, 2024, 2:15:32 PMMar 6
to deap-users
Here it comes my doubt. Im looking for minimizing my singled-objetive. When I come up for searching in the library code of DEAP of how the selection via tournament is done in reality.

def selTournament(individuals, k, tournsize, fit_attr="fitness"):
chosen = []
for in range(k):
aspirants = selRandom(individuals, tournsize)
chosen.append(max(aspirants, key=attrgetter(fit_attr)))
return chosen

The chosen is elected by the maximum fitness, being this just the opposite of what we want. 

I need somebody to give me a check of this thing that I come up with.

François-Michel De Rainville

unread,
Mar 6, 2024, 2:17:07 PMMar 6
to deap-users
It is done on the weighted objectives. For minimization the weight should be negative.

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/deap-users/4719d9dd-92b2-421a-ae59-f76e83d1562dn%40googlegroups.com.

David Valera Laborda

unread,
Mar 6, 2024, 3:03:30 PMMar 6
to deap-users
Well yeah, but how can I verify that? I mean, in terms of code, the EAsimplealgorithm call the selection method which the code is the one above. And in that code it is always selected the maximum.

François-Michel De Rainville

unread,
Mar 6, 2024, 3:21:33 PMMar 6
to deap-users
You can check how "less than" in overridden in the fitness class. Maximum, and sorting in general, uses these methods from the object.

David Valera Laborda

unread,
Mar 6, 2024, 3:23:39 PMMar 6
to deap-...@googlegroups.com
Wells I was expecting some Code to learn how It is done. But thanks anyway. At least now i know it is correct

François-Michel De Rainville

unread,
Mar 6, 2024, 4:11:10 PMMar 6
to deap-users
Reply all
Reply to author
Forward
0 new messages