-
-
Notifications
You must be signed in to change notification settings - Fork 489
-
I'm currently making some first steps with pygad and, after some difficulties in the beginning, this question arose.
Is it possible to use mixed data types for genes?
I know about the internal random function using float values, which then are converted to integer if the user sets gene_type=int. Right now I tend to stay with float and to convert these to int later, since I have some genes, which need to be float, others are integer. It confused me a bit regarding the mutation of genes as floating, which become the same integer after conversion (no mutation). Is this covered in some way? Just curious.
Regards,
Rainer
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Replies: 4 comments 4 replies
-
Hi Rainer,
Despite being not supported yet, it is very interesting to have this feature in the next release of PyGAD to help you specify a data type for each gene. For now, all genes could be only of a single data type.
Thank you at all!
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi Rainer,
Your requested feature is supported in PyGAD 2.14.1
Tor example, if you have 2 Gene's where the first is int and the second is float, then use:
gene_type=[int, float]
Please try this feature and let me know if there are any problems to be solved or if you have any new features in mind to be included later.
Beta Was this translation helpful? Give feedback.
All reactions
-
That was faster then any Police might allow .. great!
At first I accidently downloaded 2.14, which did produce an error (AttributeError: module 'pygad' has no attribute 'GA'), but 2.14.1 is working again. It seems to work on my in pro-gress examples, but printing the solution is not looking nice anymore.
solution, solution_fitness, solution_idx = ga_instance.best_solution()
print("Solution : {solution}".format(solution=solution))
gene_type=int,
Solution : [142 8 14]
gene_type=[int, int, float],
Solution : [array([82.65273693]) 116 array([7.80978576])]
Solution : [array([74.57225008]) array([55.74501245]) 13.525247767957666]
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
Sorry I had a problem in the __init__.py
file while pushing the library to PyPI. This is why I added the 2.14.1 release directly after 2.14.0 was published.
I figured out the problem and fixed it. I pushed the new pygad.py
file to GitHub and later will reflect this on PyPI.
Thank you too much for your valuable feedback!
Beta Was this translation helpful? Give feedback.
All reactions
-
A general question in this context would be decimal places of float genes. I my opinion (beyond what is going on during mutation) it would be helpful if one could decrease the precision of floats, global and/or individual. If this could also increase the whole workflow performance it would make sense to me, to use this i.e. for a exploratory run or for destinct use cases, where a finer granularity over a certain precision does not make any sense.
I'm not that much involved what's under the hood at pygad right know, but for me this relates also to the topic exit criteria (I'll add to this as a idea topic). I.e. the found solution is best with leap to others, but the systematic result by the found genes stays the same.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
-
That is something interesting to be supported.
Sure, controlling the precision for floating-point numbers is a good feature.
I will add this feature in the to-do list to be supported in the next release.
Beta Was this translation helpful? Give feedback.
All reactions
-
could be possible a gene type of boolean? or maybe a list of possible values? like [0,1]
Beta Was this translation helpful? Give feedback.
All reactions
-
You can use [0,1]
instead of [False, True]
Beta Was this translation helpful? Give feedback.