dynamicslab / pysindy

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

[BUG] FROLS makes `.history_` an array, not a list. #377

Open Jacob-Stevens-Haas opened 1 year ago

Jacob-Stevens-Haas commented 1 year ago

Reproducing code example:

import pysindy as ps
import numpy as np

rng = np.random.default_rng(94)
x = rng.standard_normal(size=(100,))
model = ps.SINDy(optimizer=ps.FROLS())
model.fit(x, t=1)

model2 = ps.SINDy(optimizer=ps.STLSQ())
model2.fit(x, t=1)

print(type(model.optimizer.history_))
print(type(model2.optimizer.history_))

Result:

<class 'numpy.ndarray'>
<class 'list'>

Expected

<class 'list'>
<class 'list'>

Discussion

When working on #319, I noticed that the history_ argument is documented as a list. FROLS turns it into an array. Prevents adding the result of unbiasing to history_. Solution is simple - edit FROLS to keep it a list. As a follow-on, add a history_ entry after _unbias() and slim down all the BaseOptimizer subclass docstrings with "See Base Class"

PySINDy/Python version information:

master/3.10