Skip to content

Defining boolean operators #432

Answered by MilesCranmer
j-thib asked this question in Q&A
Sep 19, 2023 · 1 comments · 8 replies
Discussion options

You must be logged in to vote

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:

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 x > 0 => true and x <= 0 => false. It should be much easier for it to search.

Also, some Julia stuff: zero(x) returns a 0.0 but with the same precision as x. Easier than writing Floa…

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@MilesCranmer
Comment options

@MilesCranmer
Comment options

@j-thib
Comment options

@MilesCranmer
Comment options

@MilesCranmer
Comment options

Answer selected by MilesCranmer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
PySR PySR-related discussion SymbolicRegression.jl SymbolicRegression.jl-related discussion
2 participants