Rémi Mochon
unread,Aug 21, 2022, 1:34:14 PM8/21/22Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to deap-users
Hello,
I am currently developping a lgp module in deap taking
example on the existing gp module (and geppy). This lgp module stands
for Linear Genetic Programming. The principle is roughly the same as in
gp, but the individuals are not lists of primitives but 2D matrices of
integers instead.
I chosed to create my individuals with a class
inheriting from ndarray. I did it because some functions (like genetic
operators) are, to my mind, cleaner written using numpy instead of a
list of lists. I am not an expert in python, so I just findout that
numpy arrays (unlike lists) can't be modified in place.
Here is
my issue: when two individuals get involved in a crossover operation,
their respective size can change, and since they are numpy arrays, I
can't modify them in place. Instead I have to create two new individual
instances in the crossover operation and return them. So, for example,
if I create two individuals and make a crossover operation with them:
# creating two individuals
ind_1 = toolbox.individual()
ind_2 = toolbox.individual()
# applying crossover operator, may modify the size of both individuals
offspring_1, offspring_2 = crossover(ind_1, ind_2)
Then
"ind_1 is offspring_1" in python will return "False". This is because
offspring_1, is a new instance of toolbox.individual(). In the gp
module, since the individuals are inheriting from lists, the individuals
can be modified in place, and I think they are in all genetic operators
defined in the gp module. As a result, in gp, "ind_1 is offspring_1"
returns "True".
My question: Is it a problem, within deap, to have
genetic operators that return new individual instances, or must they
modify the individuals in place ?
If it is a problem, then I shall create my individuals as list of lists (to mimic a 2D matrix) instead of using numpy.
I hope I am clear in my explanations. If needed, I can send my code.
Looking forward to an answer ! Best regards.
Rémi MOCHON