TemplateExpressionSpec with custom operator #808
-
Hi there, I am a newbie in using pysr, but may I check if is there a way to use a custom operator (Indicator function here) within the TemplateExpressionSpec? template = TemplateExpressionSpec(
function_symbols = ["f"],
combine="((; f), (x0)) -> Indicator(f(x0))"
)
PySRRegressor(
...
unary_operators=[
...
"Indicator(x::T) where {T} = x > T(0) ? T(1) : T(0)"
],
extra_sympy_mappings={
"Indicator": lambda x: sympy.Piecewise((1, x > 0), (0, True))
},
...
) |
Beta Was this translation helpful? Give feedback.
Answered by
MilesCranmer
Jan 15, 2025
Replies: 1 comment 13 replies
-
It’s a bit more complex (see other discussion threads with gm89uk) but as a simpler solution I would just turn it into a multiplication, like ((; f), (x0,)) -> (f(x0) > 0*x0) * (1 + 0*x0) |
Beta Was this translation helpful? Give feedback.
13 replies
Answer selected by
ProPLr00
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It’s a bit more complex (see other discussion threads with gm89uk) but as a simpler solution I would just turn it into a multiplication, like