pysindy icon indicating copy to clipboard operation
pysindy copied to clipboard

model.fit generates error in Example 2

Open Malarius1999 opened this issue 1 year ago • 2 comments

When I execute either Example 1 or 2 of the git repo i get an error while fitting the model. Not sure if i did something wrong on installation, but i tried several hours to get it running.

Error message:


ValueError Traceback (most recent call last) Cell In[28], line 1 ----> 1 model.fit(X, t=t)

File /usr/local/lib/python3.10/site-packages/pysindy/pysindy.py:246, in SINDy.fit(self, x, t, x_dot, u) 240 u = validate_control_variables( 241 x, 242 u, 243 trim_last_point=(self.discrete_time and x_dot is None), 244 ) 245 self.n_control_features_ = u[0].shape[u[0].ax_coord] --> 246 x, x_dot = self._process_trajectories(x, t, x_dot) 248 # Append control variables 249 if u is not None:

File /usr/local/lib/python3.10/site-packages/pysindy/pysindy.py:491, in SINDy._process_trajectories(self, x, t, x_dot) 488 x = [xi[:-1] for xi in x] 489 else: 490 x, x_dot = zip( --> 491 *[ 492 self.feature_library.calc_trajectory( 493 self.differentiation_method, xi, ti 494 ) 495 for xi, ti in _zip_like_sequence(x, t) 496 ] 497 ) 498 return x, x_dot

File /usr/local/lib/python3.10/site-packages/pysindy/pysindy.py:492, in (.0) 488 x = [xi[:-1] for xi in x] 489 else: 490 x, x_dot = zip( 491 *[ --> 492 self.feature_library.calc_trajectory( 493 self.differentiation_method, xi, ti 494 ) 495 for xi, ti in _zip_like_sequence(x, t) 496 ] 497 ) 498 return x, x_dot

File /usr/local/lib/python3.10/site-packages/pysindy/feature_library/base.py:66, in BaseFeatureLibrary.calc_trajectory(self, diff_method, x, t) 65 def calc_trajectory(self, diff_method, x, t): ---> 66 x_dot = diff_method(x, t=t) 67 x = AxesArray(diff_method.smoothed_x_, x.axes) 68 return x, AxesArray(x_dot, x.axes)

File /usr/local/lib/python3.10/site-packages/pysindy/differentiation/base.py:53, in BaseDifferentiation.call(self, x, t) 52 def call(self, x, t=1): ---> 53 return self._differentiate(x, t)

File /usr/local/lib/python3.10/site-packages/pysindy/differentiation/finite_difference.py:269, in FiniteDifference._differentiate(self, x, t) 267 else: 268 t = AxesArray(np.array(t), axes={"ax_time": 0}) --> 269 coeffs = self._coefficients(t) 270 interior = self._accumulate(coeffs, x) 271 s[self.axis] = slice((self.n_stencil - 1) // 2, -(self.n_stencil - 1) // 2)

File /usr/local/lib/python3.10/site-packages/pysindy/differentiation/finite_difference.py:112, in FiniteDifference._coefficients(self, t) 110 b = AxesArray(np.zeros((1, self.n_stencil)), {"ax_time": 0, "ax_power": 1}) 111 b[0, self.d] = factorial(self.d) --> 112 return np.linalg.solve(matrices, b)

File /usr/local/lib/python3.10/site-packages/pysindy/utils/axes.py:420, in AxesArray.array_function(self, func, types, args, kwargs) 418 if not all(issubclass(t, AxesArray) for t in types): 419 return NotImplemented --> 420 return HANDLED_FUNCTIONS[func](*args, **kwargs)

File /usr/local/lib/python3.10/site-packages/pysindy/utils/axes.py:631, in linalg_solve(a, b) 629 @_implements(np.linalg.solve) 630 def linalg_solve(a: AxesArray, b: AxesArray) -> AxesArray: --> 631 result = np.linalg.solve(np.asarray(a), np.asarray(b)) 632 a_rev = a._ax_map.reverse_map 633 a_names = [a_rev[k] for k in sorted(a_rev)]

File /usr/local/lib/python3.10/site-packages/numpy/linalg/_linalg.py:413, in solve(a, b) 410 signature = 'DD->D' if isComplexType(t) else 'dd->d' 411 with errstate(call=_raise_linalgerror_singular, invalid='call', 412 over='ignore', divide='ignore', under='ignore'): --> 413 r = gufunc(a, b, signature=signature) 415 return wrap(r.astype(result_t, copy=False))

ValueError: solve: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (m,m),(m,n)->(m,n) (size 1 is different from 3)

PySINDy/Python version information:

Python 3.10.12 1.7.6.dev485+g23da590.d20241007 3.10.12 (main, Jun 7 2023, 19:32:10) [GCC 10.2.1 20210110]

Malarius1999 avatar Oct 07 '24 22:10 Malarius1999

update: I got it working again with

Python 3.10.15 numpy==1.21.6 pysindy==1.7.3

Malarius1999 avatar Oct 09 '24 16:10 Malarius1999

I tried example 1 (without modification) and got:

Traceback (most recent call last): File "/home/mkalz/fit_lorenz.py", line 8, in x = solve_ivp(lorenz, [-8,8,27], t) File "/home/mkalz/.conda/envs/photon_systems/lib/python3.10/site-packages/scipy/integrate/_ivp/ivp.py", line 577, in solve_ivp t0, tf = map(float, t_span) ValueError: too many values to unpack (expected 2)

Did you change anything? @Malarius1999

michaelkalz avatar Oct 11 '24 18:10 michaelkalz