GeneticAlgorithmPython
GeneticAlgorithmPython copied to clipboard
Integer precision issues
Passing gene_type=int
in the GA
class constructor, will result in internal numpy
arrays holding 64-bit integer values. This is well known to numpy users:
>>> type(numpy.array([1], dtype=int)[0])
<class 'numpy.int64'>
This, however, has two major problems:
- It contradicts the fact that Python
int
s are arbitrary precision integers - It prohibits users from using
pygad
to explore bigger state-spaces (e.g. bit-vectors of 256-bits, or even larger in my case)
To solve this problem, a one-liner fix is to add object
in GA.supported_int_types
here. Then, users can pass gene_type=object
in the GA
constructor and handle Python integers in objective functions without worrying about numpy
getting in their way.
Added in a recent commit https://github.com/ahmedfgad/GeneticAlgorithmPython/commit/d06223483386af0a4d1f24de57e6117c0b83e917. Will be supported in the next release.
Finally found some time to port my code to the new version and run some tests.
Works like charm, thanks a lot @ahmedfgad :)