popu = toolbox.population(n=3)
algorithms.eaSimple(popu, toolbox, cxpb=CXPB, mutpb=MUTPB, ngen=NGEN)
....
at the second line I am getting this error:
invalid_ind = [ind for ind in population if not ind.fitness.valid]
AttributeError: 'numpy.ndarray' object has no attribute 'fitness'
How can I handle this problem?
Thank you very much.
--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)
toolbox.register("individual", tools.initIterate, createIndividual, creator.Individual)
toolbox.register("population", list, toolbox.individual)
in createIndividual function, individual type is numpy array but
still should I change the list type with numpy.ndarray in these lines?
Thank you.
--
You received this message because you are subscribed to a topic in the Google Groups "deap-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/deap-users/alxeOILteJk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to deap-users+unsubscribe@googlegroups.com.
class Individual(my_parent_class)
To unsubscribe from this group and all its topics, send an email to deap-users+...@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to deap-users+unsubscribe@googlegroups.com.
algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2, ngen=50)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/deap/algorithms.py", line 146, in eaSimple
invalid_ind = [ind for ind in population if not ind.fitness.valid]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/deap/algorithms.py", line 146, in <listcomp>
invalid_ind = [ind for ind in population if not ind.fitness.valid]
AttributeError: 'numpy.ndarray' object has no attribute 'fitness'
# Fitness:
creator.create("FitnessMulti", base.Fitness, weights=(-1.0, 1.0))
creator.create("Individual", numpy.ndarray, dtype=int, fitness=creator.FitnessMulti)
# toolbox
toolbox = base.Toolbox()
toolbox.register("individual", create_individual, n_c, n_d)
toolbox.register("population", tools.initRepeat, list, toolbox.individual) # short-hand for repeating individual creation
toolbox.register("evaluate", evaluate_individual, disc=disc, cpp=cpp, cpd=cpd)
toolbox.register("mate", crossover_individuals)
toolbox.register("mutate", mutate_individual)
toolbox.register("select", tools.selTournament, tournsize=3)
# initial (random) population
pop = toolbox.population(n=20)
# optimise
algorithms.eaSimple(pop, toolbox, cxpb=0.5, mutpb=0.2, ngen=50)
>>> create_individual(10,4)
array([[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 0, 1, 0],
[0, 0, 1, 0],
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 0, 1, 0],
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 0, 1, 0]])
>>> type(create_individual(10,4))
<class 'numpy.ndarray'>
>>>
>>> pop = toolbox.population(4)
>>> type(pop[0])
<class 'numpy.ndarray'>
>>> toolbox.evaluate(pop[0])
(30.7, 1.0794631944831576)
>>> toolbox.mate(pop[0],pop[1])
array([[0, 1, 0, 0],
[0, 1, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[1, 0, 0, 0],
[0, 1, 0, 0],
[1, 0, 0, 0]])
>>> type(toolbox.mate(pop[0],pop[1]))
<class 'numpy.ndarray'>
>>> toolbox.mutate(pop[0])
array([[1, 0, 0, 0],
[0, 0, 1, 0],
[0, 1, 0, 0],
[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 1, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[1, 0, 0, 0],
[0, 0, 1, 0]])
>>> type(toolbox.mutate(pop[0]))
<class 'numpy.ndarray'>
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+unsubscribe@googlegroups.com.
Thanks so much clearer now and working.
Merci beaucoup
M-I
To unsubscribe from this group and stop receiving emails from it, send an email to deap-users+...@googlegroups.com.
--
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.