Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

data types #43

rengel8 started this conversation in General
May 18, 2021 · 4 comments · 4 replies
Discussion options

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

You must be logged in to vote

Replies: 4 comments 4 replies

Comment options

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!

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
2 replies
Comment options

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]

Comment options

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!

Comment options

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.

You must be logged in to vote
1 reply
Comment options

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.

Comment options

could be possible a gene type of boolean? or maybe a list of possible values? like [0,1]

You must be logged in to vote
1 reply
Comment options

You can use [0,1] instead of [False, True]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested

AltStyle によって変換されたページ (->オリジナル) /