dynamicslab / pysindy

A package for the sparse identification of nonlinear dynamical systems from data
https://pysindy.readthedocs.io/en/latest/
Other
1.4k stars 308 forks source link

Optimizer parameters validation improvement #542

Open himkwtn opened 1 month ago

himkwtn commented 1 month ago

Right now, parameters validation is done in the constructor as follows https://github.com/dynamicslab/pysindy/blob/3e8a4455fd4de046225344dda9b516d0d013ee36/pysindy/optimizers/sr3.py#L138-L163

According to the scikit-learn documents, validations should be done in the fit method because if we call set_params, it will bypass the validation in the constructor.

Reproducing code example:

from pysindy.optimizers import SR3
opt = SR3(threshold=-1)
# raises "ValueError: threshold cannot be negative"
from pysindy.optimizers import SR3
opt = SR3()
opt.set_params(threshold=-1)
# no error
Jacob-Stevens-Haas commented 1 month ago

This is a good point, although fairly low impact, since I believe set_params() is only used in gridsearch, which is not done much with SINDy, and we can cheat by doing the same validation in set_params() that we do in __init__(). That said, this is something we want, and the way to do this is: