Skip to content
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] Short-circuit WrappedOptimizer when passed an existing SINDy optimizer #572

Open
Jacob-Stevens-Haas opened this issue Oct 16, 2024 · 0 comments

Comments

@Jacob-Stevens-Haas
Copy link
Collaborator

Jacob-Stevens-Haas commented Oct 16, 2024

WrappedOptimizer allows users to make SINDy-compatible optimizers (which accept unbiasing and normalizing) from generic regression optimizers. However, its called on a range of SINDy optimizers that natively prevent unbiasing.

Reproducing code example:

import pysindy as ps

ps.TrappingSR3(unbias=True)  # ValueError: Trapping does not allow unbiasing
ps.WrappedOptimizer(ps.TrappingSR3(), unbias=True)  # Should raise a ValueError but does not

Solution

Pretty straightforwardly, we can prevent this by implementing WrappedOptimizer.__new__(cls, optimizer, ...) and checking the type of optimizer. If it's already a ps.BaseOptimzer, then just return it (potentially, verifying that a conflicting unbias is not present)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant