-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to define floating point numbers as expressions in grammar #21
Comments
The question is not very clear. |
I want to get formulas where numbers like 1.434539 or 0.95846 or 27.476503 or any other floating point number but also integers like 1 or 5 are possible coefficients. Have a look at the following example:
Thank you |
This is not a solution, more like a trick.
Even in this humble form, the number of expressions is simply overwhelming.
|
Interesting approach... I was hoping for a more elegant solution... won't there be performance issues this way?... anyway, thank you |
I'm far from an expert, but it seems to me that there is no other way in grammatical evolution. |
Thanks @mytarmail but I'm not an expert either! Your implementation is straight-forward, generalizable, and readable. One other idea is to implement it digit by digit: floater = grule(digit * 100 + digit * 10 + digit + digit * 0.1 + digit * 0.01),
digit = grule(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Search space will be more or less the same (10 ^ 5), but it might be a good idea to test this in an actual toy problem against a But reducing the search space will really depend on @vonjd 's problem. For example, what is the search space range? does some sort of non-linear transformation (exponential, tan, or even sin/cos) help map a limited range (e.g. 10 values between -1 to 1) to a broader range? what will be the minimum resolution? Can it be combined with some sort of deterministic optimization (Newton's method etc) that runs as a part of GE? |
Wow, thanks, cool solution, it was really interesting to see the comparison. One question, it is possible to make this cumbersome formula displayed as a single number? |
I'm not really sure, but making a function may make it look slightly nicer: make_fixed_point <- function(a,b,c,d,e) {
return a * 100 + b * 10 + c + d * 0.1 + e * 0.01
} Then use it in grammar: floater = grule(make_fixed_point(digit, digit,digit, digit,digit)),
digit = grule(0, 1, 2, 3, 4, 5, 6, 7, 8, 9) This will render to something slightly more readable: I named it fixed point as this literally has a fixed decimal point rather than being a true floating point. |
Perhaps it would be more efficient to define reserved placeholders for different numeric types within the package so that you only have to add |
@vonjd, I'm open to suggestions and happy to merge an pull requests. How do you see these random numbers working? Will these be simple calls to runif? or will they be some sort of constants selected from an already populated list? |
Just one idea: How about reserving a special word |
Even better would be to have something like |
Ok, so here is my final idea:
Does this make sense? |
or instead of |
Another thing I tried is to define floating-point numbers from the ground up (like other BNF grammars do it, see e.g. here: https://www.gentee.com/doc/syntax/bnf.htm)
But for some reason the |
Finally one promising workaround could be the following: |
This way you can find all kinds of approximations for pi, like the well known 22/7, sqrt(10), log(23), and more complicated ones. |
How do I define floating point numbers as valid expressions in the grammar? Thank you
The text was updated successfully, but these errors were encountered: