Skip to content

n-th root for negative values, for odd n #434

Answered by MilesCranmer
romanszewczyk asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @romanszewczyk,

Thanks for the question. In PySR all operators need to handle any real-valued input. So because in Julia, custom powers require the base to be non-negative, you should instead write: x >= 0 ? x^(1//5) : -(-x)^(1//5) as the operator (the // creates a rational number). And for operators which are invalid for negatives, you can just return a NaN like x >= 0 ? x^(1//4) : typeof(x)(NaN).

Cheers,
Miles

Replies: 1 comment 7 replies

Comment options

You must be logged in to vote
7 replies
@romanszewczyk
Comment options

@MilesCranmer
Comment options

@MilesCranmer
Comment options

@MilesCranmer
Comment options

@romanszewczyk
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