dynamicslab / pysindy

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

[BUG] Multiple trajectories raises a ValueError #484

Closed bentaps closed 3 months ago

bentaps commented 3 months ago

When the training data input to ps.SINDy() is a Sequence of multiple trajectories as outlined in the documentation a ValueError is raised. The error can be reproduced by running the example found in 1_feature_overview/example.ipynb. Specifically the following code can reproduce the error:

Reproducing code example:

if __name__ != "testing":
    n_trajectories = 20
    sample_range = (500, 1500)
else:
    n_trajectories = 2
    sample_range = (10, 15)
x0s = np.array([36, 48, 41]) * (np.random.rand(n_trajectories, 3) - 0.5) + np.array(
    [0, 0, 25]
)
x_train_multi = []
for i in range(n_trajectories):
    x_train_multi.append(
        solve_ivp(
            lorenz, t_train_span, x0s[i], t_eval=t_train, **integrator_keywords
        ).y.T
    )

model = ps.SINDy()
model.fit(x_train_multi, t=dt)
model.print()

Error message:

ValueError: x is a Sequence, but multiple_trajectories not set. Did you mean to set multiple trajectories?

PySINDy/Python version information:

1.7.5 3.9.6 (default, Oct 18 2022, 12:41:40) [Clang 14.0.0 (clang-1400.0.29.202)]

Jacob-Stevens-Haas commented 3 months ago

This is because you're on the master branch of the example notebook, but using a stable release of pysindy. Check out the stable example of the notebook. The master branch can include breaking changes for the 2.x series of releases, such as removing the multiple_trajectories kwarg.

bentaps commented 3 months ago

Ah gotcha! Thanks for the quick reply, Jacob :) got it working now!