Assigning fitness values to individuals

25 views
Skip to first unread message

Welcome Tshuma

unread,
Dec 28, 2023, 7:24:20 AM12/28/23
to deap-users
Hi all,

I seem to be having a problem when assigning fitness values to individuals in a population using these lines of code:
fitnesses=list(map(toolbox.evaluate, population))
for ind, fit in zip (population, fitnesses):
    ind.fitness.values=fit
File ~\anaconda3\lib\site-packages\deap\base.py:188, in Fitness.setValues(self, values) 187 def setValues(self, values): --> 188 assert len(values) == len(self.weights), "Assigned values have not the same length than fitness weights" 189 try: 190 self.wvalues = tuple(map(mul, values, self.weights)) TypeError: object of type 'float' has no len()
How do I resolve this?

Rupert Young

unread,
Jan 2, 2024, 12:35:17 PMJan 2
to deap-users
Hi,

What do you have registered as the "evaluate" function and what does it return?
e.g. self.toolbox.register("evaluate", self.evaluate())

I believe it returns a tuple. In my function I have

        return score,
Reply all
Reply to author
Forward
0 new messages