-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] min binary function raises errors during prediction #183
Comments
Thanks for the amazing package by the way ! |
Hi @gdelab, Thanks for posting. I didn't that I wonder if the reason these don't work at the prediction step is because model = PySRRegressor(
binary_operators=[
"mmin(x, y) = min(x, y)",
"mmax(x, y) = max(x, y)",
],
extra_sympy_mappings={"mmin": sympy.Min, "mmax": sympy.Max}
) Let me know if this works. Everything else looks fine though. Cheers, |
Actually, wait. I just looked and sympy seems to be doing it's job. If you look at I think the reason it doesn't work in the predict stage is because sympy's lambdify function does not have a numpy mapping for I'll think of a hack around this... |
So I did something similar here: #150 You can hack this with the model = PySRRegressor(
binary_operators=[
"min", "max"
],
extra_sympy_mappings={
"min": lambda x, y: sympy.Piecewise((x, x < y), (y, True)),
"max": lambda x, y: sympy.Piecewise((y, x < y), (x, True)),
}
) This correctly uses |
Would you be interested in submitting a PR to add Lines 40 to 78 in dc1a4e7
|
Thanks for the thourough answer. Yes, sure for the PR ! |
@MilesCranmer thanks for your amazing answer! What is the status of this PR? I looked into the current default sympy mappings but couldn't find them implemented! |
Yeah I don’t think it has been submitted yet. You’re more than welcome to if you want! |
@MilesCranmer I cannot seem to find that |
To overcome the sympy bug while using Min/Max operators as discussed under this issue: MilesCranmer#183
* Added "min" and "max" sympy mapping To overcome the sympy bug while using Min/Max operators as discussed under this issue: #183 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Describe the bug
When I use "min" and "max" in my binary operators, fitting goes well but prediction raises an error.
Version (please include the following information):
Configuration
Error message
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Happens in predict() call. The fit result is correct.
Additional context
I tried adding {'min': np.minimum}, or {'min': min}, or {'min': sympy.Min} to extra_sympy_mappings. None worked.
I found a workaround :
Not very satisfying though.
The text was updated successfully, but these errors were encountered: