sisl / ExprOptimization.jl

Algorithms for optimization of Julia expressions
Other
44 stars 11 forks source link

Grammatical Evolution does not support _() functions in the grammar #15

Closed xgdgsc closed 5 years ago

xgdgsc commented 5 years ago

I have a function Fun(sig,N, M) that needs input constrains like N > M, so I tried using grammer of

M=|(1:30)
Add=_(rand(1:50))
sig = Fun(sig, M+Add, M)

and it doesn' t support this kind. Using rand without _( would result in expressions that contains a rand(1:50) so I could not know what is the exact input. I also tried

M=|(1:30)
Add=|(1:30)
sig = Fun(sig, M+Add, M)

and the result is some different M in the expression, like (Fun(sig, 3+10, 5)) .

What is the recommended way of doing this for now if supporting _() is hard, with inputing integers with some constraints? Thanks.

rcnlee commented 5 years ago

Hi @xgdgsc,

The GE backend doesn't currently support the () construct. The genotype in GE is a string of integers and the sequential nature means that the types can change if an integer occurring before it changes (which happens when applying genetic operators). As a result, it is not simple to add () support for GE.

In your second code snippet, you have 2 M's in the expression. Each M is treated as a separate nonterminal. The simplest way to avoid this is to define another function:

Fun2(sig, M, Add) = Fun(sig, M+Add, M)

and use Fun2 in the grammar instead.

xgdgsc commented 5 years ago

Thanks. That works for me.