Can't use a method as fitness function #69
Replies: 3 comments 2 replies
-
I am having a similar issue. Trying to encapsulate all GA in a Class and global variables are not good design pattern.
so then I tried using functools.partial and still no so then I tried using functools.partialmethod and still no. workaround is to remove the argument count checks entirely in pygad.py line 638. In fact actually there are 2 open PR to address this issue. Can we merge one of them and move forward already? |
Beta Was this translation helpful? Give feedback.
-
This is now supported. The fitness or any callback can accept a function or a method. |
Beta Was this translation helpful? Give feedback.
-
I need my fitness function to have a state, for that reason I need to use a method instead of a function in the fitness_func parameter.
The problem is, PyGAD won't accept a method as fitness function.
This happens because PyGAD verifies how many arguments a function have and together with "self" argument a method as fitnees function would have 3 arguments. PyGAD won't let any fitness_func with number of arguments different than 2.
Shouldn't this be changed in the lib?
Does someone know a way around this while this feature isn't provided?
Beta Was this translation helpful? Give feedback.
All reactions