Defining boolean operators #432
-
Hi, has anyone been successful at defining certain boolean operators such as "or"? For instance, here is a snippet from my model instantiation.
Upon searching in this space, the function returned doesn't include the defined "or" operator, instead returning a constant prediction. I have been successful with "and", "greater than" and "less than", but "or" seems to be causing problems. Is there something causing "or" to be more difficult for PySR to explore? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Hi @j-thib, Keep in mind that PySR performs all calculations in the space of real numbers, so to do calculations like this, it is much easier to treat numbers greater than 0 as true, and numbers less than 0 as false. Otherwise, to get a true, it would have to exactly land on I would do this instead: OR(x, y) = ((x > zero(x)) | (y > zero(y))) * one(x)
AND(x, y) = ((x > zero(x)) & (y > zero(y))) * one(x) This assumes that Also, some Julia stuff: Then for your sympy version, I would actually write it like this: "OR": lambda x, y: sympy.Piecewise((1.0, (x > 0) | (y > 0)), (0.0, True)),
"AND": lambda x, y: sympy.Piecewise((1.0, (x > 0) & (y > 0)), (0.0, True)), Cheers, |
Beta Was this translation helpful? Give feedback.
Hi @j-thib,
Keep in mind that PySR performs all calculations in the space of real numbers, so to do calculations like this, it is much easier to treat numbers greater than 0 as true, and numbers less than 0 as false.
Otherwise, to get a true, it would have to exactly land on
x1 = 1.0
, which, if it's doing constant optimization, is basically going to be impossible.I would do this instead:
This assumes that
x > 0
=>true
andx <= 0
=>false
. It should be much easier for it to search.Also, some Julia stuff:
zero(x)
returns a0.0
but with the same precision asx
. Easier than writingFloa…