n-th root for negative values, for odd n #434
-
Hi! I am trying to add to regressor, a custom function calculating 5th root, 7th root and 11th root. I tried the following commands: unary_operators=["sqrt", "square", "cbrt", "cube", extra_sympy_mappings={"inv": lambda x: 1 / x, Unfortunately, I've got the following error: RuntimeError: <PyCall.jlwrap (in a Julia function called from Python) n-th root for the odd values should work for negative input. Please help me, what I am doing wrong? Thank you in advance for your help! With best regards, Roman |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
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: Cheers, |
Beta Was this translation helpful? Give feedback.
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 likex >= 0 ? x^(1//4) : typeof(x)(NaN)
.Cheers,
Miles